Skip to content

Commit 9e6b1c5

Browse files
authored
Refine tester of TensorRT engine (#14390)
* Refine the tester for MixedRTPredictor. test=develop * Enable the profiler in TensorRT engine. * Support the use of combined inference model in TensorRT unittest, and print the shape of feed targets.
1 parent d3e63e6 commit 9e6b1c5

18 files changed

+315
-173
lines changed

paddle/fluid/inference/api/analysis_predictor_tester.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "paddle/fluid/inference/api/analysis_predictor.h"
1616
#include <glog/logging.h>
1717
#include <gtest/gtest.h>
18-
#include <thread>
18+
#include <thread> // NOLINT
1919
#include "paddle/fluid/inference/api/helper.h"
2020
#include "paddle/fluid/inference/api/paddle_inference_api.h"
2121

paddle/fluid/inference/api/demo_ci/simple_on_word2vec.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License. */
2323
#include <memory>
2424
#include <thread> //NOLINT
2525

26-
#include "utils.h"
26+
#include "utils.h" // NOLINT
2727

2828
DEFINE_string(dirname, "", "Directory of the inference model.");
2929
DEFINE_bool(use_gpu, false, "Whether use gpu.");

paddle/fluid/inference/api/demo_ci/trt_mobilenet_demo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at
66
7-
http://www.apache.org/licenses/LICENSE-2.0
7+
http://www.apache.org/licenses/LICENSE-2.0
88
99
Unless required by applicable law or agreed to in writing, software
1010
distributed under the License is distributed on an "AS IS" BASIS,

paddle/fluid/inference/api/paddle_analysis_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct AnalysisConfig : public NativeConfig {
4949

5050
void EnableTensorRtEngine(int workspace_size = 1 << 20,
5151
int max_batch_size = 1);
52+
bool use_tensorrt() const { return use_tensorrt_; }
53+
5254
// NOTE this is just for internal development, please not use it.
5355
// NOT stable yet.
5456
void EnableMKLDNN();

paddle/fluid/inference/api/paddle_pass_builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class CpuPassStrategy : public PassStrategy {
9191

9292
virtual ~CpuPassStrategy() = default;
9393

94-
virtual void EnableMKLDNN() override {
94+
void EnableMKLDNN() override {
9595
// TODO(Superjomn) Consider the way to mix CPU with GPU.
9696
#ifdef PADDLE_WITH_MKLDNN
9797
passes_.insert(passes_.begin(), "mkldnn_placement_pass");
@@ -123,7 +123,7 @@ class GpuPassStrategy : public PassStrategy {
123123
GpuPassStrategy(const GpuPassStrategy &other)
124124
: PassStrategy(other.AllPasses()) {}
125125

126-
virtual void EnableMKLDNN() override;
126+
void EnableMKLDNN() override;
127127

128128
virtual ~GpuPassStrategy() = default;
129129
};

paddle/fluid/inference/tests/api/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ if(WITH_GPU AND TENSORRT_FOUND)
108108
if (NOT EXISTS ${TRT_MODEL_INSTALL_DIR})
109109
inference_download_and_uncompress(${TRT_MODEL_INSTALL_DIR} ${INFERENCE_URL}/tensorrt_test "trt_test_models.tar.gz")
110110
endif()
111-
112111
inference_analysis_test(test_trt_models SRCS trt_models_tester.cc
113112
EXTRA_DEPS ${INFERENCE_EXTRA_DEPS} analysis ${analysis_deps} ir_pass_manager analysis_predictor
114-
ARGS --dirname=${TRT_MODEL_INSTALL_DIR}/trt_test_models SERIAL)
113+
ARGS --infer_model=${TRT_MODEL_INSTALL_DIR}/trt_test_models SERIAL)
115114
endif()

paddle/fluid/inference/tests/api/analyzer_dam_tester.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ TEST(Analyzer_dam, profile) {
178178
std::vector<PaddleTensor> outputs;
179179
std::vector<std::vector<PaddleTensor>> input_slots_all;
180180
SetInput(&input_slots_all);
181-
TestPrediction(cfg, input_slots_all, &outputs, FLAGS_num_threads);
181+
TestPrediction(reinterpret_cast<const PaddlePredictor::Config *>(&cfg),
182+
input_slots_all, &outputs, FLAGS_num_threads);
182183

183184
if (FLAGS_num_threads == 1 && !FLAGS_test_all_data) {
184185
PADDLE_ENFORCE_GT(outputs.size(), 0);
@@ -216,7 +217,9 @@ TEST(Analyzer_dam, compare) {
216217
SetInput(&input_slots_all);
217218

218219
if (FLAGS_use_analysis) {
219-
CompareNativeAndAnalysis(cfg, input_slots_all);
220+
CompareNativeAndAnalysis(
221+
reinterpret_cast<const PaddlePredictor::Config *>(&cfg),
222+
input_slots_all);
220223
}
221224
}
222225

paddle/fluid/inference/tests/api/analyzer_lac_tester.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ TEST(Analyzer_LAC, profile) {
133133

134134
std::vector<std::vector<PaddleTensor>> input_slots_all;
135135
SetInput(&input_slots_all);
136-
TestPrediction(cfg, input_slots_all, &outputs, FLAGS_num_threads);
136+
TestPrediction(reinterpret_cast<const PaddlePredictor::Config *>(&cfg),
137+
input_slots_all, &outputs, FLAGS_num_threads);
137138

138139
if (FLAGS_num_threads == 1 && !FLAGS_test_all_data) {
139140
// the first inference result
@@ -175,7 +176,8 @@ TEST(Analyzer_LAC, compare) {
175176

176177
std::vector<std::vector<PaddleTensor>> input_slots_all;
177178
SetInput(&input_slots_all);
178-
CompareNativeAndAnalysis(cfg, input_slots_all);
179+
CompareNativeAndAnalysis(
180+
reinterpret_cast<const PaddlePredictor::Config *>(&cfg), input_slots_all);
179181
}
180182

181183
} // namespace analysis

paddle/fluid/inference/tests/api/analyzer_ner_tester.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ TEST(Analyzer_Chinese_ner, profile) {
121121

122122
std::vector<std::vector<PaddleTensor>> input_slots_all;
123123
SetInput(&input_slots_all);
124-
TestPrediction(cfg, input_slots_all, &outputs, FLAGS_num_threads);
124+
TestPrediction(reinterpret_cast<const PaddlePredictor::Config *>(&cfg),
125+
input_slots_all, &outputs, FLAGS_num_threads);
125126

126127
if (FLAGS_num_threads == 1 && !FLAGS_test_all_data) {
127128
// the first inference result
@@ -160,7 +161,8 @@ TEST(Analyzer_Chinese_ner, compare) {
160161

161162
std::vector<std::vector<PaddleTensor>> input_slots_all;
162163
SetInput(&input_slots_all);
163-
CompareNativeAndAnalysis(cfg, input_slots_all);
164+
CompareNativeAndAnalysis(
165+
reinterpret_cast<const PaddlePredictor::Config *>(&cfg), input_slots_all);
164166
}
165167

166168
} // namespace inference

paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ void profile(bool use_mkldnn = false) {
4545

4646
std::vector<std::vector<PaddleTensor>> input_slots_all;
4747
SetInput(&input_slots_all);
48-
TestPrediction(cfg, input_slots_all, &outputs, FLAGS_num_threads);
48+
TestPrediction(reinterpret_cast<const PaddlePredictor::Config *>(&cfg),
49+
input_slots_all, &outputs, FLAGS_num_threads);
4950
}
5051

5152
TEST(Analyzer_resnet50, profile) { profile(); }
@@ -74,7 +75,8 @@ void compare(bool use_mkldnn = false) {
7475

7576
std::vector<std::vector<PaddleTensor>> input_slots_all;
7677
SetInput(&input_slots_all);
77-
CompareNativeAndAnalysis(cfg, input_slots_all);
78+
CompareNativeAndAnalysis(
79+
reinterpret_cast<const PaddlePredictor::Config *>(&cfg), input_slots_all);
7880
}
7981

8082
TEST(Analyzer_resnet50, compare) { compare(); }

0 commit comments

Comments
 (0)