From 3e586f42a0dea12f34378884d68a090cec42b59e Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 30 Nov 2013 17:20:45 +0400 Subject: [PATCH] added cv::pow to T-API --- modules/core/src/mathfuncs.cpp | 31 +++++++++++++++++++++++++++++++ modules/core/src/opencl/arithm.cl | 5 ++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 29601bec23..2f146c8559 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -1955,9 +1955,40 @@ static IPowFunc ipowTab[] = (IPowFunc)iPow32s, (IPowFunc)iPow32f, (IPowFunc)iPow64f, 0 }; +static bool ocl_pow(InputArray _src, double power, OutputArray _dst) +{ + int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); + bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; + + if ( !(_src.dims() <= 2 && (depth == CV_32F || depth == CV_64F)) || + (depth == CV_64F && !doubleSupport) ) + return false; + + UMat src = _src.getUMat(); + _dst.create(src.size(), type); + UMat dst = _dst.getUMat(); + + ocl::Kernel k("KF", ocl::core::arithm_oclsrc, + format("-D dstT=%s -D OP_POW -D UNARY_OP%s", ocl::typeToStr(CV_MAKE_TYPE(depth, 1)), + doubleSupport ? "-D DOUBLE_SUPPORT" : "")); + + ocl::KernelArg srcarg = ocl::KernelArg::ReadOnlyNoSize(src), + dstarg = ocl::KernelArg::WriteOnly(dst, cn); + + if (depth == CV_32F) + k.args(srcarg, dstarg, (float)power); + else + k.args(srcarg, dstarg, power); + + size_t globalsize[2] = { dst.cols * cn, dst.rows }; + return k.run(2, globalsize, NULL, false); +} void pow( InputArray _src, double power, OutputArray _dst ) { + if (ocl::useOpenCL() && _dst.isUMat() && ocl_pow(_src, power, _dst)) + return; + Mat src = _src.getMat(); int type = src.type(), depth = src.depth(), cn = src.channels(); diff --git a/modules/core/src/opencl/arithm.cl b/modules/core/src/opencl/arithm.cl index 87a9dece66..3b0fb99cb8 100644 --- a/modules/core/src/opencl/arithm.cl +++ b/modules/core/src/opencl/arithm.cl @@ -171,6 +171,9 @@ #elif defined OP_EXP #define PROCESS_ELEM dstelem = exp(srcelem1) +#elif defined OP_POW +#define PROCESS_ELEM dstelem = pow(srcelem1, srcelem2) + #elif defined OP_SQRT #define PROCESS_ELEM dstelem = sqrt(srcelem1) @@ -198,7 +201,7 @@ dstelem = v > (dstT)(0) ? log(v) : log(-v) #undef srcelem2 #if defined OP_AND || defined OP_OR || defined OP_XOR || defined OP_ADD || defined OP_SAT_ADD || \ defined OP_SUB || defined OP_SAT_SUB || defined OP_RSUB || defined OP_SAT_RSUB || \ - defined OP_ABSDIFF || defined OP_CMP || defined OP_MIN || defined OP_MAX + defined OP_ABSDIFF || defined OP_CMP || defined OP_MIN || defined OP_MAX || defined OP_POW #undef EXTRA_PARAMS #define EXTRA_PARAMS , workT srcelem2 #endif