From 197ee4a3f3b40d064ba8ab89127f2e10831e185b Mon Sep 17 00:00:00 2001 From: Chunseok Lee Date: Thu, 29 Aug 2024 19:25:29 +0900 Subject: [PATCH] [onert-micro] Floor Common Helper - helper for floordiv and floormod ONE-DCO-1.0-Signed-off-by: Chunseok Lee --- .../include/import/helpers/OMFloorCommon.h | 38 ++++++++++ .../onert-micro/src/import/CMakeLists.txt | 1 + .../src/import/helpers/OMFloorCommon.cpp | 76 +++++++++++++++++++ .../src/import/kernels/FloorDiv.cpp | 49 +----------- .../src/import/kernels/FloorMod.cpp | 49 +----------- 5 files changed, 119 insertions(+), 94 deletions(-) create mode 100644 onert-micro/onert-micro/include/import/helpers/OMFloorCommon.h create mode 100644 onert-micro/onert-micro/src/import/helpers/OMFloorCommon.cpp diff --git a/onert-micro/onert-micro/include/import/helpers/OMFloorCommon.h b/onert-micro/onert-micro/include/import/helpers/OMFloorCommon.h new file mode 100644 index 00000000000..dcf72847e30 --- /dev/null +++ b/onert-micro/onert-micro/include/import/helpers/OMFloorCommon.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 ONERT_MICRO_IMPORT_HELPERS_CONFIGURE_FLOOR_KERNEL_COMMON_H +#define ONERT_MICRO_IMPORT_HELPERS_CONFIGURE_FLOOR_KERNEL_COMMON_H + +#include "import/OMKernelConfigureBuilder.h" +#include "core/OMUtils.h" +#include "OMStatus.h" +#include "execute/OMRuntimeKernel.h" + +namespace onert_micro +{ +namespace import +{ +namespace helpers +{ + +OMStatus configure_floor_kernel_common(const OMConfigureArgs &config_args); + +} // namespace helpers +} // namespace import +} // namespace onert_micro + +#endif // ONERT_MICRO_IMPORT_HELPERS_CONFIGURE_FLOOR_KERNEL_COMMON_H diff --git a/onert-micro/onert-micro/src/import/CMakeLists.txt b/onert-micro/onert-micro/src/import/CMakeLists.txt index e865ada32ff..5eebbde7a6a 100644 --- a/onert-micro/onert-micro/src/import/CMakeLists.txt +++ b/onert-micro/onert-micro/src/import/CMakeLists.txt @@ -11,6 +11,7 @@ set(SOURCES helpers/OMSpacesBatchesNDCommon.cpp helpers/OMPoolingCommon.cpp helpers/OMArgCommon.cpp + helpers/OMFloorCommon.cpp ) # Add configure kernels diff --git a/onert-micro/onert-micro/src/import/helpers/OMFloorCommon.cpp b/onert-micro/onert-micro/src/import/helpers/OMFloorCommon.cpp new file mode 100644 index 00000000000..134b43b5984 --- /dev/null +++ b/onert-micro/onert-micro/src/import/helpers/OMFloorCommon.cpp @@ -0,0 +1,76 @@ +/* + * 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 "import/helpers/OMFloorCommon.h" + +using namespace onert_micro; +using namespace onert_micro::core; + +namespace +{ + +constexpr uint32_t input1TensorIdx = 0; +constexpr uint32_t input2TensorIdx = 1; +constexpr uint32_t outputTensorIdx = 0; + +} // namespace + +OMStatus +onert_micro::import::helpers::configure_floor_kernel_common(const OMConfigureArgs &config_args) +{ + OMRuntimeContext &runtime_context = config_args.runtime_context; + uint16_t op_index = config_args.kernel_index; + + onert_micro::execute::OMRuntimeKernel runtime_kernel; + + OMStatus status = runtime_kernel.readKernel(op_index, runtime_context); + if (status != Ok) + return status; + + const circle::Tensor *input1 = runtime_kernel.inputs[input1TensorIdx]; + const circle::Tensor *input2 = runtime_kernel.inputs[input2TensorIdx]; + const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx]; + + assert(input1 != nullptr); + assert(input2 != nullptr); + assert(output != nullptr); + + status = utils::checkCondition(input1->type() == input2->type()); + if (status != Ok) + return status; + + status = utils::checkCondition(input1->type() == output->type()); + if (status != Ok) + return status; + + if (input1->type() != circle::TensorType_INT8 and input1->type() != circle::TensorType_INT16) + return status; + + // Check quantization params + if (input1->quantization() == nullptr or input2->quantization() == nullptr or + output->quantization() == nullptr) + { + return NoQuantization; + } + + if (input1->quantization()->scale()->size() != 1 or + input2->quantization()->scale()->size() != 1 or output->quantization()->scale()->size() != 1) + { + return UnsupportedType; + } + + return status; +} diff --git a/onert-micro/onert-micro/src/import/kernels/FloorDiv.cpp b/onert-micro/onert-micro/src/import/kernels/FloorDiv.cpp index a9529329ffa..67b7e074b0e 100644 --- a/onert-micro/onert-micro/src/import/kernels/FloorDiv.cpp +++ b/onert-micro/onert-micro/src/import/kernels/FloorDiv.cpp @@ -14,10 +14,7 @@ * limitations under the License. */ -#include "import/OMKernelConfigureBuilder.h" -#include "core/OMUtils.h" -#include "OMStatus.h" -#include "execute/OMRuntimeKernel.h" +#include "import/helpers/OMFloorCommon.h" using namespace onert_micro; using namespace onert_micro::core; @@ -33,47 +30,5 @@ constexpr uint32_t outputTensorIdx = 0; OMStatus onert_micro::import::configure_kernel_CircleFloorDiv(const OMConfigureArgs &config_args) { - - OMRuntimeContext &runtime_context = config_args.runtime_context; - uint16_t op_index = config_args.kernel_index; - - onert_micro::execute::OMRuntimeKernel runtime_kernel; - - OMStatus status = runtime_kernel.readKernel(op_index, runtime_context); - if (status != Ok) - return status; - - const circle::Tensor *input1 = runtime_kernel.inputs[input1TensorIdx]; - const circle::Tensor *input2 = runtime_kernel.inputs[input2TensorIdx]; - const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx]; - - assert(input1 != nullptr); - assert(input2 != nullptr); - assert(output != nullptr); - - status = utils::checkCondition(input1->type() == input2->type()); - if (status != Ok) - return status; - - status = utils::checkCondition(input1->type() == output->type()); - if (status != Ok) - return status; - - if (input1->type() != circle::TensorType_INT8 and input1->type() != circle::TensorType_INT16) - return status; - - // Check quantization params - if (input1->quantization() == nullptr or input2->quantization() == nullptr or - output->quantization() == nullptr) - { - return NoQuantization; - } - - if (input1->quantization()->scale()->size() != 1 or - input2->quantization()->scale()->size() != 1 or output->quantization()->scale()->size() != 1) - { - return UnsupportedType; - } - - return status; + return onert_micro::import::helpers::configure_floor_kernel_common(config_args); } diff --git a/onert-micro/onert-micro/src/import/kernels/FloorMod.cpp b/onert-micro/onert-micro/src/import/kernels/FloorMod.cpp index eb5a7687f0d..42bc54c1e83 100644 --- a/onert-micro/onert-micro/src/import/kernels/FloorMod.cpp +++ b/onert-micro/onert-micro/src/import/kernels/FloorMod.cpp @@ -14,10 +14,7 @@ * limitations under the License. */ -#include "import/OMKernelConfigureBuilder.h" -#include "core/OMUtils.h" -#include "OMStatus.h" -#include "execute/OMRuntimeKernel.h" +#include "import/helpers/OMFloorCommon.h" using namespace onert_micro; using namespace onert_micro::core; @@ -33,47 +30,5 @@ constexpr uint32_t outputTensorIdx = 0; OMStatus onert_micro::import::configure_kernel_CircleFloorMod(const OMConfigureArgs &config_args) { - - OMRuntimeContext &runtime_context = config_args.runtime_context; - uint16_t op_index = config_args.kernel_index; - - onert_micro::execute::OMRuntimeKernel runtime_kernel; - - OMStatus status = runtime_kernel.readKernel(op_index, runtime_context); - if (status != Ok) - return status; - - const circle::Tensor *input1 = runtime_kernel.inputs[input1TensorIdx]; - const circle::Tensor *input2 = runtime_kernel.inputs[input2TensorIdx]; - const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx]; - - assert(input1 != nullptr); - assert(input2 != nullptr); - assert(output != nullptr); - - status = utils::checkCondition(input1->type() == input2->type()); - if (status != Ok) - return status; - - status = utils::checkCondition(input1->type() == output->type()); - if (status != Ok) - return status; - - if (input1->type() != circle::TensorType_INT8 and input1->type() != circle::TensorType_INT16) - return status; - - // Check quantization params - if (input1->quantization() == nullptr or input2->quantization() == nullptr or - output->quantization() == nullptr) - { - return NoQuantization; - } - - if (input1->quantization()->scale()->size() != 1 or - input2->quantization()->scale()->size() != 1 or output->quantization()->scale()->size() != 1) - { - return UnsupportedType; - } - - return status; + return onert_micro::import::helpers::configure_floor_kernel_common(config_args); }