1 /* Copyright 2019 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_COMPILER_MLIR_TENSORFLOW_UTILS_DEVICE_UTIL_H_ 17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_DEVICE_UTIL_H_ 18 19 #include "llvm/ADT/SmallVector.h" 20 #include "mlir/IR/Operation.h" // TF:llvm-project 21 #include "mlir/Support/LogicalResult.h" // TF:llvm-project 22 #include "tensorflow/core/common_runtime/device_set.h" 23 #include "tensorflow/core/util/device_name_utils.h" 24 25 namespace tensorflow { 26 // Collects all devices known to the system by name and adds them as a 27 // `tf.devices` array attribute of string attributes to an op. Device names 28 // added are in the following form: 29 // /job:<name>/replica:<replica>/task:<task>/device:<type>:<device_num> 30 void AddDevicesToOp(mlir::Operation* op, const DeviceSet* device_set); 31 32 // Collects devices as DeviceNameUtils::ParsedName from an op `tf.devices` 33 // attribute. A failure will be returned if the attribute is not an 34 // ArrayAttr<StringAttr> or the devices are invalid. 35 mlir::LogicalResult GetDevicesFromOp( 36 mlir::Operation* op, 37 llvm::SmallVectorImpl<DeviceNameUtils::ParsedName>* devices); 38 39 } // namespace tensorflow 40 41 #endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_DEVICE_UTIL_H_ 42