From f3c56f8310f16069922f1c8eae20882b64bae5cb Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 16 Apr 2014 15:34:18 +0400 Subject: [PATCH] first attemp --- modules/core/include/opencv2/core/base.hpp | 3 + modules/core/src/arithm.cpp | 28 ++++++++++ modules/core/src/convert.cpp | 2 + modules/core/src/copy.cpp | 1 + modules/core/src/precomp.hpp | 3 +- modules/core/src/system.cpp | 10 ++++ modules/ts/include/opencv2/ts.hpp | 3 +- modules/ts/include/opencv2/ts/ts_ext.hpp | 89 ++++++++++++++++++++++++++++++ modules/ts/include/opencv2/ts/ts_perf.hpp | 3 +- 9 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 modules/ts/include/opencv2/ts/ts_ext.hpp diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index e9187fa..ba5c8fe 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -560,6 +560,9 @@ namespace cudev template class GpuMat_; } +CV_EXPORTS void setIppStatus(int status); +CV_EXPORTS int getIppStatus(); + } // cv #endif //__OPENCV_CORE_BASE_HPP__ diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index b74678c..190bdf9 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -464,6 +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); #endif (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -483,6 +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); #endif (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -495,6 +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); #endif (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -514,6 +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); #endif (vBinOp32, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -533,6 +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); #endif (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -552,6 +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); #endif (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -564,6 +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); #endif (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -583,6 +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); #endif (vBinOp32, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } @@ -617,6 +625,7 @@ static void max8u( const uchar* src1, size_t step1, } if (i == sz.height) return; + setIppStatus(-1); #endif vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } @@ -648,6 +657,7 @@ static void max16u( const ushort* src1, size_t step1, } if (i == sz.height) return; + setIppStatus(-1); #endif vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } @@ -686,6 +696,7 @@ static void max32f( const float* src1, size_t step1, } if (i == sz.height) return; + setIppStatus(-1); #endif vBinOp32, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } @@ -717,6 +728,7 @@ static void min8u( const uchar* src1, size_t step1, } if (i == sz.height) return; + setIppStatus(-1); #endif vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } @@ -748,6 +760,7 @@ static void min16u( const ushort* src1, size_t step1, } if (i == sz.height) return; + setIppStatus(-1); #endif vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } @@ -786,6 +799,7 @@ static void min32f( const float* src1, size_t step1, } if (i == sz.height) return; + setIppStatus(-1); #endif vBinOp32, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } @@ -802,9 +816,11 @@ 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); #endif (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } @@ -821,9 +837,11 @@ 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); #endif (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } @@ -847,9 +865,11 @@ 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); #endif (vBinOp32, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } @@ -870,6 +890,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); #endif (vBinOp, IF_SIMD(VAnd)>(src1, step1, src2, step2, dst, step, sz)); } @@ -882,6 +903,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); #endif (vBinOp, IF_SIMD(VOr)>(src1, step1, src2, step2, dst, step, sz)); } @@ -894,6 +916,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); #endif (vBinOp, IF_SIMD(VXor)>(src1, step1, src2, step2, dst, step, sz)); } @@ -906,6 +929,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); #endif (vBinOp, IF_SIMD(VNot)>(src1, step1, src2, step2, dst, step, sz)); } @@ -2390,6 +2414,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); } #endif //vz optimized cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); @@ -2473,6 +2498,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); } #endif cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); @@ -2488,6 +2514,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); } #endif //vz optimized cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop); @@ -2594,6 +2621,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); } #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 155ca67..3d3f1aa 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -1086,6 +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); \ cvt_(src, sstep, dst, dstep, size); \ } @@ -1095,6 +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); \ cvt_(src, sstep, dst, dstep, size); \ } #else diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 202e7a9..6a1ff4b 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -574,6 +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); } #endif diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index 1c498cd..37e4a34 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -235,13 +235,14 @@ void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t bl struct CoreTLSData { - CoreTLSData() : device(0), useOpenCL(-1) + CoreTLSData() : device(0), useOpenCL(-1), ippStatus(0) {} 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 cef4db3..cf4b986 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1063,6 +1063,16 @@ TLSStorage::~TLSStorage() TLSData coreTlsData; +void setIppStatus(int status) +{ + coreTlsData.get()->ippStatus = status; +} + +int getIppStatus() +{ + return coreTlsData.get()->ippStatus; +} + } // namespace cv /* End of file. */ diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 8aeec65..07f9845 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -25,6 +25,7 @@ #define GTEST_DONT_DEFINE_TEST 0 #include "opencv2/ts/ts_gtest.h" +#include "opencv2/ts/ts_ext.hpp" #ifndef GTEST_USES_SIMPLE_RE # define GTEST_USES_SIMPLE_RE 0 @@ -553,7 +554,7 @@ CV_EXPORTS void printVersionInfo(bool useStdOut = true); #endif #endif -#if defined(HAVE_OPENCL) && !defined(CV_BUILD_OCL_MODULE) +#if defined(HAVE_OPENCL) namespace cvtest { namespace ocl { void dumpOpenCLDevice(); }} diff --git a/modules/ts/include/opencv2/ts/ts_ext.hpp b/modules/ts/include/opencv2/ts/ts_ext.hpp new file mode 100644 index 0000000..14541fe --- /dev/null +++ b/modules/ts/include/opencv2/ts/ts_ext.hpp @@ -0,0 +1,89 @@ +#ifndef __OPENCV_TS_EXT_HPP__ +#define __OPENCV_TS_EXT_HPP__ + +#define CHECK_IPP_STATUS \ + do \ + { \ + EXPECT_LE(0, getIppStatus()); \ + } while ((void)0, 0) + +#undef TEST +#define TEST(test_case_name, test_name) \ + class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public ::testing::Test {\ + public:\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ + private:\ + virtual void TestBody();\ + virtual void Body();\ + static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ + };\ + \ + ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ + ::test_info_ =\ + ::testing::internal::MakeAndRegisterTestInfo(\ + #test_case_name, #test_name, NULL, NULL, \ + (::testing::internal::GetTestTypeId()), \ + ::testing::Test::SetUpTestCase, \ + ::testing::Test::TearDownTestCase, \ + new ::testing::internal::TestFactoryImpl<\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ + void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() { setIppStatus(0); Body(); CHECK_IPP_STATUS; } \ + void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body() + +#undef TEST_F +#define TEST_F(test_fixture, test_name)\ + class GTEST_TEST_CLASS_NAME_(test_fixture, test_name) : public test_fixture {\ + public:\ + GTEST_TEST_CLASS_NAME_(test_fixture, test_name)() {}\ + private:\ + virtual void TestBody();\ + virtual void Body(); \ + static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ + GTEST_TEST_CLASS_NAME_(test_fixture, test_name));\ + };\ + \ + ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_fixture, test_name)\ + ::test_info_ =\ + ::testing::internal::MakeAndRegisterTestInfo(\ + #test_fixture, #test_name, NULL, NULL, \ + (::testing::internal::GetTypeId()), \ + test_fixture::SetUpTestCase, \ + test_fixture::TearDownTestCase, \ + new ::testing::internal::TestFactoryImpl<\ + GTEST_TEST_CLASS_NAME_(test_fixture, test_name)>);\ + void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::TestBody() { setIppStatus(0); Body(); CHECK_IPP_STATUS; } \ + void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::Body() + +#undef TEST_P +#define TEST_P(test_case_name, test_name) \ + class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ + : public test_case_name { \ + public: \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ + private: \ + virtual void Body(); \ + virtual void TestBody(); \ + static int AddToRegistry() { \ + ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ + GetTestCasePatternHolder(\ + #test_case_name, __FILE__, __LINE__)->AddTestPattern(\ + #test_case_name, \ + #test_name, \ + new ::testing::internal::TestMetaFactory< \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \ + return 0; \ + } \ + static int gtest_registering_dummy_; \ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ + }; \ + int GTEST_TEST_CLASS_NAME_(test_case_name, \ + test_name)::gtest_registering_dummy_ = \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ + void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() { setIppStatus(0); Body(); CHECK_IPP_STATUS; } \ + void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body() + +#endif // __OPENCV_TS_EXT_HPP__ diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index 62e9e14..3326556 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -3,6 +3,7 @@ #include "opencv2/core.hpp" #include "ts_gtest.h" +#include "ts_ext.hpp" #include @@ -512,7 +513,7 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os); #endif #endif -#if defined(HAVE_OPENCL) && !defined(CV_BUILD_OCL_MODULE) +#ifdef HAVE_OPENCL namespace cvtest { namespace ocl { void dumpOpenCLDevice(); }} -- 2.7.4