xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/mlir/lite/utils/perception_ops_utils.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 
16 #ifndef TENSORFLOW_COMPILER_MLIR_LITE_UTILS_PERCEPTION_OPS_UTILS_H_
17 #define TENSORFLOW_COMPILER_MLIR_LITE_UTILS_PERCEPTION_OPS_UTILS_H_
18 
19 #include <string>
20 
21 #include "mlir/Dialect/Func/IR/FuncOps.h"  // from @llvm-project
22 #include "mlir/IR/Attributes.h"  // from @llvm-project
23 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
24 #include "mlir/Support/LogicalResult.h"  // from @llvm-project
25 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_attributes.h"
26 
27 namespace mlir {
28 namespace TFL {
29 
30 // Fuse MaxUnpooling2D ops annotated by tf.function to a TFLite custom op.
31 class ConvertMaxUnpoolingFunc {
32  public:
ConvertMaxUnpoolingFunc(func::FuncOp func,mlir::TF::FuncAttr attr)33   explicit ConvertMaxUnpoolingFunc(func::FuncOp func, mlir::TF::FuncAttr attr)
34       : func_(func), attr_(attr) {}
35 
36   LogicalResult RewriteFunc();
37 
38   LogicalResult VerifySignature();
39 
40  private:
41   LogicalResult CreateCustomOptions(std::string& custom_option_buffer);
42 
43   func::FuncOp func_;
44   mlir::TF::FuncAttr attr_;
45 };
46 
47 // Fuse DenseImageWarp ops annotated by tf.function to a TFLite custom op.
48 class ConvertDenseImageWarpFunc {
49  public:
ConvertDenseImageWarpFunc(func::FuncOp func)50   explicit ConvertDenseImageWarpFunc(func::FuncOp func) : func_(func) {}
51 
52   LogicalResult RewriteFunc();
53 
54   LogicalResult VerifySignature();
55 
56  private:
57   func::FuncOp func_;
58 };
59 
60 }  // end namespace TFL
61 }  // end namespace mlir
62 
63 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_UTILS_PERCEPTION_OPS_UTILS_H_
64