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_METRICS_DB_H_ 17 #define TENSORFLOW_CORE_PROFILER_CONVERT_XPLANE_TO_OP_METRICS_DB_H_ 18 19 #include "absl/container/flat_hash_map.h" 20 #include "tensorflow/core/platform/types.h" 21 #include "tensorflow/core/profiler/convert/op_metrics_db_combiner.h" 22 #include "tensorflow/core/profiler/protobuf/op_metrics.pb.h" 23 #include "tensorflow/core/profiler/protobuf/xplane.pb.h" 24 #include "tensorflow/core/profiler/utils/op_utils.h" 25 #include "tensorflow/core/profiler/utils/tf_op_utils.h" 26 #include "tensorflow/core/profiler/utils/xplane_visitor.h" 27 28 namespace tensorflow { 29 namespace profiler { 30 31 // Data per host thread for TensorFlow Op Metrics Database. 32 struct TfMetricsDbData { 33 // The start timestamp in ps of the last infeed enqueue op on this core. 34 uint64 last_infeed_enq_start_timestamp_ps = 0; 35 // The duration in ps of the last infeed enqueue op on this core. 36 uint64 last_infeed_enq_duration_ps = 0; 37 38 // A database of TF-Op metrics for this core. 39 OpMetricsDb tf_metrics_db; 40 HostOpMetricsDbBuilder tf_metrics_db_builder{&tf_metrics_db}; 41 }; 42 43 absl::flat_hash_map<int64, TfOp> CollectTfOpsFromHostThreadsXPlane( 44 const XPlane& host_trace); 45 46 TfMetricsDbData ConvertHostThreadsXLineToTfMetricsDbData( 47 const XLineVisitor& line, const absl::flat_hash_map<int64, TfOp>& tf_ops); 48 49 void ConsumeTfMetricsDbData(TfMetricsDbData src, OpMetricsDbCombiner* dst); 50 51 OpMetricsDb ConvertHostThreadsXPlaneToOpMetricsDb(const XPlane& host_trace); 52 53 OpMetricsDb ConvertDeviceTraceXPlaneToOpMetricsDb(const XPlane& device_trace); 54 55 } // namespace profiler 56 } // namespace tensorflow 57 58 #endif // TENSORFLOW_CORE_PROFILER_CONVERT_XPLANE_TO_OP_METRICS_DB_H_ 59