Merge pull request #2191 from ilya-lavrenov:tapi_macro

This commit is contained in:
Andrey Pavlenko 2014-01-25 16:32:54 +04:00 committed by OpenCV Buildbot
commit 3f61007563
10 changed files with 223 additions and 110 deletions

View File

@ -29,6 +29,7 @@ ${nested_namespace_start}
set(STR_HPP "// This file is auto-generated. Do not edit!
#include \"opencv2/core/ocl_genbase.hpp\"
#include \"opencv2/core/opencl/ocl_defs.hpp\"
namespace cv
{

View File

@ -0,0 +1,33 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
#ifdef HAVE_OPENCL
#ifdef CV_OPENCL_RUN_VERBOSE
#define CV_OCL_RUN(condition, func) \
{ \
if (cv::ocl::useOpenCL() && (condition) && func) \
{ \
printf("%s: OpenCL implementation is running\n", CV_Func); \
fflush(stdout); \
return; \
} \
else \
{ \
printf("%s: Plain implementation is running\n", CV_Func); \
fflush(stdout); \
} \
}
#else
#define CV_OCL_RUN(condition, func) \
if (cv::ocl::useOpenCL() && (condition) && func) \
return;
#endif
#else
#define CV_OCL_RUN(condition, func)
#endif

View File

@ -918,6 +918,8 @@ enum { OCL_OP_ADD=0, OCL_OP_SUB=1, OCL_OP_RSUB=2, OCL_OP_ABSDIFF=3, OCL_OP_MUL=4
OCL_OP_AND=9, OCL_OP_OR=10, OCL_OP_XOR=11, OCL_OP_NOT=12, OCL_OP_MIN=13, OCL_OP_MAX=14,
OCL_OP_RDIV_SCALE=15 };
#ifdef HAVE_OPENCL
static const char* oclop2str[] = { "OP_ADD", "OP_SUB", "OP_RSUB", "OP_ABSDIFF",
"OP_MUL", "OP_MUL_SCALE", "OP_DIV_SCALE", "OP_RECIP_SCALE",
"OP_ADDW", "OP_AND", "OP_OR", "OP_XOR", "OP_NOT", "OP_MIN", "OP_MAX", "OP_RDIV_SCALE", 0 };
@ -989,6 +991,7 @@ static bool ocl_binary_op(InputArray _src1, InputArray _src2, OutputArray _dst,
return k.run(2, globalsize, 0, false);
}
#endif
static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst,
InputArray _mask, const BinaryFunc* tab,
@ -1001,16 +1004,19 @@ static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst,
int dims1 = psrc1->dims(), dims2 = psrc2->dims();
Size sz1 = dims1 <= 2 ? psrc1->size() : Size();
Size sz2 = dims2 <= 2 ? psrc2->size() : Size();
#ifdef HAVE_OPENCL
bool use_opencl = (kind1 == _InputArray::UMAT || kind2 == _InputArray::UMAT) &&
ocl::useOpenCL() && dims1 <= 2 && dims2 <= 2;
dims1 <= 2 && dims2 <= 2;
#endif
bool haveMask = !_mask.empty(), haveScalar = false;
BinaryFunc func;
if( dims1 <= 2 && dims2 <= 2 && kind1 == kind2 && sz1 == sz2 && type1 == type2 && !haveMask )
{
_dst.create(sz1, type1);
if( use_opencl && ocl_binary_op(*psrc1, *psrc2, _dst, _mask, bitwise, oclop, false) )
return;
CV_OCL_RUN(use_opencl,
ocl_binary_op(*psrc1, *psrc2, _dst, _mask, bitwise, oclop, false))
if( bitwise )
{
func = *tab;
@ -1077,8 +1083,9 @@ static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst,
if( haveMask && reallocate )
_dst.setTo(0.);
if( use_opencl && ocl_binary_op(*psrc1, *psrc2, _dst, _mask, bitwise, oclop, haveScalar ))
return;
CV_OCL_RUN(use_opencl,
ocl_binary_op(*psrc1, *psrc2, _dst, _mask, bitwise, oclop, haveScalar))
Mat src1 = psrc1->getMat(), src2 = psrc2->getMat();
Mat dst = _dst.getMat(), mask = _mask.getMat();
@ -1089,9 +1096,7 @@ static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst,
cn = (int)esz;
}
else
{
func = tab[depth1];
}
if( !haveScalar )
{
@ -1278,6 +1283,7 @@ static int actualScalarDepth(const double* data, int len)
CV_32S;
}
#ifdef HAVE_OPENCL
static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
InputArray _mask, int wtype,
@ -1395,6 +1401,7 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
return k.run(2, globalsize, NULL, false);
}
#endif
static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
InputArray _mask, int dtype, BinaryFunc* tab, bool muldiv=false,
@ -1409,7 +1416,9 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
int wtype, dims1 = psrc1->dims(), dims2 = psrc2->dims();
Size sz1 = dims1 <= 2 ? psrc1->size() : Size();
Size sz2 = dims2 <= 2 ? psrc2->size() : Size();
bool use_opencl = _dst.isUMat() && ocl::useOpenCL() && dims1 <= 2 && dims2 <= 2;
#ifdef HAVE_OPENCL
bool use_opencl = _dst.isUMat() && dims1 <= 2 && dims2 <= 2;
#endif
bool src1Scalar = checkScalar(*psrc1, type2, kind1, kind2);
bool src2Scalar = checkScalar(*psrc2, type1, kind2, kind1);
@ -1419,11 +1428,10 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
((src1Scalar && src2Scalar) || (!src1Scalar && !src2Scalar)) )
{
_dst.createSameSize(*psrc1, type1);
if( use_opencl &&
CV_OCL_RUN(use_opencl,
ocl_arithm_op(*psrc1, *psrc2, _dst, _mask,
(!usrdata ? type1 : std::max(depth1, CV_32F)),
usrdata, oclop, false))
return;
Mat src1 = psrc1->getMat(), src2 = psrc2->getMat(), dst = _dst.getMat();
Size sz = getContinuousSize(src1, src2, dst, src1.channels());
@ -1520,10 +1528,9 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
if( reallocate )
_dst.setTo(0.);
if( use_opencl &&
ocl_arithm_op(*psrc1, *psrc2, _dst, _mask, wtype,
usrdata, oclop, haveScalar))
return;
CV_OCL_RUN(use_opencl,
ocl_arithm_op(*psrc1, *psrc2, _dst, _mask, wtype,
usrdata, oclop, haveScalar))
BinaryFunc cvtsrc1 = type1 == wtype ? 0 : getConvertFunc(type1, wtype);
BinaryFunc cvtsrc2 = type2 == type1 ? cvtsrc1 : type2 == wtype ? 0 : getConvertFunc(type2, wtype);
@ -2600,6 +2607,8 @@ static double getMaxVal(int depth)
return tab[depth];
}
#ifdef HAVE_OPENCL
static bool ocl_compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
{
if ( !((_src1.isMat() || _src1.isUMat()) && (_src2.isMat() || _src2.isUMat())) )
@ -2636,6 +2645,8 @@ static bool ocl_compare(InputArray _src1, InputArray _src2, OutputArray _dst, in
return k.run(2, globalsize, NULL, false);
}
#endif
}
void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
@ -2643,9 +2654,8 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
CV_Assert( op == CMP_LT || op == CMP_LE || op == CMP_EQ ||
op == CMP_NE || op == CMP_GE || op == CMP_GT );
if (ocl::useOpenCL() && _src1.dims() <= 2 && _src2.dims() <= 2 && _dst.isUMat() &&
ocl_compare(_src1, _src2, _dst, op))
return;
CV_OCL_RUN(_src1.dims() <= 2 && _src2.dims() <= 2 && _dst.isUMat(),
ocl_compare(_src1, _src2, _dst, op))
int kind1 = _src1.kind(), kind2 = _src2.kind();
Mat src1 = _src1.getMat(), src2 = _src2.getMat();
@ -2877,6 +2887,8 @@ static InRangeFunc getInRangeFunc(int depth)
return inRangeTab[depth];
}
#ifdef HAVE_OPENCL
static bool ocl_inRange( InputArray _src, InputArray _lowerb,
InputArray _upperb, OutputArray _dst )
{
@ -2983,14 +2995,16 @@ static bool ocl_inRange( InputArray _src, InputArray _lowerb,
return ker.run(2, globalsize, NULL, false);
}
#endif
}
void cv::inRange(InputArray _src, InputArray _lowerb,
InputArray _upperb, OutputArray _dst)
{
if (ocl::useOpenCL() && _src.dims() <= 2 && _lowerb.dims() <= 2 &&
_upperb.dims() <= 2 && _dst.isUMat() && ocl_inRange(_src, _lowerb, _upperb, _dst))
return;
CV_OCL_RUN(_src.dims() <= 2 && _lowerb.dims() <= 2 &&
_upperb.dims() <= 2 && _dst.isUMat(),
ocl_inRange(_src, _lowerb, _upperb, _dst))
int skind = _src.kind(), lkind = _lowerb.kind(), ukind = _upperb.kind();
Mat src = _src.getMat(), lb = _lowerb.getMat(), ub = _upperb.getMat();

View File

@ -264,6 +264,8 @@ void cv::split(const Mat& src, Mat* mv)
}
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_split( InputArray _m, OutputArrayOfArrays _mv )
@ -302,11 +304,12 @@ static bool ocl_split( InputArray _m, OutputArrayOfArrays _mv )
}
#endif
void cv::split(InputArray _m, OutputArrayOfArrays _mv)
{
if (ocl::useOpenCL() && _m.dims() <= 2 && _mv.isUMatVector() &&
ocl_split(_m, _mv))
return;
CV_OCL_RUN(_m.dims() <= 2 && _mv.isUMatVector(),
ocl_split(_m, _mv))
Mat m = _m.getMat();
if( m.empty() )
@ -395,6 +398,8 @@ void cv::merge(const Mat* mv, size_t n, OutputArray _dst)
}
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_merge( InputArrayOfArrays _mv, OutputArray _dst )
@ -442,10 +447,12 @@ static bool ocl_merge( InputArrayOfArrays _mv, OutputArray _dst )
}
#endif
void cv::merge(InputArrayOfArrays _mv, OutputArray _dst)
{
if (ocl::useOpenCL() && _mv.isUMatVector() && _dst.isUMat() && ocl_merge(_mv, _dst))
return;
CV_OCL_RUN(_mv.isUMatVector() && _dst.isUMat(),
ocl_merge(_mv, _dst))
std::vector<Mat> mv;
_mv.getMatVector(mv);
@ -612,6 +619,8 @@ void cv::mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, cons
}
}
#ifdef HAVE_OPENCL
namespace cv {
static void getUMatIndex(const std::vector<UMat> & um, int cn, int & idx, int & cnidx)
@ -701,15 +710,16 @@ static bool ocl_mixChannels(InputArrayOfArrays _src, InputOutputArrayOfArrays _d
}
#endif
void cv::mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
const int* fromTo, size_t npairs)
{
if (npairs == 0 || fromTo == NULL)
return;
if (ocl::useOpenCL() && src.isUMatVector() && dst.isUMatVector() &&
ocl_mixChannels(src, dst, fromTo, npairs))
return;
CV_OCL_RUN(src.isUMatVector() && dst.isUMatVector(),
ocl_mixChannels(src, dst, fromTo, npairs))
bool src_is_mat = src.kind() != _InputArray::STD_VECTOR_MAT &&
src.kind() != _InputArray::STD_VECTOR_VECTOR &&
@ -737,9 +747,8 @@ void cv::mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
if (fromTo.empty())
return;
if (ocl::useOpenCL() && src.isUMatVector() && dst.isUMatVector() &&
ocl_mixChannels(src, dst, &fromTo[0], fromTo.size()>>1))
return;
CV_OCL_RUN(src.isUMatVector() && dst.isUMatVector(),
ocl_mixChannels(src, dst, &fromTo[0], fromTo.size()>>1))
bool src_is_mat = src.kind() != _InputArray::STD_VECTOR_MAT &&
src.kind() != _InputArray::STD_VECTOR_VECTOR &&
@ -1284,6 +1293,8 @@ static BinaryFunc getConvertScaleFunc(int sdepth, int ddepth)
return cvtScaleTab[CV_MAT_DEPTH(ddepth)][CV_MAT_DEPTH(sdepth)];
}
#ifdef HAVE_OPENCL
static bool ocl_convertScaleAbs( InputArray _src, OutputArray _dst, double alpha, double beta )
{
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
@ -1319,13 +1330,14 @@ static bool ocl_convertScaleAbs( InputArray _src, OutputArray _dst, double alpha
return k.run(2, globalsize, NULL, false);
}
#endif
}
void cv::convertScaleAbs( InputArray _src, OutputArray _dst, double alpha, double beta )
{
if (ocl::useOpenCL() && _src.dims() <= 2 && _dst.isUMat() &&
ocl_convertScaleAbs(_src, _dst, alpha, beta))
return;
CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat(),
ocl_convertScaleAbs(_src, _dst, alpha, beta))
Mat src = _src.getMat();
int cn = src.channels();
@ -1462,9 +1474,7 @@ static LUTFunc lutTab[] =
(LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f, 0
};
}
namespace cv {
#ifdef HAVE_OPENCL
static bool ocl_LUT(InputArray _src, InputArray _lut, OutputArray _dst)
{
@ -1489,7 +1499,9 @@ static bool ocl_LUT(InputArray _src, InputArray _lut, OutputArray _dst)
return k.run(2, globalSize, NULL, false);
}
} // cv
#endif
}
void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst )
{
@ -1500,8 +1512,8 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst )
_lut.total() == 256 && _lut.isContinuous() &&
(depth == CV_8U || depth == CV_8S) );
if (ocl::useOpenCL() && _dst.isUMat() && ocl_LUT(_src, _lut, _dst))
return;
CV_OCL_RUN(_dst.isUMat(),
ocl_LUT(_src, _lut, _dst))
Mat src = _src.getMat(), lut = _lut.getMat();
_dst.create(src.dims, src.size, CV_MAKETYPE(_lut.depth(), cn));
@ -1521,6 +1533,8 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst )
namespace cv {
#ifdef HAVE_OPENCL
static bool ocl_normalize( InputArray _src, OutputArray _dst, InputArray _mask, int rtype,
double scale, double shift )
{
@ -1538,6 +1552,8 @@ static bool ocl_normalize( InputArray _src, OutputArray _dst, InputArray _mask,
return true;
}
#endif
}
void cv::normalize( InputArray _src, OutputArray _dst, double a, double b,
@ -1566,9 +1582,8 @@ void cv::normalize( InputArray _src, OutputArray _dst, double a, double b,
rtype = _dst.fixedType() ? _dst.depth() : depth;
_dst.createSameSize(_src, CV_MAKETYPE(rtype, cn));
if (ocl::useOpenCL() && _dst.isUMat() &&
ocl_normalize(_src, _dst, _mask, rtype, scale, shift))
return;
CV_OCL_RUN(_dst.isUMat(),
ocl_normalize(_src, _dst, _mask, rtype, scale, shift))
Mat src = _src.getMat(), dst = _dst.getMat();
if( _mask.empty() )

View File

@ -475,6 +475,8 @@ flipVert( const uchar* src0, size_t sstep, uchar* dst0, size_t dstep, Size size,
}
}
#ifdef HAVE_OPENCL
enum { FLIP_COLS = 1 << 0, FLIP_ROWS = 1 << 1, FLIP_BOTH = FLIP_ROWS | FLIP_COLS };
static bool ocl_flip(InputArray _src, OutputArray _dst, int flipCode )
@ -519,13 +521,13 @@ static bool ocl_flip(InputArray _src, OutputArray _dst, int flipCode )
return k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst), rows, cols).run(2, globalsize, NULL, false);
}
#endif
void flip( InputArray _src, OutputArray _dst, int flip_mode )
{
CV_Assert( _src.dims() <= 2 );
bool use_opencl = ocl::useOpenCL() && _dst.isUMat();
if ( use_opencl && ocl_flip(_src,_dst, flip_mode))
return;
CV_OCL_RUN( _dst.isUMat(), ocl_flip(_src,_dst, flip_mode))
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
@ -541,6 +543,7 @@ void flip( InputArray _src, OutputArray _dst, int flip_mode )
flipHoriz( dst.data, dst.step, dst.data, dst.step, dst.size(), esz );
}
#ifdef HAVE_OPENCL
static bool ocl_repeat(InputArray _src, int ny, int nx, OutputArray _dst)
{
@ -556,6 +559,8 @@ static bool ocl_repeat(InputArray _src, int ny, int nx, OutputArray _dst)
return true;
}
#endif
void repeat(InputArray _src, int ny, int nx, OutputArray _dst)
{
CV_Assert( _src.dims() <= 2 );
@ -564,11 +569,8 @@ void repeat(InputArray _src, int ny, int nx, OutputArray _dst)
Size ssize = _src.size();
_dst.create(ssize.height*ny, ssize.width*nx, _src.type());
if (ocl::useOpenCL() && _src.isUMat())
{
CV_Assert(ocl_repeat(_src, ny, nx, _dst));
return;
}
CV_OCL_RUN(_dst.isUMat(),
ocl_repeat(_src, ny, nx, _dst))
Mat src = _src.getMat(), dst = _dst.getMat();
Size dsize = dst.size();
@ -768,6 +770,8 @@ void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, cv::Size srcroi,
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
@ -824,14 +828,15 @@ static bool ocl_copyMakeBorder( InputArray _src, OutputArray _dst, int top, int
}
#endif
void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
int left, int right, int borderType, const Scalar& value )
{
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
if (ocl::useOpenCL() && _dst.isUMat() && _src.dims() <= 2 &&
ocl_copyMakeBorder(_src, _dst, top, bottom, left, right, borderType, value))
return;
CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2,
ocl_copyMakeBorder(_src, _dst, top, bottom, left, right, borderType, value))
Mat src = _src.getMat();

View File

@ -1726,9 +1726,9 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags)
void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows )
{
#ifdef HAVE_CLAMDFFT
if (ocl::useOpenCL() && ocl::haveAmdFft() && ocl::Device::getDefault().type() != ocl::Device::TYPE_CPU &&
_dst.isUMat() && _src0.dims() <= 2 && nonzero_rows == 0 && ocl_dft(_src0, _dst, flags))
return;
CV_OCL_RUN(ocl::haveAmdFft() && ocl::Device::getDefault().type() != ocl::Device::TYPE_CPU &&
_dst.isUMat() && _src0.dims() <= 2 && nonzero_rows == 0,
ocl_dft(_src0, _dst, flags))
#endif
static DFTFunc dft_tbl[6] =
@ -2135,6 +2135,8 @@ void cv::idft( InputArray src, OutputArray dst, int flags, int nonzero_rows )
dft( src, dst, flags | DFT_INVERSE, nonzero_rows );
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_mulSpectrums( InputArray _srcA, InputArray _srcB,
@ -2168,12 +2170,13 @@ static bool ocl_mulSpectrums( InputArray _srcA, InputArray _srcB,
}
#endif
void cv::mulSpectrums( InputArray _srcA, InputArray _srcB,
OutputArray _dst, int flags, bool conjB )
{
if (ocl::useOpenCL() && _dst.isUMat() &&
CV_OCL_RUN(_dst.isUMat() && _srcA.dims() <= 2 && _srcB.dims() <= 2,
ocl_mulSpectrums(_srcA, _srcB, _dst, flags, conjB))
return;
Mat srcA = _srcA.getMat(), srcB = _srcB.getMat();
int depth = srcA.depth(), cn = srcA.channels(), type = srcA.type();

View File

@ -54,6 +54,7 @@ static const float atan2_p3 = -0.3258083974640975f*(float)(180/CV_PI);
static const float atan2_p5 = 0.1555786518463281f*(float)(180/CV_PI);
static const float atan2_p7 = -0.04432655554792128f*(float)(180/CV_PI);
#ifdef HAVE_OPENCL
enum { OCL_OP_LOG=0, OCL_OP_EXP=1, OCL_OP_MAG=2, OCL_OP_PHASE_DEGREES=3, OCL_OP_PHASE_RADIANS=4 };
@ -98,6 +99,8 @@ static bool ocl_math_op(InputArray _src1, InputArray _src2, OutputArray _dst, in
return k.run(2, globalsize, 0, false);
}
#endif
float fastAtan2( float y, float x )
{
float ax = std::abs(x), ay = std::abs(y);
@ -401,11 +404,8 @@ void magnitude( InputArray src1, InputArray src2, OutputArray dst )
int type = src1.type(), depth = src1.depth(), cn = src1.channels();
CV_Assert( src1.size() == src2.size() && type == src2.type() && (depth == CV_32F || depth == CV_64F));
bool use_opencl = dst.isUMat() && ocl::useOpenCL()
&& src1.dims() <= 2 && src2.dims() <= 2;
if(use_opencl && ocl_math_op(src1, src2, dst, OCL_OP_MAG) )
return;
CV_OCL_RUN(dst.isUMat() && src1.dims() <= 2 && src2.dims() <= 2,
ocl_math_op(src1, src2, dst, OCL_OP_MAG))
Mat X = src1.getMat(), Y = src2.getMat();
dst.create(X.dims, X.size, X.type());
@ -439,11 +439,8 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre
int type = src1.type(), depth = src1.depth(), cn = src1.channels();
CV_Assert( src1.size() == src2.size() && type == src2.type() && (depth == CV_32F || depth == CV_64F));
bool use_opencl = dst.isUMat() && ocl::useOpenCL()
&& src1.dims() <= 2 && src2.dims() <= 2;
if(use_opencl && ocl_math_op(src1, src2, dst, angleInDegrees ? OCL_OP_PHASE_DEGREES : OCL_OP_PHASE_RADIANS) )
return;
CV_OCL_RUN(dst.isUMat() && src1.dims() <= 2 && src2.dims() <= 2,
ocl_math_op(src1, src2, dst, angleInDegrees ? OCL_OP_PHASE_DEGREES : OCL_OP_PHASE_RADIANS))
Mat X = src1.getMat(), Y = src2.getMat();
dst.create( X.dims, X.size, type );
@ -497,6 +494,8 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre
}
}
#ifdef HAVE_OPENCL
static bool ocl_cartToPolar( InputArray _src1, InputArray _src2,
OutputArray _dst1, OutputArray _dst2, bool angleInDegrees )
{
@ -533,12 +532,13 @@ static bool ocl_cartToPolar( InputArray _src1, InputArray _src2,
return k.run(2, globalsize, NULL, false);
}
#endif
void cartToPolar( InputArray src1, InputArray src2,
OutputArray dst1, OutputArray dst2, bool angleInDegrees )
{
if (ocl::useOpenCL() && dst1.isUMat() && dst2.isUMat() &&
CV_OCL_RUN(dst1.isUMat() && dst2.isUMat(),
ocl_cartToPolar(src1, src2, dst1, dst2, angleInDegrees))
return;
Mat X = src1.getMat(), Y = src2.getMat();
int type = X.type(), depth = X.depth(), cn = X.channels();
@ -683,6 +683,8 @@ static void SinCos_32f( const float *angle, float *sinval, float* cosval,
}
#ifdef HAVE_OPENCL
static bool ocl_polarToCart( InputArray _mag, InputArray _angle,
OutputArray _dst1, OutputArray _dst2, bool angleInDegrees )
{
@ -715,15 +717,16 @@ static bool ocl_polarToCart( InputArray _mag, InputArray _angle,
return k.run(2, globalsize, NULL, false);
}
#endif
void polarToCart( InputArray src1, InputArray src2,
OutputArray dst1, OutputArray dst2, bool angleInDegrees )
{
int type = src2.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
CV_Assert((depth == CV_32F || depth == CV_64F) && (src1.empty() || src1.type() == type));
if (ocl::useOpenCL() && !src1.empty() && src2.dims() <= 2 && dst1.isUMat() && dst2.isUMat() &&
ocl_polarToCart(src1, src2, dst1, dst2, angleInDegrees))
return;
CV_OCL_RUN(!src1.empty() && src2.dims() <= 2 && dst1.isUMat() && dst2.isUMat(),
ocl_polarToCart(src1, src2, dst1, dst2, angleInDegrees))
Mat Mag = src1.getMat(), Angle = src2.getMat();
CV_Assert( Mag.empty() || Angle.size == Mag.size);
@ -1289,10 +1292,8 @@ void exp( InputArray _src, OutputArray _dst )
int type = _src.type(), depth = _src.depth(), cn = _src.channels();
CV_Assert( depth == CV_32F || depth == CV_64F );
bool use_opencl = _dst.isUMat() && ocl::useOpenCL() && _src.dims() <= 2;
if(use_opencl && ocl_math_op(_src, noArray(), _dst, OCL_OP_EXP) )
return;
CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2,
ocl_math_op(_src, noArray(), _dst, OCL_OP_EXP))
Mat src = _src.getMat();
_dst.create( src.dims, src.size, type );
@ -1938,10 +1939,8 @@ void log( InputArray _src, OutputArray _dst )
int type = _src.type(), depth = _src.depth(), cn = _src.channels();
CV_Assert( depth == CV_32F || depth == CV_64F );
bool use_opencl = _dst.isUMat() && ocl::useOpenCL() && _src.dims() <= 2;
if(use_opencl && ocl_math_op(_src, noArray(), _dst, OCL_OP_LOG) )
return;
CV_OCL_RUN( _dst.isUMat() && _src.dims() <= 2,
ocl_math_op(_src, noArray(), _dst, OCL_OP_LOG))
Mat src = _src.getMat();
_dst.create( src.dims, src.size, type );
@ -2032,6 +2031,8 @@ static IPowFunc ipowTab[] =
(IPowFunc)iPow32s, (IPowFunc)iPow32f, (IPowFunc)iPow64f, 0
};
#ifdef HAVE_OPENCL
static bool ocl_pow(InputArray _src, double power, OutputArray _dst)
{
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
@ -2071,10 +2072,12 @@ static bool ocl_pow(InputArray _src, double power, OutputArray _dst)
return k.run(2, globalsize, NULL, false);
}
#endif
void pow( InputArray _src, double power, OutputArray _dst )
{
if (ocl::useOpenCL() && _dst.isUMat() && ocl_pow(_src, power, _dst))
return;
CV_OCL_RUN(_dst.isUMat(),
ocl_pow(_src, power, _dst))
Mat src = _src.getMat();
int type = src.type(), depth = src.depth(), cn = src.channels();
@ -2369,6 +2372,8 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
return badPt.x < 0;
}
#ifdef HAVE_OPENCL
static bool ocl_patchNaNs( InputOutputArray _a, float value )
{
ocl::Kernel k("KF", ocl::core::arithm_oclsrc,
@ -2386,12 +2391,14 @@ static bool ocl_patchNaNs( InputOutputArray _a, float value )
return k.run(2, globalsize, NULL, false);
}
#endif
void patchNaNs( InputOutputArray _a, double _val )
{
CV_Assert( _a.depth() == CV_32F );
if (ocl::useOpenCL() && _a.isUMat() && _a.dims() <= 2 && ocl_patchNaNs(_a, (float)_val))
return;
CV_OCL_RUN(_a.isUMat() && _a.dims() <= 2,
ocl_patchNaNs(_a, (float)_val))
Mat a = _a.getMat();
const Mat* arrays[] = {&a, 0};

View File

@ -785,10 +785,8 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha,
InputArray matC, double beta, OutputArray _matD, int flags )
{
#ifdef HAVE_CLAMDBLAS
if (ocl::haveAmdBlas() && matA.dims() <= 2 && matB.dims() <= 2 && matC.dims() <= 2 &&
ocl::useOpenCL() && _matD.isUMat() &&
CV_OCL_RUN(ocl::haveAmdBlas() && matA.dims() <= 2 && matB.dims() <= 2 && matC.dims() <= 2 && _matD.isUMat(),
ocl_gemm(matA, matB, alpha, matC, beta, _matD, flags))
return;
#endif
const int block_lin_size = 128;
@ -2155,6 +2153,8 @@ static void scaleAdd_64f(const double* src1, const double* src2, double* dst,
typedef void (*ScaleAddFunc)(const uchar* src1, const uchar* src2, uchar* dst, int len, const void* alpha);
#ifdef HAVE_OPENCL
static bool ocl_scaleAdd( InputArray _src1, double alpha, InputArray _src2, OutputArray _dst, int type )
{
int depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type), wdepth = std::max(depth, CV_32F);
@ -2190,6 +2190,8 @@ static bool ocl_scaleAdd( InputArray _src1, double alpha, InputArray _src2, Outp
return k.run(2, globalsize, NULL, false);
}
#endif
}
void cv::scaleAdd( InputArray _src1, double alpha, InputArray _src2, OutputArray _dst )
@ -2197,9 +2199,8 @@ void cv::scaleAdd( InputArray _src1, double alpha, InputArray _src2, OutputArray
int type = _src1.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
CV_Assert( type == _src2.type() );
if (ocl::useOpenCL() && _src1.dims() <= 2 && _src2.dims() <= 2 && _dst.isUMat() &&
CV_OCL_RUN(_src1.dims() <= 2 && _src2.dims() <= 2 && _dst.isUMat(),
ocl_scaleAdd(_src1, alpha, _src2, _dst, type))
return;
if( depth < CV_32F )
{

View File

@ -2558,6 +2558,8 @@ void cv::vconcat(InputArray _src, OutputArray dst)
//////////////////////////////////////// set identity ////////////////////////////////////////////
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_setIdentity( InputOutputArray _m, const Scalar& s )
@ -2580,12 +2582,14 @@ static bool ocl_setIdentity( InputOutputArray _m, const Scalar& s )
}
#endif
void cv::setIdentity( InputOutputArray _m, const Scalar& s )
{
CV_Assert( _m.dims() <= 2 );
if (ocl::useOpenCL() && _m.isUMat() && ocl_setIdentity(_m, s))
return;
CV_OCL_RUN(_m.isUMat(),
ocl_setIdentity(_m, s))
Mat m = _m.getMat();
int i, j, rows = m.rows, cols = m.cols, type = m.type();
@ -2764,6 +2768,8 @@ static TransposeInplaceFunc transposeInplaceTab[] =
0, 0, 0, 0, 0, 0, 0, transposeI_32sC6, 0, 0, 0, 0, 0, 0, 0, transposeI_32sC8
};
#ifdef HAVE_OPENCL
static inline int divUp(int a, int b)
{
return (a + b - 1) / b;
@ -2805,6 +2811,8 @@ static bool ocl_transpose( InputArray _src, OutputArray _dst )
return k.run(2, globalsize, localsize, false);
}
#endif
}
void cv::transpose( InputArray _src, OutputArray _dst )
@ -2812,8 +2820,8 @@ void cv::transpose( InputArray _src, OutputArray _dst )
int type = _src.type(), esz = CV_ELEM_SIZE(type);
CV_Assert( _src.dims() <= 2 && esz <= 32 );
if (ocl::useOpenCL() && _dst.isUMat() && ocl_transpose(_src, _dst))
return;
CV_OCL_RUN(_dst.isUMat(),
ocl_transpose(_src, _dst))
Mat src = _src.getMat();
if( src.empty() )
@ -3043,6 +3051,8 @@ typedef void (*ReduceFunc)( const Mat& src, Mat& dst );
#define reduceMinC32f reduceC_<float, float, OpMin<float> >
#define reduceMinC64f reduceC_<double,double,OpMin<double> >
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_reduce(InputArray _src, OutputArray _dst,
@ -3096,6 +3106,8 @@ static bool ocl_reduce(InputArray _src, OutputArray _dst,
}
#endif
void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype)
{
CV_Assert( _src.dims() <= 2 );
@ -3110,9 +3122,8 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype)
CV_Assert( op == CV_REDUCE_SUM || op == CV_REDUCE_MAX ||
op == CV_REDUCE_MIN || op == CV_REDUCE_AVG );
if (ocl::useOpenCL() && _dst.isUMat() &&
ocl_reduce(_src, _dst, dim, op, op0, stype, dtype))
return;
CV_OCL_RUN(_dst.isUMat(),
ocl_reduce(_src, _dst, dim, op, op0, stype, dtype))
Mat src = _src.getMat();
_dst.create(dim == 0 ? 1 : src.rows, dim == 0 ? src.cols : 1, dtype);

View File

@ -464,6 +464,8 @@ template <typename T> Scalar ocl_part_sum(Mat m)
return s;
}
#ifdef HAVE_OPENCL
enum { OCL_OP_SUM = 0, OCL_OP_SUM_ABS = 1, OCL_OP_SUM_SQR = 2 };
static bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask = noArray() )
@ -523,13 +525,17 @@ static bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask
return false;
}
#endif
}
cv::Scalar cv::sum( InputArray _src )
{
#ifdef HAVE_OPENCL
Scalar _res;
if (ocl::useOpenCL() && _src.isUMat() && ocl_sum(_src, _res, OCL_OP_SUM))
return _res;
#endif
Mat src = _src.getMat();
int k, cn = src.channels(), depth = src.depth();
@ -621,6 +627,8 @@ cv::Scalar cv::sum( InputArray _src )
return s;
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_countNonZero( InputArray _src, int & res )
@ -658,13 +666,17 @@ static bool ocl_countNonZero( InputArray _src, int & res )
}
#endif
int cv::countNonZero( InputArray _src )
{
CV_Assert( _src.channels() == 1 );
#ifdef HAVE_OPENCL
int res = -1;
if (ocl::useOpenCL() && _src.isUMat() && ocl_countNonZero(_src, res))
return res;
#endif
Mat src = _src.getMat();
CountNonZeroFunc func = getCountNonZeroTab(src.depth());
@ -815,6 +827,8 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask )
return s*(nz0 ? 1./nz0 : 0);
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray _mask )
@ -861,10 +875,12 @@ static bool ocl_meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv
}
#endif
void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray _mask )
{
if (ocl::useOpenCL() && _src.isUMat() && ocl_meanStdDev(_src, _mean, _sdv, _mask))
return;
CV_OCL_RUN(_src.isUMat() && _src.dims() <= 2,
ocl_meanStdDev(_src, _mean, _sdv, _mask))
Mat src = _src.getMat(), mask = _mask.getMat();
CV_Assert( mask.empty() || mask.type() == CV_8U );
@ -1171,10 +1187,7 @@ static void ofs2idx(const Mat& a, size_t ofs, int* idx)
}
}
}
namespace cv
{
#ifdef HAVE_OPENCL
template <typename T>
void getMinMaxRes(const Mat &minv, const Mat &maxv, const Mat &minl, const Mat &maxl, double* minVal,
@ -1288,6 +1301,9 @@ static bool ocl_minMaxIdx( InputArray _src, double* minVal, double* maxVal, int*
return true;
}
#endif
}
void cv::minMaxIdx(InputArray _src, double* minVal,
@ -1297,9 +1313,8 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
CV_Assert( (_src.channels() == 1 && (_mask.empty() || _mask.type() == CV_8U)) ||
(_src.channels() >= 1 && _mask.empty() && !minIdx && !maxIdx) );
if( ocl::useOpenCL() && _src.isUMat() && _src.dims() <= 2 && ( _mask.empty() || _src.size() == _mask.size() )
&& ocl_minMaxIdx(_src, minVal, maxVal, minIdx, maxIdx, _mask) )
return;
CV_OCL_RUN(_src.isUMat() && _src.dims() <= 2 && (_mask.empty() || _src.size() == _mask.size()),
ocl_minMaxIdx(_src, minVal, maxVal, minIdx, maxIdx, _mask))
Mat src = _src.getMat(), mask = _mask.getMat();
int depth = src.depth(), cn = src.channels();
@ -1892,9 +1907,7 @@ static NormDiffFunc getNormDiffFunc(int normType, int depth)
return normDiffTab[normType][depth];
}
}
namespace cv {
#ifdef HAVE_OPENCL
static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double & result )
{
@ -1959,6 +1972,8 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double &
return true;
}
#endif
}
double cv::norm( InputArray _src, int normType, InputArray _mask )
@ -1968,9 +1983,11 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
normType == NORM_L2 || normType == NORM_L2SQR ||
((normType == NORM_HAMMING || normType == NORM_HAMMING2) && _src.type() == CV_8U) );
#ifdef HAVE_OPENCL
double _result = 0;
if (ocl::useOpenCL() && _src.isUMat() && _src.dims() <= 2 && ocl_norm(_src, normType, _mask, _result))
return _result;
#endif
Mat src = _src.getMat(), mask = _mask.getMat();
int depth = src.depth(), cn = src.channels();
@ -2252,6 +2269,8 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
return result.d;
}
#ifdef HAVE_OPENCL
namespace cv {
static bool ocl_norm( InputArray _src1, InputArray _src2, int normType, double & result )
@ -2293,14 +2312,18 @@ static bool ocl_norm( InputArray _src1, InputArray _src2, int normType, double &
}
#endif
double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _mask )
{
CV_Assert( _src1.sameSize(_src2) && _src1.type() == _src2.type() );
#ifdef HAVE_OPENCL
double _result = 0;
if (ocl::useOpenCL() && _mask.empty() && _src1.isUMat() && _src2.isUMat() &&
_src1.dims() <= 2 && _src2.dims() <= 2 && ocl_norm(_src1, _src2, normType, _result))
return _result;
#endif
if( normType & CV_RELATIVE )
{