From 60cb9d16308162d76e645b29d2308c617eb7d168 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Tue, 30 Apr 2024 17:23:28 +0900 Subject: [PATCH] [tflchef] Enable RELU_0_TO_1 (#12943) This will enable to chef RELU_0_TO_1 Op. ONE-DCO-1.0-Signed-off-by: SaeHie Park --- compiler/tflchef/core/src/Op/ReLU0To1.cpp | 27 +++++++++++ compiler/tflchef/core/src/Op/ReLU0To1.h | 46 +++++++++++++++++++ compiler/tflchef/core/src/OpChef.def | 1 + compiler/tflchef/core/src/OpChefs.h | 1 + compiler/tflchef/tflite/src/Op/ReLU0To1.cpp | 40 ++++++++++++++++ .../tflchef/tflite/src/Op/include/ReLU0To1.h | 38 +++++++++++++++ compiler/tflchef/tflite/src/TFliteOpChefs.h | 1 + .../tflchef/tflite/src/TFliteOpRegistry.h | 1 + 8 files changed, 155 insertions(+) create mode 100644 compiler/tflchef/core/src/Op/ReLU0To1.cpp create mode 100644 compiler/tflchef/core/src/Op/ReLU0To1.h create mode 100644 compiler/tflchef/tflite/src/Op/ReLU0To1.cpp create mode 100644 compiler/tflchef/tflite/src/Op/include/ReLU0To1.h diff --git a/compiler/tflchef/core/src/Op/ReLU0To1.cpp b/compiler/tflchef/core/src/Op/ReLU0To1.cpp new file mode 100644 index 00000000000..417642700c2 --- /dev/null +++ b/compiler/tflchef/core/src/Op/ReLU0To1.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. 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. + */ + +#include "ReLU0To1.h" + +flatbuffers::Offset ReLU0To1Chef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset(); +} + +std::unique_ptr ReLU0To1ChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new ReLU0To1Chef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/ReLU0To1.h b/compiler/tflchef/core/src/Op/ReLU0To1.h new file mode 100644 index 00000000000..dc93710cb4d --- /dev/null +++ b/compiler/tflchef/core/src/Op/ReLU0To1.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. 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 __OP_RELU_0_TO_1_H__ +#define __OP_RELU_0_TO_1_H__ + +#include "OpChef.h" + +class ReLU0To1Chef final : public OpChef +{ +public: + explicit ReLU0To1Chef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_RELU_0_TO_1; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_NONE; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct ReLU0To1ChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_RELU_0_TO_1_H__ diff --git a/compiler/tflchef/core/src/OpChef.def b/compiler/tflchef/core/src/OpChef.def index 4a09c3112ce..8881451e879 100644 --- a/compiler/tflchef/core/src/OpChef.def +++ b/compiler/tflchef/core/src/OpChef.def @@ -80,6 +80,7 @@ OP_CHEF(ReduceMax, ReduceMaxChefFactory) OP_CHEF(ReduceMin, ReduceMinChefFactory) OP_CHEF(ReduceProd, ReduceProdChefFactory) OP_CHEF(ReLU, ReLUChefFactory) +OP_CHEF(ReLU0To1, ReLU0To1ChefFactory) OP_CHEF(ReLU6, ReLU6ChefFactory) OP_CHEF(ReLUN1To1, ReLUN1To1ChefFactory) OP_CHEF(Reshape, ReshapeChefFactory) diff --git a/compiler/tflchef/core/src/OpChefs.h b/compiler/tflchef/core/src/OpChefs.h index c62e5f8e562..2c2b9be67a6 100644 --- a/compiler/tflchef/core/src/OpChefs.h +++ b/compiler/tflchef/core/src/OpChefs.h @@ -92,6 +92,7 @@ #include "Op/ReduceMin.h" #include "Op/ReduceProd.h" #include "Op/ReLU.h" +#include "Op/ReLU0To1.h" #include "Op/ReLU6.h" #include "Op/ReLUN1To1.h" #include "Op/Reshape.h" diff --git a/compiler/tflchef/tflite/src/Op/ReLU0To1.cpp b/compiler/tflchef/tflite/src/Op/ReLU0To1.cpp new file mode 100644 index 00000000000..e5353c39860 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/ReLU0To1.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. 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. + */ + +#include "ReLU0To1.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpReLU0To1::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpReLU0To1::build(RecipeChefContext *ctx) const +{ + tflchef::Operation *operation = ctx->chefop; + const tflite::Operator *op = ctx->tflop; + + operation->set_type("ReLU0To1"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/include/ReLU0To1.h b/compiler/tflchef/tflite/src/Op/include/ReLU0To1.h new file mode 100644 index 00000000000..6543f322a5a --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/include/ReLU0To1.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. 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 __TFLITE_OP_RELU_0_TO_1_H__ +#define __TFLITE_OP_RELU_0_TO_1_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for RELU_0_TO_1 + */ +class TFliteOpReLU0To1 : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(RecipeChefContext *ctx) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_RELU_0_TO_1_H__ diff --git a/compiler/tflchef/tflite/src/TFliteOpChefs.h b/compiler/tflchef/tflite/src/TFliteOpChefs.h index 409dd39f984..94e2ad25c26 100644 --- a/compiler/tflchef/tflite/src/TFliteOpChefs.h +++ b/compiler/tflchef/tflite/src/TFliteOpChefs.h @@ -92,6 +92,7 @@ #include "Op/include/ReduceMin.h" #include "Op/include/ReduceProd.h" #include "Op/include/ReLU.h" +#include "Op/include/ReLU0To1.h" #include "Op/include/ReLU6.h" #include "Op/include/ReLUN1To1.h" #include "Op/include/Reshape.h" diff --git a/compiler/tflchef/tflite/src/TFliteOpRegistry.h b/compiler/tflchef/tflite/src/TFliteOpRegistry.h index 3679248bb98..43d526d3427 100644 --- a/compiler/tflchef/tflite/src/TFliteOpRegistry.h +++ b/compiler/tflchef/tflite/src/TFliteOpRegistry.h @@ -129,6 +129,7 @@ class TFliteOpRegistry REG_TFL_OP(REDUCE_MIN, TFliteOpReduceMin); REG_TFL_OP(REDUCE_PROD, TFliteOpReduceProd); REG_TFL_OP(RELU, TFliteOpReLU); + REG_TFL_OP(RELU_0_TO_1, TFliteOpReLU0To1); REG_TFL_OP(RELU6, TFliteOpReLU6); REG_TFL_OP(RELU_N1_TO_1, TFliteOpReLUN1To1); REG_TFL_OP(RESHAPE, TFliteOpReshape);