STT-tensorflow/tensorflow/compiler/mlir/lite/flatbuffer_import.h
Abdurrahman Akkas 8502c9e5c8 Adding input-arrays flag to to MLIR flatbuffer importer.
Experimental pruning flag now prunes the ops that come before the new input tensors. input-arrays flag requires the usage of pruning since it is unclear what should happen to these ops if they are not pruned.

Rearranged tflite::FlatBufferToMlir interface to put these flags together and gave them optional values.

Also, moving output-arrays flag from flatbuffer_translate.cc to flatbuffer_import.cc, since it only relates to flatbuffer_import.

PiperOrigin-RevId: 297006319
Change-Id: Ia4557bf0cb0a44c964f5bf732bdbb76b5bef917d
2020-02-24 17:21:46 -08:00

45 lines
2.1 KiB
C++

/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_IMPORT_H_
#define TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_IMPORT_H_
#include "absl/strings/string_view.h"
#include "mlir/IR/Location.h" // TF:llvm-project
#include "mlir/IR/MLIRContext.h" // TF:llvm-project
#include "mlir/IR/Module.h" // TF:llvm-project
namespace tflite {
// Converts a TFLite flatbuffer stored in `buffer` to a MLIR module
// The buffer must live for the duration of the function call,
// The caller receives ownership of the module.
// `base_loc` is used for error reporting and debug info.
// If ordered_output_arrays is not empty, then the imported mlir function will
// only return nodes in ordered_output_arrays in the same order. Returns nullptr
// on failure, and more specific errors will be emitted via the context.
// If `use_external_constant` is true, it will create `tfl.external_const`
// instead of `tfl.const`.
// If `experimental_prune_unreachable_nodes_unconditionally` is true, nodes that
// are not ancestors of the output nodes will be pruned.
mlir::OwningModuleRef FlatBufferToMlir(
absl::string_view buffer, mlir::MLIRContext* context,
mlir::Location base_loc, bool use_external_constant = false,
const std::vector<std::string>& ordered_input_arrays = {},
const std::vector<std::string>& ordered_output_arrays = {},
bool experimental_prune_unreachable_nodes_unconditionally = false);
} // namespace tflite
#endif // TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_IMPORT_H_