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