From 05a47d9014d6fa003bcae375203740f461b7705c Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 17 Apr 2014 15:21:30 +0400 Subject: [PATCH] cmd option --- modules/core/include/opencv2/core/base.hpp | 4 ++- modules/core/include/opencv2/core/private.hpp | 2 ++ modules/core/src/system.cpp | 9 ++++-- modules/imgproc/src/color.cpp | 11 +++++-- modules/imgproc/src/imgwarp.cpp | 2 +- modules/imgproc/src/morph.cpp | 1 - modules/ts/include/opencv2/ts.hpp | 7 +++-- modules/ts/include/opencv2/ts/ts_ext.hpp | 19 +++++++----- modules/ts/src/ts.cpp | 29 +++++++++++++++++++ modules/ts/src/ts_perf.cpp | 7 ++++- 10 files changed, 72 insertions(+), 19 deletions(-) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index d081d353ad..1830ded92e 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -560,12 +560,14 @@ namespace cudev template class GpuMat_; } +namespace ipp +{ 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__) +} // ipp } // cv #endif //__OPENCV_CORE_BASE_HPP__ diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index 8857fa378f..a9210a18ba 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -218,6 +218,8 @@ CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int un # endif # define IPP_VERSION_X100 (IPP_VERSION_MAJOR * 100 + IPP_VERSION_MINOR) +#define setIppErrorStatus() cv::ipp::setIppStatus(-1, CV_Func, __FILE__, __LINE__) + static inline IppiSize ippiSize(int width, int height) { IppiSize size = { width, height }; diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 6081a60841..6296fe5180 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1063,9 +1063,12 @@ TLSStorage::~TLSStorage() TLSData coreTlsData; +namespace ipp +{ + static int ippStatus = 0; // 0 - all is ok, -1 - IPP functions failed -static const char * funcname, * filename; -static int linen; +static const char * funcname = NULL, * filename = NULL; +static int linen = 0; void setIppStatus(int status, const char * const _funcname, const char * const _filename, int _line) { @@ -1085,6 +1088,8 @@ String getIppErrorLocation() return format("%s:%d %s", filename ? filename : "", linen, funcname ? funcname : ""); } +} // namespace ipp + } // namespace cv /* End of file. */ diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index ef198f6159..9c04d1cd63 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -374,7 +374,7 @@ static ippiGeneralFunc ippiHLS2RGBTab[] = 0, (ippiGeneralFunc)ippiHLSToRGB_32f_C3R, 0, 0 }; -#if !defined(HAVE_IPP_ICV_ONLY) +#if !defined(HAVE_IPP_ICV_ONLY) && 0 static ippiGeneralFunc ippiRGBToLUVTab[] = { (ippiGeneralFunc)ippiRGBToLUV_8u_C3R, 0, (ippiGeneralFunc)ippiRGBToLUV_16u_C3R, 0, @@ -3920,6 +3920,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) dst = _dst.getMat(); #if defined HAVE_IPP && !defined(HAVE_IPP_ICV_ONLY) +#if 0 if (code == CV_LBGR2Lab && scn == 3 && depth == CV_8U) { if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor((ippiGeneralFunc)ippiBGRToLab_8u_C3R))) @@ -3933,7 +3934,9 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) return; setIppErrorStatus(); } - else if (code == CV_LRGB2Lab && scn == 3 && depth == CV_8U) + else +#endif + if (code == CV_LRGB2Lab && scn == 3 && depth == CV_8U) { if (CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth], (ippiGeneralFunc)ippiBGRToLab_8u_C3R, 2, 1, 0, depth))) @@ -3947,6 +3950,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) return; setIppErrorStatus(); } +#if 0 else if (code == CV_LRGB2Luv && scn == 3) { if (CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiRGBToLUVTab[depth]))) @@ -3974,6 +3978,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) return; setIppErrorStatus(); } +#endif #endif if( code == CV_BGR2Lab || code == CV_RGB2Lab || @@ -4036,7 +4041,6 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) return; setIppErrorStatus(); } -#endif if( code == CV_Luv2LRGB && dcn == 3 ) { if( CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiLUVToRGBTab[depth])) ) @@ -4060,6 +4064,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)) ) return; } +#endif #endif if( code == CV_Lab2BGR || code == CV_Lab2RGB || diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index eaea144187..16ad5552d2 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -1876,7 +1876,7 @@ static int computeResizeAreaTab( int ssize, int dsize, int cn, double scale, Dec return k; } -#define CHECK_IPP_STATUS(STATUS) if (STATUS < 0) { *ok = false; return; } +#define CHECK_IPP_STATUS(STATUS) if (STATUS != 0) { *ok = false; return; } #define SET_IPP_RESIZE_LINEAR_FUNC_PTR(TYPE, CN) \ func = (ippiResizeFunc)ippiResizeLinear_##TYPE##_##CN##R; \ diff --git a/modules/imgproc/src/morph.cpp b/modules/imgproc/src/morph.cpp index 56b24b6068..e76f8ab4ed 100644 --- a/modules/imgproc/src/morph.cpp +++ b/modules/imgproc/src/morph.cpp @@ -1337,7 +1337,6 @@ static bool IPPMorphOp(int op, InputArray _src, OutputArray _dst, if (IPPMorphReplicate( op, src, dst, kernel, ksize, anchor, rectKernel )) return true; - setIppErrorStatus(); return false; } #endif diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 07f9845b76..c58d31969b 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -554,15 +554,17 @@ CV_EXPORTS void printVersionInfo(bool useStdOut = true); #endif #endif -#if defined(HAVE_OPENCL) +#ifdef HAVE_OPENCL namespace cvtest { namespace ocl { void dumpOpenCLDevice(); -}} +} } #define TEST_DUMP_OCL_INFO cvtest::ocl::dumpOpenCLDevice(); #else #define TEST_DUMP_OCL_INFO #endif +void parseCustomOptions(int argc, char **argv); + #define CV_TEST_MAIN(resourcesubdir, ...) \ int main(int argc, char **argv) \ { \ @@ -571,6 +573,7 @@ int main(int argc, char **argv) \ cvtest::printVersionInfo(); \ __CV_TEST_EXEC_ARGS(__VA_ARGS__) \ TEST_DUMP_OCL_INFO \ + parseCustomOptions(argc, argv); \ return RUN_ALL_TESTS(); \ } diff --git a/modules/ts/include/opencv2/ts/ts_ext.hpp b/modules/ts/include/opencv2/ts/ts_ext.hpp index 97349a9a2e..08039baded 100644 --- a/modules/ts/include/opencv2/ts/ts_ext.hpp +++ b/modules/ts/include/opencv2/ts/ts_ext.hpp @@ -1,11 +1,14 @@ +// 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, Intel, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. + #ifndef __OPENCV_TS_EXT_HPP__ #define __OPENCV_TS_EXT_HPP__ -#define CHECK_IPP_STATUS \ - do \ - { \ - EXPECT_LE(0, getIppStatus()) << getIppErrorLocation().c_str(); \ - } while ((void)0, 0) +void checkIppStatus(); #undef TEST #define TEST(test_case_name, test_name) \ @@ -29,7 +32,7 @@ ::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)::TestBody() { cv::ipp::setIppStatus(0); Body(); checkIppStatus(); } \ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body() #undef TEST_F @@ -54,7 +57,7 @@ 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)::TestBody() { cv::ipp::setIppStatus(0); Body(); checkIppStatus(); } \ void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::Body() #undef TEST_P @@ -83,7 +86,7 @@ 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)::TestBody() { cv::ipp::setIppStatus(0); Body(); checkIppStatus(); } \ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body() #endif // __OPENCV_TS_EXT_HPP__ diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index 45aaadf13c..29fd056fea 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -658,4 +658,33 @@ void smoothBorder(Mat& img, const Scalar& color, int delta) } //namespace cvtest +bool test_ipp_check = false; + +void checkIppStatus() +{ + if (test_ipp_check) + { + int status = cv::ipp::getIppStatus(); + EXPECT_LE(0, status) << cv::ipp::getIppErrorLocation().c_str(); + } +} + +void parseCustomOptions(int argc, char **argv) +{ + const char * const command_line_keys = + "{ ipp test_ipp_check |false |check whether IPP works without failures }" + "{ h help |false |print help info }"; + + cv::CommandLineParser parser(argc, argv, command_line_keys); + if (parser.get("help")) + { + std::cout << "\nAvailable options besides google test option: \n"; + parser.printMessage(); + } + + test_ipp_check = parser.get("test_ipp_check"); + if (!test_ipp_check) + test_ipp_check = getenv("OPENCV_IPP_CHECK") != NULL; +} + /* End of file. */ diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 25981a7219..c5d4be5c2b 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -31,6 +31,7 @@ static double param_time_limit; static int param_threads; static bool param_write_sanity; static bool param_verify_sanity; +extern bool test_ipp_check; #ifdef HAVE_CUDA static int param_cuda_device; #endif @@ -670,6 +671,9 @@ void TestBase::Init(const std::vector & availableImpls, "{ perf_time_limit |3.0 |default time limit for a single test (in seconds)}" #endif "{ perf_max_deviation |1.0 |}" +#ifdef HAVE_IPP + "{ perf_ipp_check |false |check whether IPP works without failures}" +#endif "{ help h |false |print help info}" #ifdef HAVE_CUDA "{ perf_cuda_device |0 |run CUDA test suite onto specific CUDA capable device}" @@ -713,7 +717,8 @@ void TestBase::Init(const std::vector & availableImpls, param_force_samples = args.get("perf_force_samples"); param_write_sanity = args.has("perf_write_sanity"); param_verify_sanity = args.has("perf_verify_sanity"); - param_threads = args.get("perf_threads"); + test_ipp_check = !args.has("perf_ipp_check") ? getenv("OPENCV_IPP_CHECK") != NULL : true; + param_threads = args.get("perf_threads"); #ifdef ANDROID param_affinity_mask = args.get("perf_affinity_mask"); log_power_checkpoints = args.has("perf_log_power_checkpoints");