@@ -74,8 +74,8 @@ void CompareResult(const std::vector<PaddleTensor> &outputs,
74
74
}
75
75
}
76
76
77
- std::unique_ptr<PaddlePredictor> GetPrediction (AnalysisConfig config,
78
- bool use_analysis = true ) {
77
+ std::unique_ptr<PaddlePredictor> CreateTestPredictor (
78
+ const AnalysisConfig &config, bool use_analysis = true ) {
79
79
if (use_analysis) {
80
80
return CreatePaddlePredictor<AnalysisConfig, PaddleEngineKind::kAnalysis >(
81
81
config);
@@ -92,7 +92,7 @@ size_t GetSize(const PaddleTensor &out) {
92
92
93
93
std::unordered_map<std::string, int > GetFuseStatis (AnalysisConfig config,
94
94
int *num_ops) {
95
- auto predictor = GetPrediction (config);
95
+ auto predictor = CreateTestPredictor (config);
96
96
AnalysisPredictor *analysis_predictor =
97
97
dynamic_cast <AnalysisPredictor *>(predictor.get ());
98
98
auto &fuse_statis = analysis_predictor->analysis_argument ()
@@ -113,11 +113,12 @@ std::unordered_map<std::string, int> GetFuseStatis(AnalysisConfig config,
113
113
}
114
114
115
115
void TestOneThreadPrediction (
116
- AnalysisConfig config, const std::vector<std::vector<PaddleTensor>> inputs,
116
+ const AnalysisConfig &config,
117
+ const std::vector<std::vector<PaddleTensor>> &inputs,
117
118
std::vector<PaddleTensor> *outputs, bool use_analysis = true ) {
118
119
int batch_size = FLAGS_batch_size;
119
120
int num_times = FLAGS_repeat;
120
- auto predictor = GetPrediction (config, use_analysis);
121
+ auto predictor = CreateTestPredictor (config, use_analysis);
121
122
Timer timer;
122
123
timer.tic ();
123
124
for (int i = 0 ; i < num_times; i++) {
@@ -130,7 +131,8 @@ void TestOneThreadPrediction(
130
131
}
131
132
132
133
void TestMultiThreadPrediction (
133
- AnalysisConfig config, const std::vector<std::vector<PaddleTensor>> inputs,
134
+ const AnalysisConfig &config,
135
+ const std::vector<std::vector<PaddleTensor>> &inputs,
134
136
std::vector<PaddleTensor> *outputs, int num_threads,
135
137
bool use_analysis = true ) {
136
138
int batch_size = FLAGS_batch_size;
@@ -140,7 +142,7 @@ void TestMultiThreadPrediction(
140
142
// TODO(yanchunwei): Bug here, the analyzer phase can't be parallelled
141
143
// because AttentionLSTM's hard code nodeid will be damanged.
142
144
for (int tid = 0 ; tid < num_threads; ++tid) {
143
- predictors.emplace_back (GetPrediction (config, use_analysis));
145
+ predictors.emplace_back (CreateTestPredictor (config, use_analysis));
144
146
}
145
147
for (int tid = 0 ; tid < num_threads; ++tid) {
146
148
threads.emplace_back ([&, tid]() {
@@ -164,8 +166,8 @@ void TestMultiThreadPrediction(
164
166
}
165
167
}
166
168
167
- void TestPrediction (AnalysisConfig config,
168
- const std::vector<std::vector<PaddleTensor>> inputs,
169
+ void TestPrediction (const AnalysisConfig & config,
170
+ const std::vector<std::vector<PaddleTensor>> & inputs,
169
171
std::vector<PaddleTensor> *outputs, int num_threads,
170
172
bool use_analysis = FLAGS_use_analysis) {
171
173
LOG (INFO) << " use_analysis: " << use_analysis;
@@ -178,8 +180,8 @@ void TestPrediction(AnalysisConfig config,
178
180
}
179
181
180
182
void CompareNativeAndAnalysis (
181
- AnalysisConfig config,
182
- const std::vector<std::vector<PaddleTensor>> inputs) {
183
+ const AnalysisConfig & config,
184
+ const std::vector<std::vector<PaddleTensor>> & inputs) {
183
185
std::vector<PaddleTensor> native_outputs, analysis_outputs;
184
186
TestOneThreadPrediction (config, inputs, &native_outputs, false );
185
187
TestOneThreadPrediction (config, inputs, &analysis_outputs, true );
0 commit comments