• 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_LITE_FLATBUFFER_EXPORT_H_
17 #define TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_EXPORT_H_
18 
19 #include <map>
20 #include <string>
21 #include <unordered_set>
22 
23 #include "mlir/Dialect/Func/IR/FuncOps.h"  // from @llvm-project
24 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
25 #include "tensorflow/compiler/mlir/op_or_arg_name_mapper.h"
26 #include "tensorflow/lite/toco/toco_flags.pb.h"
27 
28 namespace tflite {
29 // Options for exporting to Flatbuffer.
30 struct FlatbufferExportOptions {
31   // TocoFlags proto. The following fields are migrated.
32   // bool emit_builtin_tflite_ops  -> !toco_flags.force_select_tf_ops()
33   // bool emit_select_tf_ops       -> toco_flags.enable_select_tf_ops()
34   // bool emit_custom_ops          -> toco_flags.allow_custom_ops()
35   // bool allow_all_select_tf_ops  -> toco_flags.allow_all_select_tf_ops()
36   // std::set<> select_user_tf_ops -> toco_flags.select_user_tf_ops()
37   toco::TocoFlags toco_flags;
38   // When exporting from SavedModel, this will have the requested tags.
39   std::unordered_set<std::string> saved_model_tags;
40   // Metadata key/value pairs to write to the flatbuffer.
41   std::map<std::string, std::string> metadata;
42   // OpOrArgNameMapper to convert location of the op to name in flatbuffer.
43   // If not set, a default mapper will be used.
44   tensorflow::OpOrArgNameMapper* op_or_arg_name_mapper = nullptr;
45 };
46 
47 // Translates the given MLIR `module` into a FlatBuffer and stores the
48 // serialized flatbuffer into the string.
49 // Returns true on successful exporting, false otherwise.
50 bool MlirToFlatBufferTranslateFunction(mlir::ModuleOp module,
51                                        const FlatbufferExportOptions& options,
52                                        std::string* serialized_flatbuffer);
53 }  // namespace tflite
54 
55 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_EXPORT_H_
56