mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
core: rework code locality
- to reduce binaries size of FFmpeg Windows wrapper
- MinGW linker doesn't support -ffunction-sections (used for FFmpeg Windows wrapper)
- move code to improve locality with its used dependencies
- move UMat::dot() to matmul.dispatch.cpp (Mat::dot() is already there)
- move UMat::inv() to lapack.cpp
- move UMat::mul() to arithm.cpp
- move UMat:eye() to matrix_operations.cpp (near setIdentity() implementation)
- move normalize(): convert_scale.cpp => norm.cpp
- move convertAndUnrollScalar(): arithm.cpp => copy.cpp
- move scalarToRawData(): array.cpp => copy.cpp
- move transpose(): matrix_operations.cpp => matrix_transform.cpp
- move flip(), rotate(): copy.cpp => matrix_transform.cpp (rotate90 uses flip and transpose)
- add 'OPENCV_CORE_EXCLUDE_C_API' CMake variable to exclude compilation of C-API functions from the core module
- matrix_wrap.cpp: add compile-time checks for CUDA/OpenGL calls
- the steps above allow to reduce FFmpeg wrapper size for ~1.5Mb (initial size of OpenCV part is about 3Mb)
backport is done to improve merge experience (less conflicts)
backport of commit: 65eb946756
This commit is contained in:
@@ -1259,88 +1259,6 @@ UMat UMat::t() const
|
||||
return m;
|
||||
}
|
||||
|
||||
UMat UMat::inv(int method) const
|
||||
{
|
||||
UMat m;
|
||||
invert(*this, m, method);
|
||||
return m;
|
||||
}
|
||||
|
||||
UMat UMat::mul(InputArray m, double scale) const
|
||||
{
|
||||
UMat dst;
|
||||
multiply(*this, m, dst, scale);
|
||||
return dst;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
static bool ocl_dot( InputArray _src1, InputArray _src2, double & res )
|
||||
{
|
||||
UMat src1 = _src1.getUMat().reshape(1), src2 = _src2.getUMat().reshape(1);
|
||||
|
||||
int type = src1.type(), depth = CV_MAT_DEPTH(type),
|
||||
kercn = ocl::predictOptimalVectorWidth(src1, src2);
|
||||
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
|
||||
|
||||
if ( !doubleSupport && depth == CV_64F )
|
||||
return false;
|
||||
|
||||
int dbsize = ocl::Device::getDefault().maxComputeUnits();
|
||||
size_t wgs = ocl::Device::getDefault().maxWorkGroupSize();
|
||||
int ddepth = std::max(CV_32F, depth);
|
||||
|
||||
int wgs2_aligned = 1;
|
||||
while (wgs2_aligned < (int)wgs)
|
||||
wgs2_aligned <<= 1;
|
||||
wgs2_aligned >>= 1;
|
||||
|
||||
char cvt[40];
|
||||
ocl::Kernel k("reduce", ocl::core::reduce_oclsrc,
|
||||
format("-D srcT=%s -D srcT1=%s -D dstT=%s -D dstTK=%s -D ddepth=%d -D convertToDT=%s -D OP_DOT "
|
||||
"-D WGS=%d -D WGS2_ALIGNED=%d%s%s%s -D kercn=%d",
|
||||
ocl::typeToStr(CV_MAKE_TYPE(depth, kercn)), ocl::typeToStr(depth),
|
||||
ocl::typeToStr(ddepth), ocl::typeToStr(CV_MAKE_TYPE(ddepth, kercn)),
|
||||
ddepth, ocl::convertTypeStr(depth, ddepth, kercn, cvt),
|
||||
(int)wgs, wgs2_aligned, doubleSupport ? " -D DOUBLE_SUPPORT" : "",
|
||||
_src1.isContinuous() ? " -D HAVE_SRC_CONT" : "",
|
||||
_src2.isContinuous() ? " -D HAVE_SRC2_CONT" : "", kercn));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat db(1, dbsize, ddepth);
|
||||
|
||||
ocl::KernelArg src1arg = ocl::KernelArg::ReadOnlyNoSize(src1),
|
||||
src2arg = ocl::KernelArg::ReadOnlyNoSize(src2),
|
||||
dbarg = ocl::KernelArg::PtrWriteOnly(db);
|
||||
|
||||
k.args(src1arg, src1.cols, (int)src1.total(), dbsize, dbarg, src2arg);
|
||||
|
||||
size_t globalsize = dbsize * wgs;
|
||||
if (k.run(1, &globalsize, &wgs, false))
|
||||
{
|
||||
res = sum(db.getMat(ACCESS_READ))[0];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
double UMat::dot(InputArray m) const
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
CV_Assert(m.sameSize(*this) && m.type() == type());
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
double r = 0;
|
||||
CV_OCL_RUN_(dims <= 2, ocl_dot(*this, m, r), r)
|
||||
#endif
|
||||
|
||||
return getMat(ACCESS_READ).dot(m);
|
||||
}
|
||||
|
||||
UMat UMat::zeros(int rows, int cols, int type)
|
||||
{
|
||||
return UMat(rows, cols, type, Scalar::all(0));
|
||||
@@ -1371,18 +1289,6 @@ UMat UMat::ones(int ndims, const int* sz, int type)
|
||||
return UMat(ndims, sz, type, Scalar(1));
|
||||
}
|
||||
|
||||
UMat UMat::eye(int rows, int cols, int type)
|
||||
{
|
||||
return UMat::eye(Size(cols, rows), type);
|
||||
}
|
||||
|
||||
UMat UMat::eye(Size size, int type)
|
||||
{
|
||||
UMat m(size, type);
|
||||
setIdentity(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
Reference in New Issue
Block a user