| 607 | } |
| 608 | |
| 609 | void 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 | |
| 640 | void TestPrediction(const PaddlePredictor::Config *config, |
| 641 | const std::vector<std::vector<PaddleTensor>> &inputs, |
no test coverage detected