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 OMStatus status = Ok;
63
64 core::SplitParams params{};
65 {
66 execute::OMRuntimeKernel runtime_kernel;
67 status = runtime_kernel.readKernel(op_index, runtime_context);
68 if (status != Ok)
69 return status;
70
71 input = runtime_kernel.inputs[inputTensorIdx];
72 axis = runtime_kernel.inputs[axisTensorIdx];
73 output = runtime_kernel.outputs[outputTensorIdx];
74 assert(input != nullptr);
75 assert(axis != nullptr);
76 assert(output != nullptr);
77
78 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
79 if (status != Ok)
80 return status;
81
82 input_data = runtime_kernel.inputs_data[inputTensorIdx];
83 axis_data = runtime_kernel.inputs_data[axisTensorIdx];
84 assert(input_data != nullptr);
85 assert(axis_data != nullptr);
86 options = runtime_kernel.first_operator->builtin_options_as_SplitOptions();
87
88 params.num_outputs = options->num_splits();
89
90 for (uint32_t i = 0; i < params.num_outputs; ++i)
91 {
92 params.output_data[i] = runtime_kernel.outputs_data[i];
93 }
94 }
95
96 OMRuntimeShape axis_shape(axis);
97 OMRuntimeShape input_shape(input);
99
100 int32_t axis_value = utils::castInputData<int32_t>(axis_data)[0];
101 if (axis_value < 0)
102 {
103 axis_value += input_shape.dimensionsCount() + 1;
104 }
105
106 switch (input->type())
107 {
108#ifndef DIS_FLOAT
109 case circle::TensorType_FLOAT32:
110 status = pal::Split<float>(params, input_shape, core::utils::castInputData<float>(input_data),
111 output_shape, axis_value);
112 break;
113#endif // DIS_FLOAT
114#ifndef DIS_QUANT
115 case circle::TensorType_INT8:
116 {
117 status =
118 pal::Split<int8_t>(params, input_shape, core::utils::castInputData<int8_t>(input_data),
119 output_shape, axis_value);
120 }
121 break;
122#endif // DIS_QUANT
123 default:
124 {
125 status = UnsupportedType;
126 assert(false && "Unsupported type.");
127 }
128 }
129
130 return status;
131}
132
133} // namespace execute
134} // 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
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage