• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/lite/delegates/gpu/common/task/profiling_info.h"
17 
18 #include <map>
19 
20 namespace tflite {
21 namespace gpu {
22 
GetTotalTime() const23 absl::Duration ProfilingInfo::GetTotalTime() const {
24   absl::Duration total_time;
25   for (const auto& dispatch : dispatches) {
26     total_time += dispatch.duration;
27   }
28   return total_time;
29 }
30 
GetDetailedReport() const31 std::string ProfilingInfo::GetDetailedReport() const {
32   std::string result;
33   struct OpStatistic {
34     int count;
35     double total_time;
36   };
37   std::map<std::string, OpStatistic> statistics;
38   result +=
39       "Per kernel timing(" + std::to_string(dispatches.size()) + " kernels):\n";
40   for (const auto& dispatch : dispatches) {
41     result += "  " + dispatch.label + " - " +
42               std::to_string(absl::ToDoubleMilliseconds(dispatch.duration)) +
43               " ms\n";
44     auto name = dispatch.label.substr(0, dispatch.label.find(' '));
45     if (statistics.find(name) != statistics.end()) {
46       statistics[name].count++;
47       statistics[name].total_time +=
48           absl::ToDoubleMilliseconds(dispatch.duration);
49     } else {
50       statistics[name].count = 1;
51       statistics[name].total_time =
52           absl::ToDoubleMilliseconds(dispatch.duration);
53     }
54   }
55   result += "--------------------\n";
56   result += "Accumulated time per operation type:\n";
57   for (auto& t : statistics) {
58     auto stat = t.second;
59     result += "  " + t.first + "(x" + std::to_string(stat.count) + ") - " +
60               std::to_string(stat.total_time) + " ms\n";
61   }
62   result += "--------------------\n";
63   result += "Ideal total time: " +
64             std::to_string(absl::ToDoubleMilliseconds(GetTotalTime())) + "\n";
65   result += "--------------------\n";
66   return result;
67 }
68 
69 }  // namespace gpu
70 }  // namespace tflite
71