ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Concatenation.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 "core/OMUtils.h"
18#include "core/OMRuntimeShape.h"
19#include "core/OMKernelData.h"
20
21#include "execute/OMUtils.h"
24
25#include "OMStatus.h"
26#include "PALConcatenation.h"
27
28using namespace onert_micro;
29using namespace onert_micro::execute;
30
31namespace
32{
33
34constexpr uint32_t numOutput = 1;
35
36template <typename T> OMStatus evalGeneric(OMRuntimeKernel &runtime_kernel)
37{
38 auto output = runtime_kernel.outputs[0];
39
40 const auto *options = runtime_kernel.first_operator->builtin_options_as_ConcatenationOptions();
41
43
44 int axis = options->axis();
45 if (axis < 0)
47
48 const auto input_size = runtime_kernel.inputs_num;
49
50 std::vector<const T *> all_input_data(input_size);
51 std::vector<uint32_t> all_shape(input_size);
52
53 OMStatus status = Ok;
54 for (int32_t i = 0; i < input_size; ++i)
55 {
56 const auto *tensor = runtime_kernel.inputs[i];
57 core::OMRuntimeShape shape(tensor);
58
59 uint8_t *tensor_data = runtime_kernel.inputs_data[i];
60 all_input_data[i] = core::utils::castInputData<T>(tensor_data);
61 all_shape[i] = shape.dims(axis);
62 }
63
64 auto *output_data = core::utils::castOutputData<T>(runtime_kernel.outputs_data[0]);
65
67 params.axis = axis;
68 params.num_inputs = input_size;
69 status = pal::Concatenation<T>(params, all_shape, all_input_data, output_shape, output_data);
70
71 return status;
72}
73
74} // namespace
75
76namespace onert_micro
77{
78namespace execute
79{
80
82{
83 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
84 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
85 uint16_t op_index = execute_args.kernel_index;
86
87 execute::OMRuntimeKernel runtime_kernel;
88 runtime_kernel.readKernel(op_index, runtime_context);
89
90 const auto *t0 = runtime_kernel.inputs[0];
91 OMStatus status = Ok;
92
93 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
94
95 if (status != Ok)
96 return status;
97
98 switch (t0->type())
99 {
100#ifndef DIS_FLOAT
101 case circle::TensorType_FLOAT32:
102 status = evalGeneric<float>(runtime_kernel);
103 break;
104#endif // DIS_FLOAT
105#ifndef DIS_QUANT
106 case circle::TensorType_INT8:
107 status = evalGeneric<int8_t>(runtime_kernel);
108 break;
109#endif // DIS_QUANT
110 case circle::TensorType_INT32:
111 status = evalGeneric<int32_t>(runtime_kernel);
112 break;
113 case circle::TensorType_INT64:
114 status = evalGeneric<int64_t>(runtime_kernel);
115 break;
116 default:
117 assert(false && "Unsupported type.");
118 status = UnsupportedType;
119 }
120
121 return status;
122}
123
124} // namespace execute
125} // namespace onert_micro
int32_t dimensionsCount() const
Definition Tensor.h:106
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
OMStatus execute_kernel_CircleConcatenation(const OMExecuteArgs &execute_args)
@ UnsupportedType
Definition OMStatus.h:26
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage