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_TRANSLATE_EXPORT_TF_DIALECT_OP_H_ 17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSLATE_EXPORT_TF_DIALECT_OP_H_ 18 19 #include "llvm/ADT/StringRef.h" 20 #include "mlir/IR/Operation.h" // from @llvm-project 21 #include "tensorflow/compiler/mlir/tensorflow/utils/export_utils.h" 22 #include "tensorflow/core/framework/attr_value.pb.h" 23 #include "tensorflow/core/framework/node_def.pb.h" 24 #include "tensorflow/core/framework/node_def_util.h" 25 #include "tensorflow/core/framework/op_def_builder.h" 26 #include "tensorflow/core/platform/status.h" 27 #include "tensorflow/stream_executor/lib/statusor.h" 28 29 namespace tensorflow { 30 31 // Extracts the attributes of a MLIR operation and populates the converted 32 // attributes in a proto map<string, AttrValue>. 33 Status GetAttrValuesFromOperation( 34 mlir::Operation* inst, llvm::StringRef name, 35 const tensorflow::OpRegistrationData* op_reg_data, 36 bool ignore_unregistered_attrs, AttrValueMap* attributes); 37 38 // Converts a MLIR operation to TensorFlow NodeDef with given node name. This 39 // name should be unique to the graph it is being inserted to. If the 40 // `ignore_unregistered_attrs` argument is set to true, the attributes which are 41 // not in the op registry will be ignored. If the `ignore_unregistered_attrs` 42 // argument is not set to true, _output_shapes attribute is added to nodes with 43 // ShapedType for the leading values with ShapedType in the results of the 44 // nodes. Set it to true if the returned NodeDef will be executed by the linked 45 // TF Eager runtime. 46 StatusOr<std::unique_ptr<NodeDef>> ConvertTFDialectOpToNodeDef( 47 mlir::Operation* inst, llvm::StringRef name, 48 bool ignore_unregistered_attrs); 49 50 } // namespace tensorflow 51 52 #endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSLATE_EXPORT_TF_DIALECT_OP_H_ 53