From 19169d1388e164d533c0fe7e00b2ffdad8841e02 Mon Sep 17 00:00:00 2001 From: Seungho Henry Park Date: Fri, 13 Feb 2026 16:37:08 +0900 Subject: [PATCH] [compiler/tflchef] Introduce Sign operation This adds support for the Sign operation in tflchef. ONE-DCO-1.0-Signed-off-by: Seungho Henry Park --- compiler/tflchef/core/src/Op/Sign.cpp | 27 +++++++++++ compiler/tflchef/core/src/Op/Sign.h | 46 +++++++++++++++++++ compiler/tflchef/core/src/OpChef.def | 1 + compiler/tflchef/core/src/OpChefs.h | 1 + compiler/tflchef/tflite/src/Op/Sign.cpp | 40 ++++++++++++++++ compiler/tflchef/tflite/src/Op/include/Sign.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/Sign.cpp create mode 100644 compiler/tflchef/core/src/Op/Sign.h create mode 100644 compiler/tflchef/tflite/src/Op/Sign.cpp create mode 100644 compiler/tflchef/tflite/src/Op/include/Sign.h diff --git a/compiler/tflchef/core/src/Op/Sign.cpp b/compiler/tflchef/core/src/Op/Sign.cpp new file mode 100644 index 00000000000..7ec3b2b3784 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Sign.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2026 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 "Sign.h" + +flatbuffers::Offset SignChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset(); +} + +std::unique_ptr SignChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new SignChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Sign.h b/compiler/tflchef/core/src/Op/Sign.h new file mode 100644 index 00000000000..f3cfe4f8f8d --- /dev/null +++ b/compiler/tflchef/core/src/Op/Sign.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2026 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_SIGN_H__ +#define __OP_SIGN_H__ + +#include "OpChef.h" + +class SignChef final : public OpChef +{ +public: + explicit SignChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_SIGN; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_NONE; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct SignChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_SIGN_H__ diff --git a/compiler/tflchef/core/src/OpChef.def b/compiler/tflchef/core/src/OpChef.def index 8881451e879..e74c1211ccc 100644 --- a/compiler/tflchef/core/src/OpChef.def +++ b/compiler/tflchef/core/src/OpChef.def @@ -95,6 +95,7 @@ OP_CHEF(SegmentSum,SegmentSumChefFactory) OP_CHEF(Select, SelectChefFactory) OP_CHEF(SelectV2, SelectV2ChefFactory) OP_CHEF(Shape, ShapeChefFactory) +OP_CHEF(Sign, SignChefFactory) OP_CHEF(Sin, SinChefFactory) OP_CHEF(Slice, SliceChefFactory) OP_CHEF(Softmax, SoftmaxChefFactory) diff --git a/compiler/tflchef/core/src/OpChefs.h b/compiler/tflchef/core/src/OpChefs.h index 2c2b9be67a6..1e2598f513c 100644 --- a/compiler/tflchef/core/src/OpChefs.h +++ b/compiler/tflchef/core/src/OpChefs.h @@ -108,6 +108,7 @@ #include "Op/Select.h" #include "Op/SelectV2.h" #include "Op/Shape.h" +#include "Op/Sign.h" #include "Op/Sin.h" #include "Op/Slice.h" #include "Op/Softmax.h" diff --git a/compiler/tflchef/tflite/src/Op/Sign.cpp b/compiler/tflchef/tflite/src/Op/Sign.cpp new file mode 100644 index 00000000000..96ce4081636 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Sign.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2026 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 "Sign.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpSign::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpSign::build(RecipeChefContext *ctx) const +{ + tflchef::Operation *operation = ctx->chefop; + const tflite::Operator *op = ctx->tflop; + + operation->set_type("Sign"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/include/Sign.h b/compiler/tflchef/tflite/src/Op/include/Sign.h new file mode 100644 index 00000000000..827633543e4 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/include/Sign.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2026 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_SIGN_H__ +#define __TFLITE_OP_SIGN_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Sign + */ +class TFliteOpSign : 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_SIGN_H__ diff --git a/compiler/tflchef/tflite/src/TFliteOpChefs.h b/compiler/tflchef/tflite/src/TFliteOpChefs.h index 94e2ad25c26..ece52d3a633 100644 --- a/compiler/tflchef/tflite/src/TFliteOpChefs.h +++ b/compiler/tflchef/tflite/src/TFliteOpChefs.h @@ -107,6 +107,7 @@ #include "Op/include/Select.h" #include "Op/include/SelectV2.h" #include "Op/include/Shape.h" +#include "Op/include/Sign.h" #include "Op/include/Sin.h" #include "Op/include/Slice.h" #include "Op/include/Softmax.h" diff --git a/compiler/tflchef/tflite/src/TFliteOpRegistry.h b/compiler/tflchef/tflite/src/TFliteOpRegistry.h index 43d526d3427..2ce83cd4a83 100644 --- a/compiler/tflchef/tflite/src/TFliteOpRegistry.h +++ b/compiler/tflchef/tflite/src/TFliteOpRegistry.h @@ -144,6 +144,7 @@ class TFliteOpRegistry REG_TFL_OP(SELECT, TFliteOpSelect); REG_TFL_OP(SELECT_V2, TFliteOpSelectV2); REG_TFL_OP(SHAPE, TFliteOpShape); + REG_TFL_OP(SIGN, TFliteOpSign); REG_TFL_OP(SIN, TFliteOpSin); REG_TFL_OP(SLICE, TFliteOpSlice); REG_TFL_OP(SOFTMAX, TFliteOpSoftmax);