• 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_TF_MLIR_TRANSLATE_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSLATE_TF_MLIR_TRANSLATE_H_
18 
19 #include <string>
20 #include <unordered_set>
21 
22 #include "absl/base/macros.h"
23 #include "absl/strings/string_view.h"
24 #include "absl/types/span.h"
25 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
26 #include "mlir/IR/MLIRContext.h"  // from @llvm-project
27 #include "tensorflow/compiler/mlir/tensorflow/translate/mlir_import_options.h"
28 #include "tensorflow/stream_executor/lib/statusor.h"
29 
30 namespace tensorflow {
31 
32 using stream_executor::port::Status;
33 using stream_executor::port::StatusOr;
34 
35 // TODO(antiagainst): Directly manipulating files in library functions is not
36 // a good idea. We should pass in a string/stream here.
37 
38 // Converts a TensorFlow GraphDef contained in `input` param into a MLIR module.
39 // Creates MLIR entities into the given MLIR `context`.
40 StatusOr<mlir::OwningModuleRef> GraphdefToMlirTranslateFunction(
41     llvm::StringRef input, absl::string_view debug_info_file,
42     const std::vector<std::string>& input_arrays,
43     const std::vector<std::string>& input_dtypes,
44     const std::vector<llvm::Optional<std::vector<int>>>& input_shapes,
45     const std::vector<std::string>& output_arrays,
46     const std::vector<std::string>& control_output_arrays,
47     bool prune_unused_nodes, bool convert_legacy_fed_inputs,
48     bool graph_as_function, bool upgrade_legacy,
49     // TODO(jpienaar): Remove this.
50     bool enable_shape_inference, mlir::MLIRContext* context);
51 
52 ABSL_DEPRECATED(
53     "Please use the other overload of this function which accepts structured "
54     "inputs instead of strings")
55 // Converts a TensorFlow GraphDef contained in `input` param into a MLIR module.
56 // Creates MLIR entities into the given MLIR `context`.
57 StatusOr<mlir::OwningModuleRef> GraphdefToMlirTranslateFunction(
58     llvm::StringRef input, absl::string_view debug_info_file,
59     absl::string_view input_arrays, absl::string_view input_dtypes,
60     absl::string_view input_shapes, absl::string_view output_arrays,
61     absl::string_view control_output_arrays, bool prune_unused_nodes,
62     bool convert_legacy_fed_inputs, bool graph_as_function, bool upgrade_legacy,
63     // TODO(jpienaar): Remove this.
64     bool enable_shape_inference, mlir::MLIRContext* context);
65 
66 // Similar as the above function, but replaces all constant tensors
67 // with randomly generated splat values.
68 StatusOr<mlir::OwningModuleRef> GraphdefToSplattedMlirTranslateFunction(
69     llvm::StringRef input, absl::string_view debug_info_file,
70     const std::vector<std::string>& input_arrays,
71     const std::vector<std::string>& input_dtypes,
72     const std::vector<std::vector<int>>& input_shapes,
73     const std::vector<std::string>& output_arrays,
74     const std::vector<std::string>& control_output_arrays,
75     bool prune_unused_nodes, bool convert_legacy_fed_inputs,
76     bool graph_as_function, bool upgrade_legacy, bool enable_shape_inference,
77     mlir::MLIRContext* context);
78 
79 ABSL_DEPRECATED(
80     "Please use the other overload of this function which accepts structured "
81     "inputs instead of strings")
82 // Similar as the above function, but replaces all constant tensors
83 // with randomly generated splat values.
84 StatusOr<mlir::OwningModuleRef> GraphdefToSplattedMlirTranslateFunction(
85     llvm::StringRef input, absl::string_view debug_info_file,
86     absl::string_view input_arrays, absl::string_view input_dtypes,
87     absl::string_view input_shapes, absl::string_view output_arrays,
88     absl::string_view control_output_arrays, bool prune_unused_nodes,
89     bool convert_legacy_fed_inputs, bool graph_as_function, bool upgrade_legacy,
90     // TODO(jpienaar): Remove this.
91     bool enable_shape_inference, mlir::MLIRContext* context);
92 
93 // Converts a TensorFlow SavedModel stored in the directory with the given
94 // `saved_model_dir` into a MLIR module. Creates MLIR entities into the
95 // given MLIR `context`.
96 StatusOr<mlir::OwningModuleRef> SavedModelObjectGraphToMlirImport(
97     absl::string_view saved_model_dir,
98     const std::unordered_set<std::string>& tags,
99     absl::Span<std::string> exported_names, mlir::MLIRContext* context);
100 
101 // Converts a TensorFlow V1 SavedModel stored in the directory with the given
102 // `saved_model_dir` into a MLIR module. Creates MLIR entities into the
103 // given MLIR `context`.
104 StatusOr<mlir::OwningModuleRef> SavedModelSignatureDefsToMlirImport(
105     absl::string_view saved_model_dir,
106     const std::unordered_set<std::string>& tags,
107     absl::Span<std::string> exported_names, mlir::MLIRContext* context,
108     MLIRImportOptions options);
109 
110 // Converts a TensorFlow V1 SavedModel stored in the directory with the given
111 // `saved_model_dir` into a MLIR module. Creates MLIR entities into the
112 // given MLIR `context`. This does not create session internally so it is faster
113 // and does not perform any graph transformation.
114 StatusOr<mlir::OwningModuleRef> SavedModelSignatureDefsToMlirImportLite(
115     absl::string_view saved_model_dir,
116     const std::unordered_set<std::string>& tags,
117     absl::Span<std::string> exported_names, mlir::MLIRContext* context,
118     MLIRImportOptions options);
119 
120 }  // namespace tensorflow
121 
122 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSLATE_TF_MLIR_TRANSLATE_H_
123