Skip to content

Commit

Permalink
[tflchef] Enable RELU_0_TO_1 (Samsung#12943)
Browse files Browse the repository at this point in the history
This will enable to chef RELU_0_TO_1 Op.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark authored Apr 30, 2024
1 parent a9d3ee7 commit 60cb9d1
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 0 deletions.
27 changes: 27 additions & 0 deletions compiler/tflchef/core/src/Op/ReLU0To1.cpp
Original file line number Diff line number Diff line change
@@ -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<void> ReLU0To1Chef::value(flatbuffers::FlatBufferBuilder &fbb) const
{
return flatbuffers::Offset<void>();
}

std::unique_ptr<OpChef> ReLU0To1ChefFactory::create(const tflchef::Operation *operation) const
{
return std::unique_ptr<OpChef>{new ReLU0To1Chef{operation}};
}
46 changes: 46 additions & 0 deletions compiler/tflchef/core/src/Op/ReLU0To1.h
Original file line number Diff line number Diff line change
@@ -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<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;

private:
const tflchef::Operation *_operation;
};

struct ReLU0To1ChefFactory final : public OpChefFactory
{
std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override;
};

#endif // __OP_RELU_0_TO_1_H__
1 change: 1 addition & 0 deletions compiler/tflchef/core/src/OpChef.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions compiler/tflchef/core/src/OpChefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 40 additions & 0 deletions compiler/tflchef/tflite/src/Op/ReLU0To1.cpp
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions compiler/tflchef/tflite/src/Op/include/ReLU0To1.h
Original file line number Diff line number Diff line change
@@ -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__
1 change: 1 addition & 0 deletions compiler/tflchef/tflite/src/TFliteOpChefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions compiler/tflchef/tflite/src/TFliteOpRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 60cb9d1

Please sign in to comment.