ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Elu.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "OMStatus.h"
18#include "core/OMUtils.h"
19
22
23#include "PALElu.h"
24
25using namespace onert_micro;
26using namespace onert_micro::execute;
27
28namespace
29{
30
31constexpr uint32_t inputTensorIdx = 0;
32constexpr uint32_t outputTensorIdx = 0;
33
34} // namespace
35
36// NOTE: doesnt currently support dynamic shapes
37namespace onert_micro
38{
39namespace execute
40{
41
43{
44 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
45 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
46 uint16_t op_index = execute_args.kernel_index;
47
48 const circle::Tensor *input = nullptr;
49 const circle::Tensor *output = nullptr;
50
51 uint8_t *input_data = nullptr;
52 uint8_t *output_data = nullptr;
53
54 OMStatus status = Ok;
55
56 OMRuntimeKernel runtime_kernel;
57 runtime_kernel.readKernel(op_index, runtime_context);
58
59 input = runtime_kernel.inputs[inputTensorIdx];
60 output = runtime_kernel.outputs[outputTensorIdx];
61
62 assert(input != nullptr);
63 assert(output != nullptr);
64
65 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
66 if (status != Ok)
67 return status;
68
69 input_data = runtime_kernel.inputs_data[inputTensorIdx];
70 output_data = runtime_kernel.outputs_data[outputTensorIdx];
71
72 assert(input_data != nullptr);
73 assert(output_data != nullptr);
74
75 switch (input->type())
76 {
77#ifndef DIS_FLOAT
78 case circle::TensorType_FLOAT32:
79 {
80 core::OMRuntimeShape input_shape(input);
82
83 const auto *input_data_float = core::utils::castInputData<float>(input_data);
84 auto *output_data_float = core::utils::castOutputData<float>(output_data);
85
86 assert(output_data_float);
87 const int flat_size = input_shape.flatSize();
88
89 status = pal::Elu(flat_size, input_data_float, output_data_float);
90 }
91 break;
92#endif // DIS_FLOAT
93 default:
94 {
95 status = UnsupportedType;
96 assert(false && "Unsupported type.");
97 break;
98 }
99 }
100
101 return status;
102}
103
104} // namespace execute
105} // namespace onert_micro
uint8_t * outputs_data[maxOutputSize]
OMStatus getDataFromStorage(uint16_t op_index, core::OMRuntimeStorage &storage, core::OMRuntimeContext &context)
OMStatus readKernel(uint16_t op_index, core::OMRuntimeContext &runtime_context)
const circle::Tensor * outputs[maxOutputSize]
const circle::Tensor * inputs[maxInputSize]
const luci_interpreter::RuntimeShape output_shape
constexpr uint32_t outputTensorIdx
OMStatus Elu(const int flat_size, const float *input_data, float *output_data)
Definition PALElu.h:32
OMStatus execute_kernel_CircleElu(const OMExecuteArgs &execute_args)
Definition Elu.cpp:42
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage