Skip to content

Commit

Permalink
[onert-micro] Floor Common Helper (#13843)
Browse files Browse the repository at this point in the history
- helper for floordiv and floormod

ONE-DCO-1.0-Signed-off-by: Chunseok Lee <[email protected]>
  • Loading branch information
chunseoklee authored Aug 30, 2024
1 parent d6c85fb commit 2624ca2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 94 deletions.
38 changes: 38 additions & 0 deletions onert-micro/onert-micro/include/import/helpers/OMFloorCommon.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 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
1 change: 1 addition & 0 deletions onert-micro/onert-micro/src/import/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(SOURCES
helpers/OMSpacesBatchesNDCommon.cpp
helpers/OMPoolingCommon.cpp
helpers/OMArgCommon.cpp
helpers/OMFloorCommon.cpp
)

# Add configure kernels
Expand Down
76 changes: 76 additions & 0 deletions onert-micro/onert-micro/src/import/helpers/OMFloorCommon.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
49 changes: 2 additions & 47 deletions onert-micro/onert-micro/src/import/kernels/FloorDiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
49 changes: 2 additions & 47 deletions onert-micro/onert-micro/src/import/kernels/FloorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

0 comments on commit 2624ca2

Please sign in to comment.