• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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 #ifndef TENSORFLOW_COMPILER_MLIR_LITE_PYTHON_TF_TFL_FLATBUFFER_HELPERS_H_
16 #define TENSORFLOW_COMPILER_MLIR_LITE_PYTHON_TF_TFL_FLATBUFFER_HELPERS_H_
17 
18 #include <ostream>
19 #include <unordered_set>
20 #include <utility>
21 
22 #include "llvm/ADT/Optional.h"
23 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
24 #include "tensorflow/compiler/mlir/lite/common/tfl_pass_config.h"
25 #include "tensorflow/compiler/mlir/lite/transforms/passes.h"
26 #include "tensorflow/core/public/session.h"
27 #include "tensorflow/lite/toco/model_flags.pb.h"
28 #include "tensorflow/lite/toco/toco_flags.pb.h"
29 #include "tensorflow/lite/toco/types.pb.h"
30 #include "tensorflow/stream_executor/lib/statusor.h"
31 
32 namespace tensorflow {
33 namespace internal {
34 
35 // Register all custom ops including user specified custom ops.
36 Status RegisterAllCustomOps(const toco::TocoFlags& toco_flags);
37 
38 // Populate quantization specs (or not) given user specified ranges for each
39 // input arrays.
40 Status PopulateQuantizationSpecs(
41     const toco::ModelFlags& model_flags, const toco::TocoFlags& toco_flags,
42     mlir::TFL::QuantizationSpecs* quant_specs, std::vector<string>* node_names,
43     std::vector<string>* node_dtypes,
44     std::vector<llvm::Optional<std::vector<int>>>* node_shapes,
45     std::vector<llvm::Optional<double>>* node_mins,
46     std::vector<llvm::Optional<double>>* node_maxs);
47 
48 // Convert imported MLIR file to TfLite flatbuffer.
49 // This will also run relevant passes as well.
50 Status ConvertMLIRToTFLiteFlatBuffer(
51     const toco::TocoFlags& toco_flags, mlir::OwningModuleRef module,
52     const mlir::TFL::PassConfig& pass_config,
53     const std::unordered_set<std::string>& saved_model_tags, string* result,
54     llvm::Optional<tensorflow::Session*> session);
55 
56 // Give a warning for any unused flags that have been specified.
57 void WarningUnusedFlags(const toco::ModelFlags& model_flags,
58                         const toco::TocoFlags& toco_flags);
59 }  // namespace internal
60 }  // namespace tensorflow
61 
62 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_PYTHON_TF_TFL_FLATBUFFER_HELPERS_H_
63