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"
22
23using namespace onert_micro;
24using namespace onert_micro::core;
25
26namespace
27{
28
29constexpr uint32_t inputTensorIdx = 0;
30constexpr uint32_t outputTensorIdx = 0;
31
32} // namespace
33
34namespace onert_micro
35{
36namespace import
37{
38
40{
41 OMRuntimeContext &runtime_context = config_args.runtime_context;
42 OMRuntimeStorage &runtime_storage = config_args.runtime_storage;
43 uint16_t op_index = config_args.kernel_index;
44
46
47 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
48 if (status != Ok)
49 return status;
50
51 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
52 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
53
54 assert(input != nullptr);
55 assert(output != nullptr);
56
57 status = utils::checkCondition(output->type() == input->type());
58 if (status != Ok)
59 return status;
60
61 auto options = runtime_kernel.first_operator->builtin_options_as_UnpackOptions();
62 status = utils::checkCondition(options != nullptr);
63 if (status != Ok)
64 return status;
65
66 status = utils::checkCondition(runtime_kernel.outputs_num == options->num());
67 if (status != Ok)
68 return status;
69
70 // Check all outputs have the same type and shapes
72 for (uint32_t i = 1; i < options->num(); ++i)
73 {
74 const circle::Tensor *cur_output = runtime_kernel.outputs[i];
75 status = utils::checkCondition(output->type() == cur_output->type());
76 if (status != Ok)
77 return status;
78
79 OMRuntimeShape cur_output_shape(cur_output);
80 status = utils::checkCondition(output_shape == cur_output_shape);
81 if (status != Ok)
82 return status;
83 }
84
85 // Check shapes input and output
86 OMRuntimeShape input_shape(input);
87 for (int i = 0; i < input_shape.dimensionsCount(); ++i)
88 {
89 if (i == options->axis())
90 continue;
91
92 if (i < options->axis())
93 {
94 status = utils::checkCondition(input_shape.dims(i) == output_shape.dims(i));
95 }
96 else
97 {
98 status = utils::checkCondition(input_shape.dims(i) == output_shape.dims(i - 1));
99 }
100 if (status != Ok)
101 return status;
102 }
103
104 return status;
105}
106
107} // namespace import
108} // namespace onert_micro
int32_t dims(int i) const
Definition Tensor.h:108
size_t dimensionsCount() const noexcept
const circle::Operator * first_operator
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 configure_kernel_CircleUnpack(const OMConfigureArgs &config_args)
Definition Unpack.cpp:39
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage