xref: /aosp_15_r20/external/tensorflow/tensorflow/core/profiler/lib/context_types.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 #ifndef TENSORFLOW_CORE_PROFILER_LIB_CONTEXT_TYPES_H_
16 #define TENSORFLOW_CORE_PROFILER_LIB_CONTEXT_TYPES_H_
17 
18 #include <cstdint>
19 
20 namespace tensorflow {
21 namespace profiler {
22 
23 enum class ContextType : int {
24   kGeneric = 0,
25   kLegacy,
26   kTfExecutor,
27   kTfrtExecutor,
28   kSharedBatchScheduler,
29   kPjRt,
30   kAdaptiveSharedBatchScheduler,
31   kTfrtTpuRuntime,
32   kTpuEmbeddingEngine,
33   kGpuLaunch,
34   kBatcher,
35   kTpuStream,
36   kTpuLaunch,
37   kLastContextType = ContextType::kTpuLaunch,
38 };
39 
40 // In XFlow we encode context type as flow category as 6 bits.
41 static_assert(static_cast<int>(ContextType::kLastContextType) < 64,
42               "Should have less than 64 categories.");
43 
44 const char* GetContextTypeString(ContextType context_type);
45 
GetSafeContextType(uint32_t context_type)46 inline ContextType GetSafeContextType(uint32_t context_type) {
47   if (context_type > static_cast<uint32_t>(ContextType::kLastContextType)) {
48     return ContextType::kGeneric;
49   }
50   return static_cast<ContextType>(context_type);
51 }
52 
53 }  // namespace profiler
54 }  // namespace tensorflow
55 
56 #endif  // TENSORFLOW_CORE_PROFILER_UTILS_CONTEXT_TYPES_H_
57