From 54636a19822cb51dfc163cdb991fced41d36d0f0 Mon Sep 17 00:00:00 2001 From: Leo Zhao <48052473+LeoZhao-Intel@users.noreply.github.com> Date: Tue, 7 May 2019 09:24:27 +0800 Subject: [PATCH] call SetNumThreads everytime to avoid missing omp thread setting (#17224) * call SetNumThreads everytime to avoid missing omp thread setting resolve #17153 test=develop * add paddle_num_threads into config for test_analyzer_pyramid_dnn resolve #17153 test=develop --- paddle/fluid/inference/api/analysis_predictor.cc | 5 ++--- .../fluid/inference/tests/api/analyzer_pyramid_dnn_tester.cc | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index fcab1ab18..a84c909b3 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -192,9 +192,7 @@ void AnalysisPredictor::SetMkldnnThreadID(int tid) { bool AnalysisPredictor::Run(const std::vector &inputs, std::vector *output_data, int batch_size) { - if (UNLIKELY(config_.cpu_math_library_num_threads() > 1)) { - paddle::platform::SetNumThreads(config_.cpu_math_library_num_threads()); - } + paddle::platform::SetNumThreads(config_.cpu_math_library_num_threads()); VLOG(3) << "Predictor::predict"; inference::Timer timer; timer.tic(); @@ -569,6 +567,7 @@ std::unique_ptr AnalysisPredictor::GetOutputTensor( } bool AnalysisPredictor::ZeroCopyRun() { + paddle::platform::SetNumThreads(config_.cpu_math_library_num_threads()); executor_->Run(); // Fix TensorArray reuse not cleaned bug. tensor_array_batch_cleaner_.CollectTensorArrays(sub_scope_); diff --git a/paddle/fluid/inference/tests/api/analyzer_pyramid_dnn_tester.cc b/paddle/fluid/inference/tests/api/analyzer_pyramid_dnn_tester.cc index 9443b0806..cc31ab958 100644 --- a/paddle/fluid/inference/tests/api/analyzer_pyramid_dnn_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_pyramid_dnn_tester.cc @@ -107,6 +107,7 @@ void SetConfig(AnalysisConfig *cfg) { cfg->DisableGpu(); cfg->SwitchSpecifyInputNames(); cfg->SwitchIrOptim(); + cfg->SetCpuMathLibraryNumThreads(FLAGS_paddle_num_threads); if (FLAGS_zero_copy) { cfg->SwitchUseFeedFetchOps(false); } -- GitLab