Skip to content

Commit e011e34

Browse files
authored
Merge pull request #12310 from jacquesqiao/add-profiler-to-train-demo
add profiler for demo_trainer
2 parents abe32a4 + 35d09ab commit e011e34

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

paddle/fluid/train/demo/demo_trainer.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <time.h>
1516
#include <fstream>
1617

1718
#include "paddle/fluid/framework/executor.h"
@@ -21,6 +22,7 @@
2122
#include "paddle/fluid/platform/device_context.h"
2223
#include "paddle/fluid/platform/init.h"
2324
#include "paddle/fluid/platform/place.h"
25+
#include "paddle/fluid/platform/profiler.h"
2426

2527
namespace paddle {
2628
namespace train {
@@ -93,11 +95,21 @@ int main() {
9395

9496
auto loss_var = scope.Var(loss_name);
9597

98+
paddle::platform::ProfilerState pf_state;
99+
pf_state = paddle::platform::ProfilerState::kCPU;
100+
paddle::platform::EnableProfiler(pf_state);
101+
clock_t t1 = clock();
102+
96103
for (int i = 0; i < 10; ++i) {
97104
executor.Run(*train_program.get(), &scope, 0, false, true);
98105
std::cout << "step: " << i << " loss: "
99106
<< loss_var->Get<paddle::framework::LoDTensor>().data<float>()[0]
100107
<< std::endl;
101108
}
109+
110+
clock_t t2 = clock();
111+
paddle::platform::DisableProfiler(paddle::platform::EventSortingKey::kTotal,
112+
"run_paddle_op_profiler");
113+
std::cout << "run_time = " << t2 - t1 << std::endl;
102114
return 0;
103115
}

0 commit comments

Comments
 (0)