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