1 /* Copyright 2019 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_XPLANE_TO_OP_STATS_H_
17 #define TENSORFLOW_CORE_PROFILER_CONVERT_XPLANE_TO_OP_STATS_H_
18 
19 #include "absl/container/flat_hash_set.h"
20 #include "tensorflow/core/platform/status.h"
21 #include "tensorflow/core/profiler/protobuf/hardware_types.pb.h"
22 #include "tensorflow/core/profiler/protobuf/op_stats.pb.h"
23 #include "tensorflow/core/profiler/protobuf/xplane.pb.h"
24 
25 namespace tensorflow {
26 namespace profiler {
27 
28 struct OpStatsOptions {
29   bool maybe_drop_incomplete_steps = false;
30   bool generate_op_metrics_db = false;
31   bool generate_step_db = false;
32   bool generate_kernel_stats_db = false;
33 };
34 
35 // NOTE: call GroupTfEvents before if OpStats.step_db needs to be generated.
36 OpStats ConvertXSpaceToOpStats(const XSpace& space,
37                                const OpStatsOptions& options);
38 
39 // Propagate and dedup the diagnostics in XSpace and add to OpStats.
40 void PropagateXSpaceDiagnosticsToOpStats(const XSpace& space,
41                                          OpStats* op_stats);
42 
43 // Extracts DeviceCapabilities from XPlane stats.
44 DeviceCapabilities GetDeviceCapFromXPlane(const XPlane& device_plane);
45 
46 // Populates PerfEnv.
47 PerfEnv MakePerfEnv(double peak_tera_flops_per_second,
48                     double peak_hbm_bw_giga_bytes_per_second);
49 
50 // Extracts PerfEnv from XPlane stats.
51 PerfEnv GetPerfEnvFromXPlane(const XPlane& device_plane);
52 
53 // Reads multiple XSpaces from <xspace_paths>, convert them to OpStats, and
54 // combine them to a single OpStats in <combined_op_stats>.
55 // Return the first error status during conversion, or return Status::OK() if
56 // there is no error.
57 Status ConvertMultiXSpacesToCombinedOpStats(
58     const std::vector<std::string>& xspace_paths, const OpStatsOptions& options,
59     OpStats* combined_op_stats);
60 
61 }  // namespace profiler
62 }  // namespace tensorflow
63 
64 #endif  // TENSORFLOW_CORE_PROFILER_CONVERT_XPLANE_TO_OP_STATS_H_
65