-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[onert-micro] Reduce Relu code duplication
This pr reduces code duplication for Relu. ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
- Loading branch information
Artem Balyshev
committed
Jun 26, 2024
1 parent
0a7eea9
commit 98f85b6
Showing
6 changed files
with
135 additions
and
155 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
onert-micro/onert-micro/include/execute/kernels/ReluCommon.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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_EXECUTE_KERNELS_RESHAPE_COMMON_H | ||
#define ONERT_MICRO_EXECUTE_KERNELS_RESHAPE_COMMON_H | ||
|
||
#include "OMStatus.h" | ||
#include "core/OMUtils.h" | ||
|
||
#include "execute/OMKernelExecutionBuilder.h" | ||
#include "execute/OMRuntimeKernel.h" | ||
|
||
namespace onert_micro | ||
{ | ||
namespace execute | ||
{ | ||
|
||
OMStatus execute_relu_common(const OMExecuteArgs &execute_args, bool is_relu_6); | ||
|
||
} // namespace execute | ||
} // namespace onert_micro | ||
|
||
#endif // ONERT_MICRO_EXECUTE_KERNELS_RESHAPE_COMMON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
onert-micro/onert-micro/src/execute/kernels/ReluCommon.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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 "execute/kernels/ReluCommon.h" | ||
#include "PALReluCommon.h" | ||
|
||
using namespace onert_micro; | ||
using namespace onert_micro::execute; | ||
|
||
namespace | ||
{ | ||
|
||
constexpr uint32_t inputTensorIdx = 0; | ||
constexpr uint32_t outputTensorIdx = 0; | ||
|
||
} // namespace | ||
|
||
// NOTE: doesnt currently support dynamic shapes | ||
OMStatus onert_micro::execute::execute_relu_common(const OMExecuteArgs &execute_args, | ||
bool is_relu_6) | ||
{ | ||
core::OMRuntimeContext &runtime_context = execute_args.runtime_context; | ||
core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage; | ||
uint16_t op_index = execute_args.kernel_index; | ||
|
||
const circle::Tensor *input = nullptr; | ||
const circle::Tensor *output = nullptr; | ||
|
||
uint8_t *input_data = nullptr; | ||
uint8_t *output_data = nullptr; | ||
|
||
OMStatus status = Ok; | ||
|
||
OMRuntimeKernel runtime_kernel; | ||
runtime_kernel.readKernel(op_index, runtime_context); | ||
|
||
input = runtime_kernel.inputs[inputTensorIdx]; | ||
output = runtime_kernel.outputs[outputTensorIdx]; | ||
|
||
assert(input != nullptr); | ||
assert(output != nullptr); | ||
|
||
status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context); | ||
if (status != Ok) | ||
return status; | ||
|
||
input_data = runtime_kernel.inputs_data[inputTensorIdx]; | ||
output_data = runtime_kernel.outputs_data[outputTensorIdx]; | ||
|
||
assert(input_data != nullptr); | ||
assert(output_data != nullptr); | ||
|
||
switch (input->type()) | ||
{ | ||
#ifndef DIS_FLOAT | ||
case circle::TensorType_FLOAT32: | ||
{ | ||
core::OMRuntimeShape input_shape(input); | ||
core::OMRuntimeShape output_shape(output); | ||
|
||
const auto *input_data_float = core::utils::castInputData<float>(input_data); | ||
auto *output_data_float = core::utils::castOutputData<float>(output_data); | ||
|
||
assert(output_data_float); | ||
const int flat_size = input_shape.flatSize(); | ||
|
||
status = pal::ReLUCommon(flat_size, input_data_float, output_data_float, 0.0f, is_relu_6); | ||
} | ||
break; | ||
#endif // DIS_FLOAT | ||
default: | ||
{ | ||
status = UnsupportedType; | ||
assert(false && "Unsupported type."); | ||
} | ||
} | ||
|
||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters