xref: /aosp_15_r20/external/tensorflow/tensorflow/core/profiler/convert/op_stats_to_op_profile.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2022 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 #ifndef TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OP_PROFILE_H_
17 #define TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OP_PROFILE_H_
18 
19 #include "tensorflow/core/profiler/protobuf/hardware_types.pb.h"
20 #include "tensorflow/core/profiler/protobuf/op_profile.pb.h"
21 #include "tensorflow/core/profiler/protobuf/op_stats.pb.h"
22 
23 namespace tensorflow {
24 namespace profiler {
25 
26 // Assembles a hierarchical performance profile based on HLOs in the op metrics
27 // db.
28 // The node hierarchy is as following:
29 //    by_category
30 //      - combined_root
31 //          - category 1
32 //          - category 2
33 //          - ...
34 //      - idle
35 //    by_program
36 //      - program_1_root
37 //          - category 1
38 //          - category 2
39 //          - ...
40 //      - program_2_root
41 //          - category 1
42 //          - ...
43 //      - idle
44 // The nodes in the profile are sorted by time in decreasing order and pruned
45 // to reduce the profile size. Only 100 nodes are kept for level >= 3.
46 // See op_profile.proto for the detailed semantics of the returned profile.
47 void ConvertOpStatsToOpProfile(
48     const tensorflow::profiler::OpStats& op_stats,
49     tensorflow::profiler::HardwareType hardware_type,
50     tensorflow::profiler::op_profile::Profile& profile);
51 
52 }  // namespace profiler
53 }  // namespace tensorflow
54 
55 #endif  // THIRD_PARTY_TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OP_PROFILE_H_
56