From 2eca75ccdd04f66e5be10acab20e62fbc4b90f84 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 27 Nov 2012 11:08:53 +0400 Subject: [PATCH] added common TransformFunctorTraits for element operations --- modules/gpu/src/cuda/element_operations.cu | 776 +++++---------------- 1 file changed, 164 insertions(+), 612 deletions(-) diff --git a/modules/gpu/src/cuda/element_operations.cu b/modules/gpu/src/cuda/element_operations.cu index eaf577bac..071ad89ce 100644 --- a/modules/gpu/src/cuda/element_operations.cu +++ b/modules/gpu/src/cuda/element_operations.cu @@ -52,6 +52,103 @@ using namespace cv::gpu; using namespace cv::gpu::device; +namespace +{ + template struct ArithmFuncTraits + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 1 }; + }; + + template <> struct ArithmFuncTraits<1, 1> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + template <> struct ArithmFuncTraits<1, 2> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + template <> struct ArithmFuncTraits<1, 4> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + + template <> struct ArithmFuncTraits<2, 1> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + template <> struct ArithmFuncTraits<2, 2> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + template <> struct ArithmFuncTraits<2, 4> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + + template <> struct ArithmFuncTraits<4, 1> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + template <> struct ArithmFuncTraits<4, 2> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; + template <> struct ArithmFuncTraits<4, 4> + { + enum { simple_block_dim_x = 32 }; + enum { simple_block_dim_y = 8 }; + + enum { smart_block_dim_x = 32 }; + enum { smart_block_dim_y = 8 }; + enum { smart_shift = 4 }; + }; +} + ////////////////////////////////////////////////////////////////////////// // addMat @@ -239,39 +336,20 @@ namespace namespace cv { namespace gpu { namespace device { - template struct TransformFunctorTraits< VAdd4 > : DefaultTransformFunctorTraits< VAdd4 > + template struct TransformFunctorTraits< VAdd4 > : ArithmFuncTraits { - enum { smart_shift = 2 }; }; //////////////////////////////////// - template struct TransformFunctorTraits< VAdd2 > : DefaultTransformFunctorTraits< VAdd4 > + template struct TransformFunctorTraits< VAdd2 > : ArithmFuncTraits { - enum { smart_shift = 2 }; }; //////////////////////////////////// - template <> struct TransformFunctorTraits< AddMat > : DefaultTransformFunctorTraits< AddMat > + template struct TransformFunctorTraits< AddMat > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AddMat > : DefaultTransformFunctorTraits< AddMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AddMat > : DefaultTransformFunctorTraits< AddMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AddMat > : DefaultTransformFunctorTraits< AddMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -385,25 +463,8 @@ namespace namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< AddScalar > : DefaultTransformFunctorTraits< AddScalar > + template struct TransformFunctorTraits< AddScalar > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AddScalar > : DefaultTransformFunctorTraits< AddScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AddScalar > : DefaultTransformFunctorTraits< AddScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AddScalar > : DefaultTransformFunctorTraits< AddScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -664,39 +725,20 @@ namespace namespace cv { namespace gpu { namespace device { - template struct TransformFunctorTraits< VSub4 > : DefaultTransformFunctorTraits< VSub4 > + template struct TransformFunctorTraits< VSub4 > : ArithmFuncTraits { - enum { smart_shift = 2 }; }; //////////////////////////////////// - template struct TransformFunctorTraits< VSub2 > : DefaultTransformFunctorTraits< VSub2 > + template struct TransformFunctorTraits< VSub2 > : ArithmFuncTraits { - enum { smart_shift = 2 }; }; //////////////////////////////////// - template <> struct TransformFunctorTraits< SubMat > : DefaultTransformFunctorTraits< SubMat > + template struct TransformFunctorTraits< SubMat > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< SubMat > : DefaultTransformFunctorTraits< SubMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< SubMat > : DefaultTransformFunctorTraits< SubMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< SubMat > : DefaultTransformFunctorTraits< SubMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -924,53 +966,16 @@ namespace namespace cv { namespace gpu { namespace device { - OPENCV_GPU_TRANSFORM_FUNCTOR_TRAITS(Mul_8uc4_32f) + template <> struct TransformFunctorTraits : ArithmFuncTraits { - enum { smart_block_dim_x = 8 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 8 }; }; - template <> struct TransformFunctorTraits< Mul > : DefaultTransformFunctorTraits< Mul > + template struct TransformFunctorTraits< Mul > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Mul > : DefaultTransformFunctorTraits< Mul > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Mul > : DefaultTransformFunctorTraits< Mul > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Mul > : DefaultTransformFunctorTraits< Mul > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; - template <> struct TransformFunctorTraits< MulScale > : DefaultTransformFunctorTraits< MulScale > + template struct TransformFunctorTraits< MulScale > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< MulScale > : DefaultTransformFunctorTraits< MulScale > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< MulScale > : DefaultTransformFunctorTraits< MulScale > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< MulScale > : DefaultTransformFunctorTraits< MulScale > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1078,25 +1083,8 @@ namespace namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< MulScalar > : DefaultTransformFunctorTraits< MulScalar > + template struct TransformFunctorTraits< MulScalar > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< MulScalar > : DefaultTransformFunctorTraits< MulScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< MulScalar > : DefaultTransformFunctorTraits< MulScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< MulScalar > : DefaultTransformFunctorTraits< MulScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1246,53 +1234,16 @@ namespace namespace cv { namespace gpu { namespace device { - OPENCV_GPU_TRANSFORM_FUNCTOR_TRAITS(Div_8uc4_32f) + template <> struct TransformFunctorTraits : ArithmFuncTraits { - enum { smart_block_dim_x = 8 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 8 }; }; - template <> struct TransformFunctorTraits< Div > : DefaultTransformFunctorTraits< Div > + template struct TransformFunctorTraits< Div > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Div > : DefaultTransformFunctorTraits< Div > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Div > : DefaultTransformFunctorTraits< Div > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Div > : DefaultTransformFunctorTraits< Div > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; - template <> struct TransformFunctorTraits< DivScale > : DefaultTransformFunctorTraits< DivScale > + template struct TransformFunctorTraits< DivScale > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< DivScale > : DefaultTransformFunctorTraits< DivScale > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< DivScale > : DefaultTransformFunctorTraits< DivScale > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< DivScale > : DefaultTransformFunctorTraits< DivScale > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1469,25 +1420,8 @@ namespace namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< DivInv > : DefaultTransformFunctorTraits< DivInv > + template struct TransformFunctorTraits< DivInv > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< DivInv > : DefaultTransformFunctorTraits< DivInv > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< DivInv > : DefaultTransformFunctorTraits< DivInv > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< DivInv > : DefaultTransformFunctorTraits< DivInv > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1677,39 +1611,20 @@ namespace namespace cv { namespace gpu { namespace device { - template struct TransformFunctorTraits< VAbsDiff4 > : DefaultTransformFunctorTraits< VAbsDiff4 > + template struct TransformFunctorTraits< VAbsDiff4 > : ArithmFuncTraits { - enum { smart_shift = 2 }; }; //////////////////////////////////// - template struct TransformFunctorTraits< VAbsDiff2 > : DefaultTransformFunctorTraits< VAbsDiff4 > + template struct TransformFunctorTraits< VAbsDiff2 > : ArithmFuncTraits { - enum { smart_shift = 2 }; }; //////////////////////////////////// - template <> struct TransformFunctorTraits< AbsDiffMat > : DefaultTransformFunctorTraits< AbsDiffMat > + template struct TransformFunctorTraits< AbsDiffMat > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AbsDiffMat > : DefaultTransformFunctorTraits< AbsDiffMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AbsDiffMat > : DefaultTransformFunctorTraits< AbsDiffMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AbsDiffMat > : DefaultTransformFunctorTraits< AbsDiffMat > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1769,25 +1684,8 @@ namespace namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< AbsDiffScalar > : DefaultTransformFunctorTraits< AbsDiffScalar > + template struct TransformFunctorTraits< AbsDiffScalar > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AbsDiffScalar > : DefaultTransformFunctorTraits< AbsDiffScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AbsDiffScalar > : DefaultTransformFunctorTraits< AbsDiffScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< AbsDiffScalar > : DefaultTransformFunctorTraits< AbsDiffScalar > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1815,25 +1713,8 @@ namespace arithm namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< abs_func > : DefaultTransformFunctorTraits< abs_func > + template struct TransformFunctorTraits< abs_func > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< abs_func > : DefaultTransformFunctorTraits< abs_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< abs_func > : DefaultTransformFunctorTraits< abs_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< abs_func > : DefaultTransformFunctorTraits< abs_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1873,25 +1754,8 @@ namespace namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< Sqr > : DefaultTransformFunctorTraits< Sqr > + template struct TransformFunctorTraits< Sqr > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Sqr > : DefaultTransformFunctorTraits< Sqr > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Sqr > : DefaultTransformFunctorTraits< Sqr > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Sqr > : DefaultTransformFunctorTraits< Sqr > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1917,33 +1781,8 @@ namespace arithm namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< sqrt_func > : DefaultTransformFunctorTraits< sqrt_func > + template struct TransformFunctorTraits< sqrt_func > : ArithmFuncTraits { - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< sqrt_func > : DefaultTransformFunctorTraits< sqrt_func > - { - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< sqrt_func > : DefaultTransformFunctorTraits< sqrt_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< sqrt_func > : DefaultTransformFunctorTraits< sqrt_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< sqrt_func > : DefaultTransformFunctorTraits< sqrt_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< sqrt_func > : DefaultTransformFunctorTraits< sqrt_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -1969,33 +1808,8 @@ namespace arithm namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< log_func > : DefaultTransformFunctorTraits< log_func > + template struct TransformFunctorTraits< log_func > : ArithmFuncTraits { - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< log_func > : DefaultTransformFunctorTraits< log_func > - { - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< log_func > : DefaultTransformFunctorTraits< log_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< log_func > : DefaultTransformFunctorTraits< log_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< log_func > : DefaultTransformFunctorTraits< log_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< log_func > : DefaultTransformFunctorTraits< log_func > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -2036,25 +1850,8 @@ namespace namespace cv { namespace gpu { namespace device { - template <> struct TransformFunctorTraits< Exp > : DefaultTransformFunctorTraits< Exp > + template struct TransformFunctorTraits< Exp > : ArithmFuncTraits { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Exp > : DefaultTransformFunctorTraits< Exp > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Exp > : DefaultTransformFunctorTraits< Exp > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct TransformFunctorTraits< Exp > : DefaultTransformFunctorTraits< Exp > - { - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; }; }}} @@ -2080,12 +1877,12 @@ namespace arithm namespace { - template