diff --git a/paddle/fluid/inference/tests/api/analyzer_rnn1_tester.cc b/paddle/fluid/inference/tests/api/analyzer_rnn1_tester.cc index 315b49533260e57f7124d382555c902b31be4e1e..22e6366fb5cba6c7a0cde9c0c5f50f56c2e23b05 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 fb4c5c0a00d0b693ac70691438e65ed9e49bd1a1..c137090879e67d5314b94709586c5292dc208745 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);