1 /* Copyright 2020 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_UTILS_OP_UTILS_H_ 17 #define TENSORFLOW_CORE_PROFILER_UTILS_OP_UTILS_H_ 18 19 #include "absl/strings/string_view.h" 20 #include "tensorflow/core/platform/protobuf.h" 21 #include "tensorflow/core/platform/types.h" 22 #include "tensorflow/core/profiler/protobuf/op_metrics.pb.h" 23 #include "tensorflow/core/profiler/utils/op_metrics_db_utils.h" 24 25 namespace tensorflow { 26 namespace profiler { 27 28 class HostOpMetricsDbBuilder : public OpMetricsDbBuilder { 29 public: HostOpMetricsDbBuilder(OpMetricsDb * db)30 explicit HostOpMetricsDbBuilder(OpMetricsDb* db) : OpMetricsDbBuilder(db) {} 31 32 // A function that will be called when the end of an OP is 33 // observed on a trace, where: 34 // name = the OP name. 35 // category = the OP category. 36 // is_eager = whether this OP is eagerly executed. 37 // time_ps = the total execution time of the OP in picoseconds, including 38 // the execution time of its children. 39 // children_time_ps = the execution time of the children of this OP in 40 // picoseconds 41 void EnterOp(absl::string_view name, absl::string_view category, 42 bool is_eager, uint64 time_ps, uint64 children_time_ps); 43 44 // Updates total_host_infeed_enq_duration_ps_ and 45 // total_host_infeed_enq_duration_ps_. 46 void UpdateHostInfeedEnqInfo(uint64 duration_ps, 47 uint64 start_timestamp_ps_diff); 48 }; 49 50 class DeviceOpMetricsDbBuilder : public OpMetricsDbBuilder { 51 public: DeviceOpMetricsDbBuilder(OpMetricsDb * db)52 explicit DeviceOpMetricsDbBuilder(OpMetricsDb* db) : OpMetricsDbBuilder(db) {} 53 54 // A function that will be called when the end of an OP is 55 // observed on a trace, where: 56 // program_id = the ID of the program that contains this OP. 57 // name = the OP name. 58 // category = the OP category. 59 // provenance = the provenance of this OP (e.g. original TF OP). 60 // is_eager = whether this OP is eagerly executed. 61 // occurrences = the number of occurrences of this OP. 62 // time_ps = the total execution time of the OP in picoseconds, including 63 // the execution time of its children. 64 // children_time_ps = the execution time of the children of this OP in 65 // picoseconds. 66 // flops = the number of floating-point operations computed. 67 // bytes_accessed = the sum of bytes read and bytes written by this OP. 68 // memory_accessed_breakdown = the breakdown of memory accessed by operation 69 // type and memory space. 70 void EnterOp(uint64 program_id, absl::string_view name, 71 absl::string_view category, absl::string_view provenance, 72 bool is_eager, uint64 occurrences, uint64 time_ps, 73 uint64 children_time_ps, int64 flops, int64 bytes_accessed, 74 const protobuf::RepeatedPtrField<OpMetrics::MemoryAccessed>& 75 memory_accessed_breakdown = {}); 76 }; 77 78 } // namespace profiler 79 } // namespace tensorflow 80 81 #endif // TENSORFLOW_CORE_PROFILER_UTILS_OP_UTILS_H_ 82