mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 20:50:25 +08:00
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).
This commit is contained in:
parent
1d5e407211
commit
59d89c7a7a
@ -925,7 +925,7 @@ if (WITH_TBB)
|
|||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib)
|
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib)
|
||||||
elseif (ANDROID)
|
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)
|
add_definitions(-DTBB_USE_GCC_BUILTINS)
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
|
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
#include "ts_gtest.h"
|
#include "ts_gtest.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_TBB
|
||||||
|
#include "tbb/task_scheduler_init.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ANDROID) && defined(USE_ANDROID_LOGGING)
|
#if defined(ANDROID) && defined(USE_ANDROID_LOGGING)
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
@ -283,6 +287,7 @@ private:
|
|||||||
|
|
||||||
_declareHelper& iterations(int n);
|
_declareHelper& iterations(int n);
|
||||||
_declareHelper& time(double timeLimitSecs);
|
_declareHelper& time(double timeLimitSecs);
|
||||||
|
_declareHelper& tbb_threads(int n);
|
||||||
private:
|
private:
|
||||||
TestBase* test;
|
TestBase* test;
|
||||||
_declareHelper(TestBase* t);
|
_declareHelper(TestBase* t);
|
||||||
@ -292,6 +297,10 @@ private:
|
|||||||
};
|
};
|
||||||
friend class _declareHelper;
|
friend class _declareHelper;
|
||||||
|
|
||||||
|
#ifdef HAVE_TBB
|
||||||
|
cv::Ptr<tbb::task_scheduler_init> p_tbb_initializer;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_declareHelper declare;
|
_declareHelper declare;
|
||||||
};
|
};
|
||||||
|
@ -385,6 +385,7 @@ const char *command_line_keys =
|
|||||||
"{ |perf_max_outliers |8 |percent of allowed outliers}"
|
"{ |perf_max_outliers |8 |percent of allowed outliers}"
|
||||||
"{ |perf_min_samples |10 |minimal required numer of samples}"
|
"{ |perf_min_samples |10 |minimal required numer of samples}"
|
||||||
"{ |perf_seed |809564 |seed for random numbers generator}"
|
"{ |perf_seed |809564 |seed for random numbers generator}"
|
||||||
|
"{ |perf_tbb_nthreads |-1 |if TBB is enabled, the number of TBB threads}"
|
||||||
#if ANDROID
|
#if ANDROID
|
||||||
"{ |perf_time_limit |6.0 |default time limit for a single test (in seconds)}"
|
"{ |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}"
|
"{ |perf_affinity_mask |0 |set affinity mask for the main thread}"
|
||||||
@ -400,6 +401,7 @@ double param_max_deviation;
|
|||||||
unsigned int param_min_samples;
|
unsigned int param_min_samples;
|
||||||
uint64 param_seed;
|
uint64 param_seed;
|
||||||
double param_time_limit;
|
double param_time_limit;
|
||||||
|
int param_tbb_nthreads;
|
||||||
#if ANDROID
|
#if ANDROID
|
||||||
int param_affinity_mask;
|
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<double>("perf_max_deviation"));
|
param_max_deviation = std::max(0., args.get<double>("perf_max_deviation"));
|
||||||
param_seed = args.get<uint64>("perf_seed");
|
param_seed = args.get<uint64>("perf_seed");
|
||||||
param_time_limit = std::max(0., args.get<double>("perf_time_limit"));
|
param_time_limit = std::max(0., args.get<double>("perf_time_limit"));
|
||||||
|
|
||||||
|
param_tbb_nthreads = args.get<int>("perf_tbb_nthreads");
|
||||||
#if ANDROID
|
#if ANDROID
|
||||||
param_affinity_mask = args.get<int>("perf_affinity_mask");
|
param_affinity_mask = args.get<int>("perf_affinity_mask");
|
||||||
#endif
|
#endif
|
||||||
@ -769,6 +773,12 @@ void TestBase::reportMetrics(bool toJUnitXML)
|
|||||||
|
|
||||||
void TestBase::SetUp()
|
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 ANDROID
|
||||||
if (param_affinity_mask)
|
if (param_affinity_mask)
|
||||||
setCurrentThreadAffinityMask(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);
|
if (type_param) printf("[ TYPE ] \t%s\n", type_param), fflush(stdout);
|
||||||
reportMetrics(true);
|
reportMetrics(true);
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_TBB
|
||||||
|
p_tbb_initializer.release();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TestBase::getDataPath(const std::string& relativePath)
|
std::string TestBase::getDataPath(const std::string& relativePath)
|
||||||
@ -882,6 +895,17 @@ TestBase::_declareHelper& TestBase::_declareHelper::time(double timeLimitSecs)
|
|||||||
return *this;
|
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)
|
TestBase::_declareHelper& TestBase::_declareHelper::in(cv::InputOutputArray a1, int wtype)
|
||||||
{
|
{
|
||||||
if (!test->times.empty()) return *this;
|
if (!test->times.empty()) return *this;
|
||||||
|
Loading…
Reference in New Issue
Block a user