From 2411ed42862481ac07d3191e9b537698b35cd857 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Mon, 14 Jan 2019 15:00:44 +0800 Subject: [PATCH] fix multi-threads in ZeroCopyProfile test=develop --- .../fluid/inference/tests/api/analyzer_rnn1_tester.cc | 11 ++++------- .../inference/tests/api/analyzer_seq_pool1_tester.cc | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/paddle/fluid/inference/tests/api/analyzer_rnn1_tester.cc b/paddle/fluid/inference/tests/api/analyzer_rnn1_tester.cc index 315b49533..22e6366fb 100644 --- a/paddle/fluid/inference/tests/api/analyzer_rnn1_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_rnn1_tester.cc @@ -370,15 +370,12 @@ TEST(Analyzer_rnn1, ZeroCopyMultiThread) { auto base_predictor = CreatePaddlePredictor(config); double total_time_of_threads{0}; std::vector threads; - std::vector> predictors; - for (int tid = 0; tid < FLAGS_num_threads; tid++) { - predictors.emplace_back(CreatePaddlePredictor(config)); - } for (int tid = 0; tid < FLAGS_num_threads; tid++) { - threads.emplace_back([config, &total_time_of_threads, &predictors, tid] { - // auto predictor = base_predictor->Clone(); - auto &predictor = predictors[tid]; + threads.emplace_back([&, tid] { + // To ensure the thread binding correctly, + // please clone inside the threadpool. + auto predictor = base_predictor->Clone(); NEW_TENSOR(data_lod_attention); NEW_TENSOR(cell_init); NEW_TENSOR(data); diff --git a/paddle/fluid/inference/tests/api/analyzer_seq_pool1_tester.cc b/paddle/fluid/inference/tests/api/analyzer_seq_pool1_tester.cc index fb4c5c0a0..c13709087 100644 --- a/paddle/fluid/inference/tests/api/analyzer_seq_pool1_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_seq_pool1_tester.cc @@ -263,15 +263,12 @@ TEST(Analyzer_seq_pool1, zerocopy_profile_threads) { auto base_predictor = CreatePaddlePredictor(config); double total_time_of_threads{0}; std::vector threads; - std::vector> predictors; - for (int tid = 0; tid < FLAGS_num_threads; tid++) { - predictors.emplace_back(base_predictor->Clone()); - // predictors.emplace_back(CreatePaddlePredictor(config)); - } for (int tid = 0; tid < FLAGS_num_threads; tid++) { - threads.emplace_back([config, &total_time_of_threads, &predictors, tid] { - auto &predictor = predictors[tid]; + threads.emplace_back([&, tid] { + // To ensure the thread binding correctly, + // please clone inside the threadpool. + auto predictor = base_predictor->Clone(); std::vector> inputs; PrepareZeroCopyInputs(predictor, &inputs); auto output_tensor = predictor->GetOutputTensor(out_var_name); -- GitLab