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
37OMStatus onert_micro::execute::execute_kernel_CircleElu(const OMExecuteArgs &execute_args)
38{
39 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
40 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
41 uint16_t op_index = execute_args.kernel_index;
42
43 const circle::Tensor *input = nullptr;
44 const circle::Tensor *output = nullptr;
45
46 uint8_t *input_data = nullptr;
47 uint8_t *output_data = nullptr;
48
49 OMStatus status = Ok;
50
51 OMRuntimeKernel runtime_kernel;
52 runtime_kernel.readKernel(op_index, runtime_context);
53
54 input = runtime_kernel.inputs[inputTensorIdx];
55 output = runtime_kernel.outputs[outputTensorIdx];
56
57 assert(input != nullptr);
58 assert(output != nullptr);
59
60 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
61 if (status != Ok)
62 return status;
63
64 input_data = runtime_kernel.inputs_data[inputTensorIdx];
66
67 assert(input_data != nullptr);
68 assert(output_data != nullptr);
69
70 switch (input->type())
71 {
72#ifndef DIS_FLOAT
73 case circle::TensorType_FLOAT32:
74 {
75 core::OMRuntimeShape input_shape(input);
77
78 const auto *input_data_float = core::utils::castInputData<float>(input_data);
79 auto *output_data_float = core::utils::castOutputData<float>(output_data);
80
81 assert(output_data_float);
82 const int flat_size = input_shape.flatSize();
83
84 status = pal::Elu(flat_size, input_data_float, output_data_float);
85 }
86 break;
87#endif // DIS_FLOAT
88 default:
89 {
90 status = UnsupportedType;
91 assert(false && "Unsupported type.");
92 break;
93 }
94 }
95
96 return status;
97}
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
list input_data
Definition infer.py:29
OMStatus Elu(const int flat_size, const float *input_data, float *output_data)
Definition PALElu.h:32
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage