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 | |
16 | #ifndef TENSORFLOW_DTENSOR_MLIR_DEVICE_UTILS_H_ |
17 | #define TENSORFLOW_DTENSOR_MLIR_DEVICE_UTILS_H_ |
18 | |
19 | #include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project |
20 | #include "mlir/IR/Builders.h" // from @llvm-project |
21 | #include "mlir/IR/BuiltinOps.h" // from @llvm-project |
22 | #include "mlir/IR/Location.h" // from @llvm-project |
23 | #include "mlir/IR/Operation.h" // from @llvm-project |
24 | #include "mlir/IR/Value.h" // from @llvm-project |
25 | #include "tensorflow/dtensor/cc/dstatus.h" |
26 | #include "tensorflow/dtensor/cc/tensor_layout.h" |
27 | |
28 | namespace tensorflow { |
29 | namespace dtensor { |
30 | |
31 | // Returns an MLIR value representing the current device ID. Passing op is |
32 | // assumed to be wrapped by a function graph from dtensor_device, and the first |
33 | // argument of the it need to be DeviceId. |
34 | StatusOr<mlir::Value> DeviceId(mlir::Operation* op); |
35 | StatusOr<mlir::Value> DeviceId(mlir::Value val); |
36 | |
37 | // Returns the device ordinal of the device executing a function. Device ordinal |
38 | // is the index of a TF device among all TF devices of the same type attached to |
39 | // the same TF task. |
40 | StatusOr<mlir::Value> GetDeviceOrdinal(const Mesh& mesh, |
41 | const mlir::Location& loc, |
42 | mlir::func::FuncOp function, |
43 | mlir::OpBuilder* builder, |
44 | bool return_int64_type = true); |
45 | |
46 | } // namespace dtensor |
47 | } // namespace tensorflow |
48 | |
49 | #endif // TENSORFLOW_DTENSOR_MLIR_DEVICE_UTILS_H_ |
50 | |