ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Reshape.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 shapeTensorIdx = 1;
31constexpr uint32_t outputTensorIdx = 0;
32
33} // namespace
34
35namespace onert_micro
36{
37namespace import
38{
39
41{
42 OMRuntimeContext &runtime_context = config_args.runtime_context;
43 uint16_t op_index = config_args.kernel_index;
44 OMRuntimeStorage &runtime_storage = config_args.runtime_storage;
45
47
48 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
49 if (status != Ok)
50 return status;
51
52 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
53 const circle::Tensor *shape = runtime_kernel.inputs[shapeTensorIdx];
54 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
55
56 assert(input != nullptr);
57 assert(shape != nullptr);
58 assert(output != nullptr);
59
60 status = utils::checkCondition(input->type() == output->type());
61 if (status != Ok)
62 return status;
63
64 OMRuntimeShape input_shape(input);
66
67#ifndef DIS_DYN_SHAPES
68 auto is_dynamic =
69 runtime_context.isConstTensor(runtime_kernel.inputs_index[shapeTensorIdx]) == false;
70
71 if (is_dynamic)
72 {
73 auto input_shape_size = input_shape.flatSize();
74
75 status = utils::checkCondition(output_shape.flatSize() == 1);
76 if (status != Ok)
77 return status;
78
79 status = utils::checkCondition(input_shape_size != 1);
80 if (status != Ok)
81 return status;
82
83 runtime_storage.setDynamicRuntimeShape(runtime_kernel.outputs_index[outputTensorIdx],
84 input_shape);
85 }
86 else
87 {
88 status = utils::checkCondition(input_shape.flatSize() == output_shape.flatSize());
89 assert(status == Ok);
90 if (status != Ok)
91 return status;
92 }
93#else
94 status = utils::checkCondition(
95 runtime_context.getCircleReader().isConstTensor(runtime_kernel.inputs_index[shapeTensorIdx]));
96 assert(status == Ok);
97 if (status != Ok)
98 return status;
99#endif // DIS_DYN_SHAPES
100
101 return status;
102}
103
104} // namespace import
105} // namespace onert_micro
bool isConstTensor(uint32_t tensor_index)
OMStatus setDynamicRuntimeShape(uint16_t tensor_index, const OMRuntimeShape &shape)
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_CircleReshape(const OMConfigureArgs &config_args)
Definition Reshape.cpp:40
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage