1 /* Copyright 2021 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_EXPERIMENTAL_TAC_TRANSFORMS_DEVICE_TRANSFORM_H_
17 #define TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_TAC_TRANSFORMS_DEVICE_TRANSFORM_H_
18 
19 #include <string>
20 
21 #include "mlir/Dialect/Func/IR/FuncOps.h"  // from @llvm-project
22 #include "mlir/IR/MLIRContext.h"  // from @llvm-project
23 #include "mlir/IR/PatternMatch.h"  // from @llvm-project
24 #include "tensorflow/compiler/mlir/lite/experimental/tac/common/targets.h"
25 #include "tensorflow/compiler/mlir/lite/ir/tfl_ops.h"
26 
27 namespace mlir {
28 namespace TFL {
29 namespace tac {
30 
31 // Returns true if 'op' is supported to run on 'hardware'.
32 bool IsSupported(Operation* op, const std::string& hardware);
33 
34 // Return proper rewriter patterns for different hardwares.
35 RewritePatternSet GetHardwareRewritePatterns(MLIRContext* context,
36                                              const std::string& hardware);
37 
38 // Convert quantized ops to float, this will essentially insert dequantize &
39 // quantize pair around the op.
40 void ConvertQuantizedOpToFloat(func::FuncOp func, OpBuilder* builder);
41 
42 // This will optimize the quantized ops -> float graph.
43 void OptimizeQuantizedOpToFloat(func::FuncOp func, MLIRContext* context);
44 
45 }  // namespace tac
46 }  // namespace TFL
47 }  // namespace mlir
48 
49 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_TAC_TRANSFORMS_DEVICE_TRANSFORM_H_
50