xref: /aosp_15_r20/external/tensorflow/tensorflow/core/common_runtime/device/device_utils.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2021 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_COMMON_RUNTIME_DEVICE_DEVICE_UTILS_H_
16 #define TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_UTILS_H_
17 
18 #include "tensorflow/core/platform/status.h"
19 #include "tensorflow/core/platform/stringpiece.h"
20 
21 namespace tensorflow {
22 namespace device_utils {
23 
24 // Validate device type. Device type must start with a capital letter and
25 // consist of capital letters and underscores. Reasoning behind this decision:
26 // * At the minimum we want to disallow '/' and ':' since
27 //   these characters are used in device spec, for e.g.
28 //   /job:foo/replica:12/device:GPU:1.
29 // * Underscores seem useful, for e.g. XLA_GPU uses underscores.
30 // * Allowing lowercase might get confusing. For example, say someone
31 //   registers a new type called "Gpu". It might be confusing for users that
32 //   "Gpu" is not the same device type as "GPU".
33 //   Note that lowercase "cpu" and "gpu" are currently supported only for
34 //   legacy reasons:
35 //   https://cs.opensource.google/tensorflow/tensorflow/+/master:tensorflow/python/framework/device_spec.py;l=46;drc=d3a378f9665d8eee827c74cb9ecbee81e4c288dd
36 Status ValidateDeviceType(StringPiece type);
37 
38 }  // namespace device_utils
39 }  // namespace tensorflow
40 
41 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_UTILS_H_
42