From d2aaa70e93c20f254e43bc743f142f42cd54786f Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 22 May 2015 16:04:10 +0300 Subject: [PATCH] removed HAL calls from public OpenCV headers; put IPP calls back to hall:sqrt() and such (but they are disabled for now) --- modules/core/include/opencv2/core/base.hpp | 33 ++++------ modules/core/include/opencv2/core/matx.hpp | 2 +- .../core/include/opencv2/core/operations.hpp | 4 +- modules/core/src/lapack.cpp | 20 ++++++ modules/hal/src/mathfuncs.cpp | 64 +++++++++++++++++++ 5 files changed, 100 insertions(+), 23 deletions(-) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index e4efe0fb9b..742e0d2ca8 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -492,17 +492,9 @@ _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n) return s; } -inline float normL2Sqr(const float* a, const float* b, int n) +static inline float normL2Sqr(const float* a, const float* b, int n) { - if( n >= 8 ) - return hal::normL2Sqr_(a, b, n); - float s = 0; - for( int i = 0; i < n; i++ ) - { - float v = a[i] - b[i]; - s += v*v; - } - return s; + return normL2Sqr(a, b, n); } template static inline @@ -527,20 +519,12 @@ _AccTp normL1(const _Tp* a, const _Tp* b, int n) inline float normL1(const float* a, const float* b, int n) { - if( n >= 8 ) - return hal::normL1_(a, b, n); - float s = 0; - for( int i = 0; i < n; i++ ) - { - float v = a[i] - b[i]; - s += std::abs(v); - } - return s; + return normL1(a, b, n); } inline int normL1(const uchar* a, const uchar* b, int n) { - return hal::normL1_(a, b, n); + return normL1(a, b, n); } template static inline @@ -573,6 +557,15 @@ CV_EXPORTS_W float cubeRoot(float val); */ CV_EXPORTS_W float fastAtan2(float y, float x); +/** proxy for hal::LU */ +CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); +/** proxy for hal::LU */ +CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); +/** proxy for hal::Cholesky */ +CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); +/** proxy for hal::Cholesky */ +CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); + ////////////////// forward declarations for important OpenCV types ////////////////// //! @cond IGNORED diff --git a/modules/core/include/opencv2/core/matx.hpp b/modules/core/include/opencv2/core/matx.hpp index e9023243e8..6cc5d06251 100644 --- a/modules/core/include/opencv2/core/matx.hpp +++ b/modules/core/include/opencv2/core/matx.hpp @@ -427,7 +427,7 @@ template struct Matx_DetOp double operator ()(const Matx<_Tp, m, m>& a) const { Matx<_Tp, m, m> temp = a; - double p = hal::LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0); + double p = LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0); if( p == 0 ) return p; for( int i = 0; i < m; i++ ) diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 2c42e1f3a3..bced1a7559 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -72,9 +72,9 @@ template struct Matx_FastInvOp b(i, i) = (_Tp)1; if( method == DECOMP_CHOLESKY ) - return hal::Cholesky(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m); + return Cholesky(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m); - return hal::LU(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m) != 0; + return LU(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m) != 0; } }; diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index e246a7c400..b3e1b52941 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -50,6 +50,26 @@ namespace cv { +int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n) +{ + return hal::LU(A, astep, m, b, bstep, n); +} + +int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n) +{ + return hal::LU(A, astep, m, b, bstep, n); +} + +bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n) +{ + return hal::Cholesky(A, astep, m, b, bstep, n); +} + +bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n) +{ + return hal::Cholesky(A, astep, m, b, bstep, n); +} + template static inline _Tp hypot(_Tp a, _Tp b) { a = std::abs(a); diff --git a/modules/hal/src/mathfuncs.cpp b/modules/hal/src/mathfuncs.cpp index 7d0199f00c..66a03e1a58 100644 --- a/modules/hal/src/mathfuncs.cpp +++ b/modules/hal/src/mathfuncs.cpp @@ -42,6 +42,8 @@ #include "precomp.hpp" +#undef HAVE_IPP + namespace cv { namespace hal { ///////////////////////////////////// ATAN2 //////////////////////////////////// @@ -160,6 +162,19 @@ void fastAtan2(const float *Y, const float *X, float *angle, int len, bool angle void magnitude(const float* x, const float* y, float* mag, int len) { +#if defined HAVE_IPP + CV_IPP_CHECK() + { + IppStatus status = ippsMagnitude_32f(x, y, mag, len); + if (status >= 0) + { + CV_IMPL_ADD(CV_IMPL_IPP); + return; + } + setIppErrorStatus(); + } +#endif + int i = 0; #if CV_SIMD128 @@ -183,6 +198,19 @@ void magnitude(const float* x, const float* y, float* mag, int len) void magnitude(const double* x, const double* y, double* mag, int len) { +#if defined(HAVE_IPP) + CV_IPP_CHECK() + { + IppStatus status = ippsMagnitude_64f(x, y, mag, len); + if (status >= 0) + { + CV_IMPL_ADD(CV_IMPL_IPP); + return; + } + setIppErrorStatus(); + } +#endif + int i = 0; #if CV_SIMD128_64F @@ -207,6 +235,18 @@ void magnitude(const double* x, const double* y, double* mag, int len) void invSqrt(const float* src, float* dst, int len) { +#if defined(HAVE_IPP) + CV_IPP_CHECK() + { + if (ippsInvSqrt_32f_A21(src, dst, len) >= 0) + { + CV_IMPL_ADD(CV_IMPL_IPP); + return; + } + setIppErrorStatus(); + } +#endif + int i = 0; #if CV_SIMD128 @@ -241,6 +281,18 @@ void invSqrt(const double* src, double* dst, int len) void sqrt(const float* src, float* dst, int len) { +#if defined(HAVE_IPP) + CV_IPP_CHECK() + { + if (ippsSqrt_32f_A21(src, dst, len) >= 0) + { + CV_IMPL_ADD(CV_IMPL_IPP); + return; + } + setIppErrorStatus(); + } +#endif + int i = 0; #if CV_SIMD128 @@ -260,6 +312,18 @@ void sqrt(const float* src, float* dst, int len) void sqrt(const double* src, double* dst, int len) { +#if defined(HAVE_IPP) + CV_IPP_CHECK() + { + if (ippsSqrt_64f_A50(src, dst, len) >= 0) + { + CV_IMPL_ADD(CV_IMPL_IPP); + return; + } + setIppErrorStatus(); + } +#endif + int i = 0; #if CV_SIMD128_64F