MCPcopy Create free account
hub / github.com/OpenPPL/ppl.nn / Profiling

Function Profiling

tools/pplnn.cc:1082–1131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1080}
1081
1082static bool Profiling(const vector<string>& input_data, Runtime* runtime) {
1083 if (g_flag_warmup_iterations > 0) {
1084 LOG(INFO) << "Warm up start for " << g_flag_warmup_iterations << " times.";
1085 for (uint32_t i = 0; i < g_flag_warmup_iterations; ++i) {
1086 runtime->Run();
1087 }
1088 LOG(INFO) << "Warm up end.";
1089 }
1090
1091#ifdef PPLNN_ENABLE_KERNEL_PROFILING
1092 auto status = runtime->Configure(RUNTIME_CONF_SET_KERNEL_PROFILING_FLAG, true);
1093 if (status != RC_SUCCESS) {
1094 LOG(WARNING) << "enable profiling failed: " << GetRetCodeStr(status);
1095 }
1096#endif
1097 LOG(INFO) << "Profiling start";
1098
1099 double run_dur = 0;
1100 uint32_t run_count = 0;
1101 while (run_dur < g_flag_min_profiling_seconds * 1000 || run_count < g_flag_min_profiling_iterations) {
1102 auto run_begin_ts = std::chrono::system_clock::now();
1103 if (g_flag_perf_with_io) {
1104 SetInputs(input_data, runtime);
1105 }
1106 runtime->Run();
1107 if (g_flag_perf_with_io) {
1108 GetOutputs(runtime);
1109 }
1110 auto run_end_ts = std::chrono::system_clock::now();
1111 auto diff = std::chrono::duration_cast<std::chrono::microseconds>(run_end_ts - run_begin_ts);
1112 run_dur += (double)diff.count() / 1000;
1113 run_count += 1;
1114 }
1115
1116 LOG(INFO) << "Total duration: " << run_dur << " ms";
1117
1118#ifdef PPLNN_ENABLE_KERNEL_PROFILING
1119 ProfilingStatistics stat;
1120 status = runtime->GetProfilingStatistics(&stat);
1121 if (status != RC_SUCCESS) {
1122 LOG(WARNING) << "Get profiling statistics failed: " << GetRetCodeStr(status);
1123 }
1124 PrintProfilingStatistics(stat, run_dur, run_count);
1125#else
1126 LOG(INFO) << "Average run costs: " << (run_dur / run_count) << " ms.";
1127#endif
1128
1129 LOG(INFO) << "Profiling End";
1130 return true;
1131}
1132
1133static uint32_t CalcModelNum() {
1134 uint32_t counter = 0;

Callers 1

mainFunction · 0.70

Calls 6

SetInputsFunction · 0.70
GetOutputsFunction · 0.70
PrintProfilingStatisticsFunction · 0.70
RunMethod · 0.45
ConfigureMethod · 0.45

Tested by

no test coverage detected