MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / TestMultiThreadPrediction

Function TestMultiThreadPrediction

test/cpp/inference/api/tester_helper.h:609–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

607}
608
609void TestMultiThreadPrediction(
610 const PaddlePredictor::Config *config,
611 const std::vector<std::vector<PaddleTensor>> &inputs,
612 std::vector<std::vector<PaddleTensor>> *outputs,
613 int num_threads,
614 bool use_analysis = true) {
615 std::vector<std::thread> threads;
616 std::vector<std::unique_ptr<PaddlePredictor>> predictors;
617 predictors.emplace_back(CreateTestPredictor(config, use_analysis));
618 for (int tid = 1; tid < num_threads; tid++) {
619 predictors.emplace_back(predictors.front()->Clone());
620 }
621
622 for (int tid = 0; tid < num_threads; ++tid) {
623 threads.emplace_back([&, tid]() {
624 // Each thread should have local inputs and outputs.
625 // The inputs of each thread are all the same.
626 std::vector<std::vector<PaddleTensor>> outputs_tid;
627 auto &predictor = predictors[tid];
628 if (FLAGS_warmup) {
629 PredictionWarmUp(
630 predictor.get(), inputs, &outputs_tid, num_threads, tid);
631 }
632 PredictionRun(predictor.get(), inputs, &outputs_tid, num_threads, tid);
633 });
634 }
635 for (int i = 0; i < num_threads; ++i) {
636 threads[i].join();
637 }
638}
639
640void TestPrediction(const PaddlePredictor::Config *config,
641 const std::vector<std::vector<PaddleTensor>> &inputs,

Callers 1

TestPredictionFunction · 0.85

Calls 8

CreateTestPredictorFunction · 0.85
PredictionWarmUpFunction · 0.85
PredictionRunFunction · 0.85
emplace_backMethod · 0.45
CloneMethod · 0.45
frontMethod · 0.45
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected