@@ -115,11 +115,11 @@ void TestInference(const std::string& dirname,
115
115
#endif
116
116
}
117
117
118
- // Enable the profiler
119
- paddle::platform::EnableProfiler (state);
120
-
121
118
// 2. Initialize the inference_program and load parameters
122
119
std::unique_ptr<paddle::framework::ProgramDesc> inference_program;
120
+
121
+ // Enable the profiler
122
+ paddle::platform::EnableProfiler (state);
123
123
{
124
124
paddle::platform::RecordEvent record_event (
125
125
" init_program" ,
@@ -143,6 +143,10 @@ void TestInference(const std::string& dirname,
143
143
inference_program = paddle::inference::Load (executor, *scope, dirname);
144
144
}
145
145
}
146
+ // Disable the profiler and print the timing information
147
+ paddle::platform::DisableProfiler (paddle::platform::EventSortingKey::kDefault ,
148
+ " load_program_profiler.txt" );
149
+ paddle::platform::ResetProfiler ();
146
150
147
151
// 3. Get the feed_target_names and fetch_target_names
148
152
const std::vector<std::string>& feed_target_names =
@@ -165,6 +169,12 @@ void TestInference(const std::string& dirname,
165
169
166
170
// 6. Run the inference program
167
171
{
172
+ // Ignore the profiling results of the first run
173
+ executor.Run (*inference_program, scope, feed_targets, fetch_targets);
174
+
175
+ // Enable the profiler
176
+ paddle::platform::EnableProfiler (state);
177
+
168
178
// Run repeat times to profile the performance
169
179
for (int i = 0 ; i < repeat; ++i) {
170
180
paddle::platform::RecordEvent record_event (
@@ -173,12 +183,13 @@ void TestInference(const std::string& dirname,
173
183
174
184
executor.Run (*inference_program, scope, feed_targets, fetch_targets);
175
185
}
176
- }
177
186
178
- // Disable the profiler and print the timing information
179
- paddle::platform::DisableProfiler (paddle::platform::EventSortingKey::kDefault ,
180
- " profiler.txt" );
181
- paddle::platform::ResetProfiler ();
187
+ // Disable the profiler and print the timing information
188
+ paddle::platform::DisableProfiler (
189
+ paddle::platform::EventSortingKey::kDefault ,
190
+ " run_inference_profiler.txt" );
191
+ paddle::platform::ResetProfiler ();
192
+ }
182
193
183
194
delete scope;
184
195
}
0 commit comments