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/IR/BuiltinOps.h" // from @llvm-project 24 #include "tensorflow/compiler/mlir/op_or_arg_name_mapper.h" 25 26 namespace tflite { 27 // Options for exporting to Flatbuffer. 28 struct FlatbufferExportOptions { 29 bool emit_builtin_tflite_ops = false; 30 bool emit_select_tf_ops = false; 31 bool emit_custom_ops = false; 32 // When exporting from SavedModel, this will have the requested tags. 33 std::unordered_set<std::string> saved_model_tags; 34 // TF custom op passed by the user. 35 std::unordered_set<std::string> select_user_tf_ops; 36 // Metadata key/value pairs to write to the flatbuffer. 37 std::map<std::string, std::string> metadata; 38 // OpOrArgNameMapper to convert location of the op to name in flatbuffer. 39 // If not set, a default mapper will be used. 40 tensorflow::OpOrArgNameMapper* op_or_arg_name_mapper = nullptr; 41 // If set to true, then allow pass through of TF ops as select Tensorflow ops. 42 bool allow_all_select_tf_ops = false; 43 }; 44 45 // Translates the given MLIR `module` into a FlatBuffer and stores the 46 // serialized flatbuffer into the string. 47 // Returns true on successful exporting, false otherwise. 48 bool MlirToFlatBufferTranslateFunction(mlir::ModuleOp module, 49 const FlatbufferExportOptions& options, 50 std::string* serialized_flatbuffer); 51 } // namespace tflite 52 53 #endif // TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_EXPORT_H_ 54