Skip to content

Commit e66b4c6

Browse files
committed
adjust tester_helper to make multi-instance multi-thread work
test=develop
1 parent a5c4b46 commit e66b4c6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

paddle/fluid/inference/tests/api/tester_helper.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,17 @@ void TestMultiThreadPrediction(
207207
int batch_size = FLAGS_batch_size;
208208
int num_times = FLAGS_repeat;
209209
std::vector<std::thread> threads;
210-
std::vector<std::unique_ptr<PaddlePredictor>> predictors;
211-
predictors.emplace_back(CreateTestPredictor(config, use_analysis));
212-
for (int tid = 1; tid < num_threads; ++tid) {
213-
predictors.emplace_back(predictors.front()->Clone());
214-
}
210+
auto main_predictor = CreateTestPredictor(config, use_analysis);
215211

216212
size_t total_time{0};
217213
for (int tid = 0; tid < num_threads; ++tid) {
218214
threads.emplace_back([&, tid]() {
219215
// Each thread should have local inputs and outputs.
220216
// The inputs of each thread are all the same.
221217
std::vector<PaddleTensor> outputs_tid;
222-
auto &predictor = predictors[tid];
218+
// To ensure the thread binding correctly,
219+
// please clone inside the threadpool.
220+
auto predictor = main_predictor->Clone();
223221
#ifdef PADDLE_WITH_MKLDNN
224222
if (use_analysis) {
225223
static_cast<AnalysisPredictor *>(predictor.get())

0 commit comments

Comments
 (0)