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_CORE_IR_IMPORTEXPORT_GRAPHDEF_EXPORT_H_ 17 #define TENSORFLOW_CORE_IR_IMPORTEXPORT_GRAPHDEF_EXPORT_H_ 18 19 #include <string> 20 21 #include "mlir/IR/BuiltinOps.h" // from @llvm-project 22 #include "mlir/IR/Value.h" // from @llvm-project 23 #include "mlir/Support/LLVM.h" // from @llvm-project 24 #include "tensorflow/core/framework/function.h" 25 #include "tensorflow/core/framework/graph.pb.h" 26 #include "tensorflow/core/framework/node_def.pb.h" 27 #include "tensorflow/core/ir/dialect.h" 28 #include "tensorflow/core/ir/ops.h" 29 #include "tensorflow/core/platform/status.h" 30 #include "tensorflow/core/platform/statusor.h" 31 32 namespace mlir { 33 namespace tfg { 34 35 // Get the name of a value as if it were an edge in a graph. 36 tensorflow::StatusOr<std::string> GetValueName(Value value, 37 TFGraphDialect *dialect); 38 39 // Convert a TFG graph directly to GraphDef. Graph functions in the module are 40 // added to the GraphDef's function library. 41 tensorflow::Status ConvertToGraphDef(ModuleOp module, 42 tensorflow::GraphDef *graph); 43 44 // Convert a single TFG op to NodeDef. This utliity function requires a callback 45 // `get_value_name` that returns the edge name of the given operand. 46 tensorflow::Status ConvertToNodeDef( 47 Operation *op, tensorflow::NodeDef *node, TFGraphDialect *dialect, 48 function_ref<tensorflow::StatusOr<std::string>(Value)> get_value_name); 49 50 // Convert a single TFG function to a FunctionDef and add it to the function 51 // library. If a function with the same name already exists, replace it. 52 tensorflow::Status ConvertToFunctionDef( 53 GraphFuncOp func, tensorflow::FunctionLibraryDefinition &library); 54 55 } // namespace tfg 56 } // namespace mlir 57 58 #endif // TENSORFLOW_CORE_IR_IMPORTEXPORT_GRAPHDEF_EXPORT_H_ 59