ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Split.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
19#include "core/OMUtils.h"
20#include "core/OMKernelData.h"
21
23#include "execute/OMUtils.h"
25
26#include "PALSplit.h"
27
28using namespace onert_micro;
29using namespace onert_micro::core;
30using namespace onert_micro::execute;
31
32namespace
33{
34
35constexpr uint32_t axisTensorIdx = 0;
36constexpr uint32_t inputTensorIdx = 1;
37constexpr uint32_t outputTensorIdx = 0;
38
39} // namespace
40
41namespace onert_micro
42{
43namespace execute
44{
45
47{
48 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
49 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
50 uint16_t op_index = execute_args.kernel_index;
51
52 const circle::Tensor *input;
53 const circle::Tensor *axis;
54 const circle::Tensor *output;
55
56 uint8_t *input_data;
57 uint8_t *axis_data;
58
59 // Read kernel
60 const circle::SplitOptions *options;
61
62 core::SplitParams params{};
63 {
64 execute::OMRuntimeKernel runtime_kernel;
65 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
66 if (status != Ok)
67 return status;
68
69 input = runtime_kernel.inputs[inputTensorIdx];
70 axis = runtime_kernel.inputs[axisTensorIdx];
71 output = runtime_kernel.outputs[outputTensorIdx];
72 assert(input != nullptr);
73 assert(axis != nullptr);
74 assert(output != nullptr);
75
76 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
77 if (status != Ok)
78 return status;
79
80 input_data = runtime_kernel.inputs_data[inputTensorIdx];
81 axis_data = runtime_kernel.inputs_data[axisTensorIdx];
82 assert(input_data != nullptr);
83 assert(axis_data != nullptr);
84 options = runtime_kernel.first_operator->builtin_options_as_SplitOptions();
85
86 params.num_outputs = options->num_splits();
87
88 for (uint32_t i = 0; i < params.num_outputs; ++i)
89 {
90 params.output_data[i] = runtime_kernel.outputs_data[i];
91 }
92 }
93 OMStatus status;
94 OMRuntimeShape axis_shape(axis);
95 OMRuntimeShape input_shape(input);
97
98 int32_t axis_value = utils::castInputData<int32_t>(axis_data)[0];
99 if (axis_value < 0)
100 {
101 axis_value += input_shape.dimensionsCount() + 1;
102 }
103
104 switch (input->type())
105 {
106#ifndef DIS_FLOAT
107 case circle::TensorType_FLOAT32:
108 status = pal::Split<float>(params, input_shape, core::utils::castInputData<float>(input_data),
109 output_shape, axis_value);
110 break;
111#endif // DIS_FLOAT
112#ifndef DIS_QUANT
113 case circle::TensorType_INT8:
114 {
115 status =
116 pal::Split<int8_t>(params, input_shape, core::utils::castInputData<int8_t>(input_data),
117 output_shape, axis_value);
118 }
119 break;
120#endif // DIS_QUANT
121 default:
122 {
123 status = UnsupportedActivation;
124 assert(false && "Unsupported type.");
125 }
126 }
127
128 return status;
129}
130
131} // namespace execute
132} // namespace onert_micro
size_t dimensionsCount() const noexcept
uint8_t * outputs_data[maxOutputSize]
const circle::Operator * first_operator
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 execute_kernel_CircleSplit(const OMExecuteArgs &execute_args)
Definition Split.cpp:46
@ UnsupportedActivation
Definition OMStatus.h:28
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage