From 59d89c7a7a6cc237af8a09f5555c900e95ba099e Mon Sep 17 00:00:00 2001 From: Leonid Beynenson Date: Mon, 31 Oct 2011 16:22:05 +0000 Subject: [PATCH] Added possibility to configure TBB behavior in Perf tests --- now we can set the number of TBB threads in the perf tests either as console parameter perf_tbb_nthreads or in a test itself using the method declare.tbb_threads(n). --- CMakeLists.txt | 2 +- modules/ts/include/opencv2/ts/ts_perf.hpp | 9 +++++++++ modules/ts/src/ts_perf.cpp | 24 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff8f20c646..e77f474d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -925,7 +925,7 @@ if (WITH_TBB) if (APPLE) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib) elseif (ANDROID) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbbmalloc tbb) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) add_definitions(-DTBB_USE_GCC_BUILTINS) elseif (UNIX) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb) diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index edbf352577..3f64fdcc41 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -4,6 +4,10 @@ #include "opencv2/core/core.hpp" #include "ts_gtest.h" +#ifdef HAVE_TBB +#include "tbb/task_scheduler_init.h" +#endif + #if defined(ANDROID) && defined(USE_ANDROID_LOGGING) #include @@ -283,6 +287,7 @@ private: _declareHelper& iterations(int n); _declareHelper& time(double timeLimitSecs); + _declareHelper& tbb_threads(int n); private: TestBase* test; _declareHelper(TestBase* t); @@ -292,6 +297,10 @@ private: }; friend class _declareHelper; +#ifdef HAVE_TBB + cv::Ptr p_tbb_initializer; +#endif + public: _declareHelper declare; }; diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 30be6303fd..5c1812b151 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -385,6 +385,7 @@ const char *command_line_keys = "{ |perf_max_outliers |8 |percent of allowed outliers}" "{ |perf_min_samples |10 |minimal required numer of samples}" "{ |perf_seed |809564 |seed for random numbers generator}" + "{ |perf_tbb_nthreads |-1 |if TBB is enabled, the number of TBB threads}" #if ANDROID "{ |perf_time_limit |6.0 |default time limit for a single test (in seconds)}" "{ |perf_affinity_mask |0 |set affinity mask for the main thread}" @@ -400,6 +401,7 @@ double param_max_deviation; unsigned int param_min_samples; uint64 param_seed; double param_time_limit; +int param_tbb_nthreads; #if ANDROID int param_affinity_mask; @@ -427,6 +429,8 @@ void TestBase::Init(int argc, const char* const argv[]) param_max_deviation = std::max(0., args.get("perf_max_deviation")); param_seed = args.get("perf_seed"); param_time_limit = std::max(0., args.get("perf_time_limit")); + + param_tbb_nthreads = args.get("perf_tbb_nthreads"); #if ANDROID param_affinity_mask = args.get("perf_affinity_mask"); #endif @@ -769,6 +773,12 @@ void TestBase::reportMetrics(bool toJUnitXML) void TestBase::SetUp() { +#ifdef HAVE_TBB + if (param_tbb_nthreads > 0) { + p_tbb_initializer.release(); + p_tbb_initializer=new tbb::task_scheduler_init(param_tbb_nthreads); + } +#endif #if ANDROID if (param_affinity_mask) setCurrentThreadAffinityMask(param_affinity_mask); @@ -796,6 +806,9 @@ void TestBase::TearDown() if (type_param) printf("[ TYPE ] \t%s\n", type_param), fflush(stdout); reportMetrics(true); } +#ifdef HAVE_TBB + p_tbb_initializer.release(); +#endif } std::string TestBase::getDataPath(const std::string& relativePath) @@ -882,6 +895,17 @@ TestBase::_declareHelper& TestBase::_declareHelper::time(double timeLimitSecs) return *this; } +TestBase::_declareHelper& TestBase::_declareHelper::tbb_threads(int n) +{ +#ifdef HAVE_TBB + if (n > 0) { + test->p_tbb_initializer.release(); + test->p_tbb_initializer=new tbb::task_scheduler_init(n); + } +#endif + return *this; +} + TestBase::_declareHelper& TestBase::_declareHelper::in(cv::InputOutputArray a1, int wtype) { if (!test->times.empty()) return *this;