mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
core(ocl): fix POWN OpenCL implementation
This commit is contained in:
@@ -938,9 +938,40 @@ static bool ocl_pow(InputArray _src, double power, OutputArray _dst,
|
||||
bool issqrt = std::abs(power - 0.5) < DBL_EPSILON;
|
||||
const char * const op = issqrt ? "OP_SQRT" : is_ipower ? "OP_POWN" : "OP_POW";
|
||||
|
||||
// Note: channels are unrolled
|
||||
|
||||
std::string extra_opts ="";
|
||||
if (is_ipower)
|
||||
{
|
||||
int wdepth = CV_32F;
|
||||
if (depth == CV_64F)
|
||||
wdepth = CV_64F;
|
||||
else if (depth == CV_16F)
|
||||
wdepth = CV_16F;
|
||||
|
||||
char cvt[2][50];
|
||||
extra_opts = format(
|
||||
" -D srcT1=%s -DsrcT1_C1=%s"
|
||||
" -D srcT2=int -D workST=int"
|
||||
" -D workT=%s -D wdepth=%d -D convertToWT1=%s"
|
||||
" -D convertToDT=%s"
|
||||
" -D workT1=%s",
|
||||
ocl::typeToStr(CV_MAKE_TYPE(depth, 1)),
|
||||
ocl::typeToStr(CV_MAKE_TYPE(depth, 1)),
|
||||
ocl::typeToStr(CV_MAKE_TYPE(wdepth, 1)),
|
||||
wdepth,
|
||||
ocl::convertTypeStr(depth, wdepth, 1, cvt[0], sizeof(cvt[0])),
|
||||
ocl::convertTypeStr(wdepth, depth, 1, cvt[1], sizeof(cvt[1])),
|
||||
ocl::typeToStr(wdepth)
|
||||
);
|
||||
}
|
||||
|
||||
ocl::Kernel k("KF", ocl::core::arithm_oclsrc,
|
||||
format("-D dstT=%s -D DEPTH_dst=%d -D rowsPerWI=%d -D %s -D UNARY_OP%s",
|
||||
ocl::typeToStr(depth), depth, rowsPerWI, op,
|
||||
format("-D cn=%d -D dstT=%s -D dstT_C1=%s -D DEPTH_dst=%d -D rowsPerWI=%d -D %s%s%s%s",
|
||||
1,
|
||||
ocl::typeToStr(depth), ocl::typeToStr(depth), depth, rowsPerWI, op,
|
||||
" -D UNARY_OP=1",
|
||||
extra_opts.empty() ? "" : extra_opts.c_str(),
|
||||
doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
@@ -80,6 +80,10 @@
|
||||
#error "Kernel configuration error: ambiguous 'depth' value is defined, use 'DEPTH_dst' instead"
|
||||
#endif
|
||||
|
||||
#define CAT__(x, y) x ## y
|
||||
#define CAT_(x, y) CAT__(x, y)
|
||||
#define CAT(x, y) CAT_(x, y)
|
||||
|
||||
|
||||
#if DEPTH_dst < 5 /* CV_32F */
|
||||
#define CV_DST_TYPE_IS_INTEGER
|
||||
@@ -325,9 +329,12 @@
|
||||
#define PROCESS_ELEM storedst(pow(srcelem1, srcelem2))
|
||||
|
||||
#elif defined OP_POWN
|
||||
#undef workT
|
||||
#define workT int
|
||||
#define PROCESS_ELEM storedst(pown(srcelem1, srcelem2))
|
||||
#if cn > 1
|
||||
#define PROCESS_INIT CAT(int, cn) powi = (CAT(int, cn))srcelem2;
|
||||
#else // cn
|
||||
#define PROCESS_INIT int powi = srcelem2;
|
||||
#endif
|
||||
#define PROCESS_ELEM storedst(convertToDT(pown(srcelem1, powi)))
|
||||
|
||||
#elif defined OP_SQRT
|
||||
#if CV_DST_TYPE_FIT_32F
|
||||
@@ -469,7 +476,7 @@
|
||||
#define srcelem2 srcelem2_
|
||||
#endif
|
||||
|
||||
#if cn == 3
|
||||
#if !defined(PROCESS_INIT) && cn == 3
|
||||
#undef srcelem2
|
||||
#define srcelem2 (workT)(srcelem2_.x, srcelem2_.y, srcelem2_.z)
|
||||
#endif
|
||||
@@ -517,6 +524,10 @@ __kernel void KF(__global const uchar * srcptr1, int srcstep1, int srcoffset1,
|
||||
int x = get_global_id(0);
|
||||
int y0 = get_global_id(1) * rowsPerWI;
|
||||
|
||||
#ifdef PROCESS_INIT
|
||||
PROCESS_INIT
|
||||
#endif
|
||||
|
||||
if (x < cols)
|
||||
{
|
||||
int mask_index = mad24(y0, maskstep, x + maskoffset);
|
||||
@@ -542,6 +553,10 @@ __kernel void KF(__global const uchar * srcptr1, int srcstep1, int srcoffset1,
|
||||
int x = get_global_id(0);
|
||||
int y0 = get_global_id(1) * rowsPerWI;
|
||||
|
||||
#ifdef PROCESS_INIT
|
||||
PROCESS_INIT
|
||||
#endif
|
||||
|
||||
if (x < cols)
|
||||
{
|
||||
int src1_index = mad24(y0, srcstep1, mad24(x, (int)sizeof(srcT1_C1) * cn, srcoffset1));
|
||||
@@ -564,6 +579,10 @@ __kernel void KF(__global const uchar * srcptr1, int srcstep1, int srcoffset1,
|
||||
int x = get_global_id(0);
|
||||
int y0 = get_global_id(1) * rowsPerWI;
|
||||
|
||||
#ifdef PROCESS_INIT
|
||||
PROCESS_INIT
|
||||
#endif
|
||||
|
||||
if (x < cols)
|
||||
{
|
||||
int mask_index = mad24(y0, maskstep, x + maskoffset);
|
||||
|
||||
Reference in New Issue
Block a user