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_TRACE_UTILS_H_ 17 #define TENSORFLOW_CORE_PROFILER_UTILS_TRACE_UTILS_H_ 18 19 #include "tensorflow/core/platform/types.h" 20 21 namespace tensorflow { 22 namespace profiler { 23 24 // Constants used as trace_viewer PID (device_id in trace_events.proto). 25 // PID 0 is unused. 26 // Support up to 500 accelerator devices. 27 constexpr uint32 kFirstDeviceId = 1; 28 constexpr uint32 kLastDeviceId = 500; 29 // Host threads are shown as a single fake device. 30 constexpr uint32 kHostThreadsDeviceId = kLastDeviceId + 1; 31 32 // Constants used as trace_viewer TID (resource_id in trace_events.proto). 33 constexpr int kThreadIdDerivedMin = 0xdeadbeef; 34 constexpr int kThreadIdStepInfo = kThreadIdDerivedMin; 35 constexpr int kThreadIdKernelLaunch = kThreadIdDerivedMin + 1; 36 constexpr int kThreadIdTfNameScope = kThreadIdDerivedMin + 2; 37 constexpr int kThreadIdTfOp = kThreadIdDerivedMin + 3; 38 constexpr int kThreadIdHloModule = kThreadIdDerivedMin + 4; 39 constexpr int kThreadIdHloOp = kThreadIdDerivedMin + 5; 40 constexpr int kThreadIdOverhead = kThreadIdDerivedMin + 6; 41 constexpr int kThreadIdDerivedMax = kThreadIdOverhead; 42 IsDerivedThreadId(int thread_id)43static inline bool IsDerivedThreadId(int thread_id) { 44 return thread_id >= kThreadIdDerivedMin && thread_id <= kThreadIdDerivedMax; 45 } 46 47 } // namespace profiler 48 } // namespace tensorflow 49 50 #endif // TENSORFLOW_CORE_PROFILER_UTILS_TRACE_UTILS_H_ 51