From: Ilya Lavrenov Date: Mon, 7 Oct 2013 18:10:11 +0000 (+0400) Subject: enabled OpenCL 1.2 branch in oclMat::setTo X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1314^2~950^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32f11e6f40d66f97c75f9d81676ac624e2666324;p=platform%2Fupstream%2Fopencv.git enabled OpenCL 1.2 branch in oclMat::setTo --- diff --git a/modules/ocl/src/matrix_operations.cpp b/modules/ocl/src/matrix_operations.cpp index 3b0e417..ed3a7ef 100644 --- a/modules/ocl/src/matrix_operations.cpp +++ b/modules/ocl/src/matrix_operations.cpp @@ -346,6 +346,66 @@ oclMat &cv::ocl::oclMat::operator = (const Scalar &s) return *this; } +#ifdef CL_VERSION_1_2 + +template +static std::vector cvt1(const cv::Scalar & s) +{ + std::vector _buf(sizeof(CLT)); + CLT * const buf = reinterpret_cast(&_buf[0]); + buf[0] = saturate_cast(s[0]); + return _buf; +} + +template +static std::vector cvt2(const cv::Scalar & s) +{ + std::vector _buf(sizeof(CLT)); + CLT * const buf = reinterpret_cast(&_buf[0]); + buf->s0 = saturate_cast(s[0]); + buf->s1 = saturate_cast(s[1]); + return _buf; +} + +template +static std::vector cvt4(const cv::Scalar & s) +{ + std::vector _buf(sizeof(CLT)); + CLT * const buf = reinterpret_cast(&_buf[0]); + buf->s0 = saturate_cast(s[0]); + buf->s1 = saturate_cast(s[1]); + buf->s2 = saturate_cast(s[2]); + buf->s3 = saturate_cast(s[3]); + return _buf; +} + +typedef std::vector (*ConvertFunc)(const cv::Scalar & s); + +static std::vector scalarToCLVector(const cv::Scalar & s, int type) +{ + const int depth = CV_MAT_DEPTH(type); + const int channels = CV_MAT_CN(type); + + static const ConvertFunc funcs[4][7] = + { + { cvt1, cvt1, cvt1, cvt1, + cvt1, cvt1, cvt1 }, + + { cvt2, cvt2, cvt2, cvt2, + cvt2, cvt2, cvt2 }, + + { 0, 0, 0, 0, 0, 0, 0 }, + + { cvt4, cvt4, cvt4, cvt4, + cvt4, cvt4, cvt4 } + }; + + ConvertFunc func = funcs[channels - 1][depth]; + return func(s); +} + +#endif + static void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, string kernelName) { vector > args; @@ -366,23 +426,14 @@ static void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, stri #ifdef CL_VERSION_1_2 // this enables backwards portability to // run on OpenCL 1.1 platform if library binaries are compiled with OpenCL 1.2 support -// if (Context::getContext()->supportsFeature(Context::CL_VER_1_2) && -// dst.offset == 0 && dst.cols == dst.wholecols) -// { -// const int sizeofMap[][7] = -// { -// { sizeof(cl_uchar) , sizeof(cl_char) , sizeof(cl_ushort) , sizeof(cl_short) , sizeof(cl_int) , sizeof(cl_float) , sizeof(cl_double) }, -// { sizeof(cl_uchar2), sizeof(cl_char2), sizeof(cl_ushort2), sizeof(cl_short2), sizeof(cl_int2), sizeof(cl_float2), sizeof(cl_double2) }, -// { 0 , 0 , 0 , 0 , 0 , 0 , 0 }, -// { sizeof(cl_uchar4), sizeof(cl_char4), sizeof(cl_ushort4), sizeof(cl_short4), sizeof(cl_int4), sizeof(cl_float4), sizeof(cl_double4) }, -// }; -// int sizeofGeneric = sizeofMap[dst.oclchannels() - 1][dst.depth()]; - -// clEnqueueFillBuffer((cl_command_queue)dst.clCxt->oclCommandQueue(), -// (cl_mem)dst.data, (void*)mat.data, sizeofGeneric, -// 0, dst.step * dst.rows, 0, NULL, NULL); -// } -// else + if (Context::getContext()->supportsFeature(FEATURE_CL_VER_1_2) && dst.isContinuous()) + { + std::vector p = ::scalarToCLVector(scalar, dst.type()); + clEnqueueFillBuffer(getClCommandQueue(dst.clCxt), + (cl_mem)dst.data, (void*)&p[0], p.size(), + 0, dst.step * dst.rows, 0, NULL, NULL); + } + else #endif { oclMat m(mat);