• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GRAPHDEF_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSLATE_EXPORT_GRAPHDEF_H_
18 
19 #include "absl/container/flat_hash_set.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
22 #include "mlir/IR/MLIRContext.h"  // from @llvm-project
23 #include "mlir/IR/Operation.h"  // from @llvm-project
24 #include "tensorflow/compiler/mlir/tensorflow/translate/mlir_roundtrip_flags.h"
25 #include "tensorflow/core/framework/function.h"
26 #include "tensorflow/core/framework/graph.pb.h"
27 #include "tensorflow/core/framework/node_def.pb.h"
28 #include "tensorflow/core/graph/graph.h"
29 #include "tensorflow/stream_executor/lib/statusor.h"
30 
31 namespace tensorflow {
32 // Given an MLIR module, returns a GraphDef.
33 stream_executor::port::StatusOr<std::unique_ptr<GraphDef>>
34 ConvertMlirToGraphdef(mlir::ModuleOp module, const GraphExportConfig& configs);
35 
36 // Converts an MLIR module to TensorFlow graph and FunctionLibraryDefinition.
37 // The "main" function of the module is stored in the graph and the rest of
38 // functions are stored in the library. Control ret nodes are stored separately
39 // in `control_ret_nodes`.
40 Status ConvertMlirToGraph(mlir::ModuleOp module,
41                           const GraphExportConfig& configs,
42                           std::unique_ptr<Graph>* graph,
43                           FunctionLibraryDefinition* flib_def,
44                           absl::flat_hash_set<Node*>* control_ret_nodes);
45 
46 // Converts an MLIR module to TensorFlow graph and FunctionLibraryDefinition.
47 // The "main" function of the module is stored in the graph and the rest of
48 // functions are stored in the library.
49 Status ConvertMlirToGraph(mlir::ModuleOp module,
50                           const GraphExportConfig& configs,
51                           std::unique_ptr<Graph>* graph,
52                           FunctionLibraryDefinition* flib_def);
53 
54 // Converts an MLIR function and adds it to a FunctionLibraryDefinition.
55 Status ConvertMlirFunctionToFunctionLibraryDef(mlir::FuncOp func,
56                                                const GraphExportConfig& configs,
57                                                FunctionDef* function_def);
58 }  // namespace tensorflow
59 
60 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSLATE_EXPORT_GRAPHDEF_H_
61