Commit 321782b9 authored by Ilya Lavrenov's avatar Ilya Lavrenov

added macro with ability of returning values

parent 06acf709
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
#ifdef CV_OPENCL_RUN_VERBOSE #ifdef CV_OPENCL_RUN_VERBOSE
#define CV_OCL_RUN(condition, func) \ #define CV_OCL_RUN_(condition, func, ...) \
{ \ { \
if (cv::ocl::useOpenCL() && (condition) && func) \ if (cv::ocl::useOpenCL() && (condition) && func) \
{ \ { \
printf("%s: OpenCL implementation is running\n", CV_Func); \ printf("%s: OpenCL implementation is running\n", CV_Func); \
fflush(stdout); \ fflush(stdout); \
return; \ return __VA_ARGS__; \
} \ } \
else \ else \
{ \ { \
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
} \ } \
} }
#else #else
#define CV_OCL_RUN(condition, func) \ #define CV_OCL_RUN_(condition, func, ...) \
if (cv::ocl::useOpenCL() && (condition) && func) \ if (cv::ocl::useOpenCL() && (condition) && func) \
return; return __VA_ARGS__;
#endif #endif
#else #else
#define CV_OCL_RUN(condition, func) #define CV_OCL_RUN_(condition, func, retval)
#endif #endif
#define CV_OCL_RUN(condition, func) CV_OCL_RUN_(condition, func)
...@@ -475,7 +475,7 @@ static bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask ...@@ -475,7 +475,7 @@ static bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
if ( (!doubleSupport && depth == CV_64F) || cn > 4 || cn == 3 || _src.dims() > 2 ) if ( (!doubleSupport && depth == CV_64F) || cn > 4 || cn == 3 )
return false; return false;
int dbsize = ocl::Device::getDefault().maxComputeUnits(); int dbsize = ocl::Device::getDefault().maxComputeUnits();
...@@ -533,8 +533,9 @@ cv::Scalar cv::sum( InputArray _src ) ...@@ -533,8 +533,9 @@ cv::Scalar cv::sum( InputArray _src )
{ {
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
Scalar _res; Scalar _res;
if (ocl::useOpenCL() && _src.isUMat() && ocl_sum(_src, _res, OCL_OP_SUM)) CV_OCL_RUN_( _src.isUMat() && _src.dims() <= 2,
return _res; ocl_sum(_src, _res, OCL_OP_SUM),
_res)
#endif #endif
Mat src = _src.getMat(); Mat src = _src.getMat();
...@@ -674,8 +675,9 @@ int cv::countNonZero( InputArray _src ) ...@@ -674,8 +675,9 @@ int cv::countNonZero( InputArray _src )
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
int res = -1; int res = -1;
if (ocl::useOpenCL() && _src.isUMat() && ocl_countNonZero(_src, res)) CV_OCL_RUN_(_src.isUMat() && _src.dims() <= 2,
return res; ocl_countNonZero(_src, res),
res)
#endif #endif
Mat src = _src.getMat(); Mat src = _src.getMat();
...@@ -1985,8 +1987,9 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) ...@@ -1985,8 +1987,9 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
double _result = 0; double _result = 0;
if (ocl::useOpenCL() && _src.isUMat() && _src.dims() <= 2 && ocl_norm(_src, normType, _mask, _result)) CV_OCL_RUN_(_src.isUMat() && _src.dims() <= 2,
return _result; ocl_norm(_src, normType, _mask, _result),
_result)
#endif #endif
Mat src = _src.getMat(), mask = _mask.getMat(); Mat src = _src.getMat(), mask = _mask.getMat();
...@@ -2320,9 +2323,10 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m ...@@ -2320,9 +2323,10 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
double _result = 0; double _result = 0;
if (ocl::useOpenCL() && _mask.empty() && _src1.isUMat() && _src2.isUMat() && CV_OCL_RUN_(_mask.empty() && _src1.isUMat() && _src2.isUMat() &&
_src1.dims() <= 2 && _src2.dims() <= 2 && ocl_norm(_src1, _src2, normType, _result)) _src1.dims() <= 2 && _src2.dims() <= 2,
return _result; ocl_norm(_src1, _src2, normType, _result),
_result)
#endif #endif
if( normType & CV_RELATIVE ) if( normType & CV_RELATIVE )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment