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