diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index ba5c8fe87..d081d353a 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -560,8 +560,11 @@ namespace cudev template class GpuMat_; } -CV_EXPORTS void setIppStatus(int status); +CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, + int line = 0); CV_EXPORTS int getIppStatus(); +CV_EXPORTS String getIppErrorLocation(); +#define setIppErrorStatus() setIppStatus(-1, CV_Func, __FILE__, __LINE__) } // cv diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 190bdf98f..f7256b85f 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -464,7 +464,7 @@ static void add8u( const uchar* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAdd_8u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz), 0)) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -484,7 +484,7 @@ static void add16u( const ushort* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAdd_16u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz), 0)) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -497,7 +497,7 @@ static void add16s( const short* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAdd_16s_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz), 0)) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -517,7 +517,7 @@ static void add32f( const float* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAdd_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp32, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -537,7 +537,7 @@ static void sub8u( const uchar* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiSub_8u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz), 0)) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -557,7 +557,7 @@ static void sub16u( const ushort* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiSub_16u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz), 0)) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -570,7 +570,7 @@ static void sub16s( const short* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiSub_16s_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz), 0)) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -590,7 +590,7 @@ static void sub32f( const float* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiSub_32f_C1R(src2, (int)step2, src1, (int)step1, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp32, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -625,7 +625,7 @@ static void max8u( const uchar* src1, size_t step1, } if (i == sz.height) return; - setIppStatus(-1); + setIppErrorStatus(); #endif vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } @@ -657,7 +657,7 @@ static void max16u( const ushort* src1, size_t step1, } if (i == sz.height) return; - setIppStatus(-1); + setIppErrorStatus(); #endif vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } @@ -696,7 +696,7 @@ static void max32f( const float* src1, size_t step1, } if (i == sz.height) return; - setIppStatus(-1); + setIppErrorStatus(); #endif vBinOp32, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } @@ -728,7 +728,7 @@ static void min8u( const uchar* src1, size_t step1, } if (i == sz.height) return; - setIppStatus(-1); + setIppErrorStatus(); #endif vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } @@ -760,7 +760,7 @@ static void min16u( const ushort* src1, size_t step1, } if (i == sz.height) return; - setIppStatus(-1); + setIppErrorStatus(); #endif vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } @@ -799,7 +799,7 @@ static void min32f( const float* src1, size_t step1, } if (i == sz.height) return; - setIppStatus(-1); + setIppErrorStatus(); #endif vBinOp32, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } @@ -816,11 +816,10 @@ static void absdiff8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - printf("!\n"); fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAbsDiff_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } @@ -837,11 +836,10 @@ static void absdiff16u( const ushort* src1, size_t step1, ushort* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - printf("!\n"); fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAbsDiff_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } @@ -865,11 +863,10 @@ static void absdiff32f( const float* src1, size_t step1, float* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - printf("!\n"); fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAbsDiff_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp32, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } @@ -890,7 +887,7 @@ static void and8u( const uchar* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiAnd_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VAnd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -903,7 +900,7 @@ static void or8u( const uchar* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiOr_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VOr)>(src1, step1, src2, step2, dst, step, sz)); } @@ -916,7 +913,7 @@ static void xor8u( const uchar* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); if (0 <= ippiXor_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VXor)>(src1, step1, src2, step2, dst, step, sz)); } @@ -929,7 +926,7 @@ static void not8u( const uchar* src1, size_t step1, fixSteps(sz, sizeof(dst[0]), step1, step2, step); (void)src2; if (0 <= ippiNot_8u_C1R(src1, (int)step1, dst, (int)step, ippiSize(sz))) return; - setIppStatus(-1); + setIppErrorStatus(); #endif (vBinOp, IF_SIMD(VNot)>(src1, step1, src2, step2, dst, step, sz)); } @@ -2414,7 +2411,7 @@ static void cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t ste fixSteps(size, sizeof(dst[0]), step1, step2, step); if (0 <= ippiCompare_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op)) return; - setIppStatus(-1); + setIppErrorStatus(); } #endif //vz optimized cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); @@ -2498,7 +2495,7 @@ static void cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t fixSteps(size, sizeof(dst[0]), step1, step2, step); if (0 <= ippiCompare_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op)) return; - setIppStatus(-1); + setIppErrorStatus(); } #endif cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); @@ -2514,7 +2511,7 @@ static void cmp16s(const short* src1, size_t step1, const short* src2, size_t st fixSteps(size, sizeof(dst[0]), step1, step2, step); if (0 <= ippiCompare_16s_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op)) return; - setIppStatus(-1); + setIppErrorStatus(); } #endif //vz optimized cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); @@ -2621,7 +2618,7 @@ static void cmp32f(const float* src1, size_t step1, const float* src2, size_t st fixSteps(size, sizeof(dst[0]), step1, step2, step); if (0 <= ippiCompare_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, ippiSize(size), op)) return; - setIppStatus(-1); + setIppErrorStatus(); } #endif cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index 3d3f1aa62..e73dfef59 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -1086,7 +1086,7 @@ static void cvt##suffix( const stype* src, size_t sstep, const uchar*, size_t, \ { \ if (ippiConvert_##ippFavor(src, (int)sstep, dst, (int)dstep, ippiSize(size.width, size.height)) >= 0) \ return; \ - setIppStatus(-1); \ + setIppErrorStatus(); \ cvt_(src, sstep, dst, dstep, size); \ } @@ -1096,7 +1096,7 @@ static void cvt##suffix( const stype* src, size_t sstep, const uchar*, size_t, \ { \ if (ippiConvert_##ippFavor(src, (int)sstep, dst, (int)dstep, ippiSize(size.width, size.height), ippRndFinancial, 0) >= 0) \ return; \ - setIppStatus(-1); \ + setIppErrorStatus(); \ cvt_(src, sstep, dst, dstep, size); \ } #else diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 6a1ff4b3c..d21a39034 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -574,7 +574,7 @@ void flip( InputArray _src, OutputArray _dst, int flip_mode ) IppStatus status = ippFunc(src.data, (int)src.step, dst.data, (int)dst.step, ippiSize(src.cols, src.rows), axis); if (status >= 0) return; - setIppStatus(-1); + setIppErrorStatus(); } #endif diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index 37e4a3494..1c498cd01 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -235,14 +235,13 @@ void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t bl struct CoreTLSData { - CoreTLSData() : device(0), useOpenCL(-1), ippStatus(0) + CoreTLSData() : device(0), useOpenCL(-1) {} RNG rng; int device; ocl::Queue oclQueue; int useOpenCL; // 1 - use, 0 - do not use, -1 - auto/not initialized - int ippStatus; // 0 - all is ok, -1 - IPP functions failed }; extern TLSData coreTlsData; diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index cf4b98653..6081a6084 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1063,14 +1063,26 @@ TLSStorage::~TLSStorage() TLSData coreTlsData; -void setIppStatus(int status) +static int ippStatus = 0; // 0 - all is ok, -1 - IPP functions failed +static const char * funcname, * filename; +static int linen; + +void setIppStatus(int status, const char * const _funcname, const char * const _filename, int _line) { - coreTlsData.get()->ippStatus = status; + ippStatus = status; + funcname = _funcname; + filename = _filename; + linen = _line; } int getIppStatus() { - return coreTlsData.get()->ippStatus; + return ippStatus; +} + +String getIppErrorLocation() +{ + return format("%s:%d %s", filename ? filename : "", linen, funcname ? funcname : ""); } } // namespace cv diff --git a/modules/ts/include/opencv2/ts/ts_ext.hpp b/modules/ts/include/opencv2/ts/ts_ext.hpp index 14541fe89..97349a9a2 100644 --- a/modules/ts/include/opencv2/ts/ts_ext.hpp +++ b/modules/ts/include/opencv2/ts/ts_ext.hpp @@ -4,7 +4,7 @@ #define CHECK_IPP_STATUS \ do \ { \ - EXPECT_LE(0, getIppStatus()); \ + EXPECT_LE(0, getIppStatus()) << getIppErrorLocation().c_str(); \ } while ((void)0, 0) #undef TEST