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_OP_UTILS_H_ 17 #define TENSORFLOW_DTENSOR_MLIR_OP_UTILS_H_ 18 19 #include <string> 20 21 #include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project 22 #include "mlir/IR/Operation.h" // from @llvm-project 23 #include "mlir/IR/Value.h" // from @llvm-project 24 #include "tensorflow/dtensor/mlir/ir/tf_dtensor.h" 25 26 namespace tensorflow { 27 namespace dtensor { 28 29 // Computes a deterministic hash of the given operation. 30 uint64_t OpHash(mlir::Operation* op); 31 OpName(mlir::Operation * op)32inline std::string OpName(mlir::Operation* op) { 33 auto ref = op->getName().getStringRef(); 34 return ref.str(); 35 } 36 37 // Returns FuncOp if `op` is a callable. 38 absl::optional<mlir::func::FuncOp> MaybeFindFunction(mlir::Operation* op); 39 40 // Removes tf.DTensorLayout op and forwards it's input to it's users. 41 // For example: 42 // %0 = tf.A() 43 // %1 = tf.DTensorLayout(%0) 44 // %2 = tf.B(%1) 45 // 46 // Will be converted to: 47 // %0 = tf.A() 48 // %2 = tf.B(%0) 49 void RemoveDTensorLayoutOp(mlir::TF::DTensorLayout layout); 50 51 } // namespace dtensor 52 } // namespace tensorflow 53 54 #endif // TENSORFLOW_DTENSOR_MLIR_OP_UTILS_H_ 55