Skip to content

Commit 2b3c140

Browse files
authored
Merge pull request opencv#10436 from alalek:test_threads
2 parents ec32022 + 9b131b5 commit 2b3c140

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

modules/dnn/perf/opencl/perf_convolution.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ OCL_PERF_TEST_P( ConvolutionPerfTest, perf, Combine(
7777
std::vector<Mat*> inpBlobs(1, &inpBlob);
7878
std::vector<Mat> outBlobs, internalBlobs;
7979

80-
cv::setNumThreads(cv::getNumberOfCPUs());
81-
8280
Ptr<Layer> layer = cv::dnn::LayerFactory::createLayerInstance("Convolution", lp);
8381
std::vector<MatShape> inputShapes(1, shape(inpBlob)), outShapes, internals;
8482
layer->getMemoryShapes(inputShapes, 0, outShapes, internals);
@@ -99,7 +97,7 @@ OCL_PERF_TEST_P( ConvolutionPerfTest, perf, Combine(
9997
Mat inpBlob2D = inpBlob.reshape(1, outCn);
10098
Mat wgtBlob2D = wgtBlob.reshape(1, outCn*(inpCn/groups));
10199
Mat outBlob2D = outBlobs[0].reshape(1, outBlobs[0].size[0]);
102-
declare.in(inpBlob2D, wgtBlob2D, WARMUP_RNG).out(outBlob2D).tbb_threads(cv::getNumThreads());
100+
declare.in(inpBlob2D, wgtBlob2D, WARMUP_RNG).out(outBlob2D);
103101

104102
// warmup
105103
layer->forward(inpBlobs, outBlobs, internalBlobs);

modules/dnn/perf/perf_convolution.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ PERF_TEST_P( ConvolutionPerfTest, perf, Combine(
6060
std::vector<Mat*> inpBlobs(1, &inpBlob);
6161
std::vector<Mat> outBlobs, internalBlobs;
6262

63-
cv::setNumThreads(cv::getNumberOfCPUs());
64-
6563
Ptr<Layer> layer = cv::dnn::LayerFactory::createLayerInstance("Convolution", lp);
6664
std::vector<MatShape> inputShapes(1, shape(inpBlob)), outShapes, internals;
6765
layer->getMemoryShapes(inputShapes, 0, outShapes, internals);
@@ -81,7 +79,7 @@ PERF_TEST_P( ConvolutionPerfTest, perf, Combine(
8179
Mat inpBlob2D = inpBlob.reshape(1, outCn);
8280
Mat wgtBlob2D = wgtBlob.reshape(1, outCn*(inpCn/groups));
8381
Mat outBlob2D = outBlobs[0].reshape(1, outBlobs[0].size[0]);
84-
declare.in(inpBlob2D, wgtBlob2D, WARMUP_RNG).out(outBlob2D).tbb_threads(cv::getNumThreads());
82+
declare.in(inpBlob2D, wgtBlob2D, WARMUP_RNG).out(outBlob2D);
8583

8684
layer->forward(inpBlobs, outBlobs, internalBlobs); /// warmup
8785

modules/dnn/test/test_layers.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ void testLayerUsingCaffeModels(String basename, int targetId = DNN_TARGET_CPU,
107107
String inpfile = (useCommonInputBlob) ? _tf("blob.npy") : _tf(basename + ".input.npy");
108108
String outfile = _tf(basename + ".npy");
109109

110-
cv::setNumThreads(cv::getNumberOfCPUs());
111-
112110
Net net = readNetFromCaffe(prototxt, (useCaffeModel) ? caffemodel : String());
113111
ASSERT_FALSE(net.empty());
114112

@@ -537,8 +535,6 @@ void testLayerUsingDarknetModels(String basename, bool useDarknetModel = false,
537535
String inpfile = (useCommonInputBlob) ? _tf("blob.npy") : _tf(basename + ".input.npy");
538536
String outfile = _tf(basename + ".npy");
539537

540-
cv::setNumThreads(cv::getNumberOfCPUs());
541-
542538
Net net = readNetFromDarknet(cfg, (useDarknetModel) ? weights : String());
543539
ASSERT_FALSE(net.empty());
544540

modules/ts/include/opencv2/ts/ts_ext.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
namespace cvtest {
1212
void checkIppStatus();
1313
extern bool skipUnstableTests;
14+
extern int testThreads;
1415
}
1516

1617
#define CV__TEST_INIT \
1718
cv::ipp::setIppStatus(0); \
18-
cv::theRNG().state = cvtest::param_seed;
19+
cv::theRNG().state = cvtest::param_seed; \
20+
cv::setNumThreads(cvtest::testThreads);
1921
#define CV__TEST_CLEANUP ::cvtest::checkIppStatus();
2022
#define CV__TEST_BODY_IMPL(name) \
2123
{ \

modules/ts/src/ts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,14 @@ void checkIppStatus()
695695
}
696696

697697
bool skipUnstableTests = false;
698+
int testThreads = 0;
698699

699700
void parseCustomOptions(int argc, char **argv)
700701
{
701702
const char * const command_line_keys =
702703
"{ ipp test_ipp_check |false |check whether IPP works without failures }"
703704
"{ test_seed |809564 |seed for random numbers generator }"
705+
"{ test_threads |-1 |the number of worker threads, if parallel execution is enabled}"
704706
"{ skip_unstable |false |skip unstable tests }"
705707
"{ h help |false |print help info }";
706708

@@ -721,6 +723,8 @@ void parseCustomOptions(int argc, char **argv)
721723

722724
param_seed = parser.get<unsigned int>("test_seed");
723725

726+
testThreads = parser.get<int>("test_threads");
727+
724728
skipUnstableTests = parser.get<bool>("skip_unstable");
725729
}
726730

modules/ts/src/ts_perf.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static double param_max_deviation;
3939
static unsigned int param_min_samples;
4040
static unsigned int param_force_samples;
4141
static double param_time_limit;
42-
static int param_threads;
4342
static bool param_write_sanity;
4443
static bool param_verify_sanity;
4544
#ifdef CV_COLLECT_IMPL_DATA
@@ -1042,7 +1041,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
10421041
#ifdef HAVE_IPP
10431042
test_ipp_check = !args.get<bool>("perf_ipp_check") ? getenv("OPENCV_IPP_CHECK") != NULL : true;
10441043
#endif
1045-
param_threads = args.get<int>("perf_threads");
1044+
testThreads = args.get<int>("perf_threads");
10461045
#ifdef CV_COLLECT_IMPL_DATA
10471046
param_collect_impl = args.get<bool>("perf_collect_impl");
10481047
#endif
@@ -1160,7 +1159,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
11601159
void TestBase::RecordRunParameters()
11611160
{
11621161
::testing::Test::RecordProperty("cv_implementation", param_impl);
1163-
::testing::Test::RecordProperty("cv_num_threads", param_threads);
1162+
::testing::Test::RecordProperty("cv_num_threads", testThreads);
11641163

11651164
#ifdef HAVE_CUDA
11661165
if (param_impl == "cuda")
@@ -1851,8 +1850,8 @@ void TestBase::SetUp()
18511850
{
18521851
cv::theRNG().state = param_seed; // this rng should generate same numbers for each run
18531852

1854-
if (param_threads >= 0)
1855-
cv::setNumThreads(param_threads);
1853+
if (testThreads >= 0)
1854+
cv::setNumThreads(testThreads);
18561855
else
18571856
cv::setNumThreads(-1);
18581857

0 commit comments

Comments
 (0)