ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
35OMStatus onert_micro::import::configure_kernel_CircleReshape(const OMConfigureArgs &config_args)
36{
37 OMRuntimeContext &runtime_context = config_args.runtime_context;
38 uint16_t op_index = config_args.kernel_index;
39 OMRuntimeStorage &runtime_storage = config_args.runtime_storage;
40
42
43 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
44 if (status != Ok)
45 return status;
46
47 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
48 const circle::Tensor *shape = runtime_kernel.inputs[shapeTensorIdx];
49 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
50
51 assert(input != nullptr);
52 assert(shape != nullptr);
53 assert(output != nullptr);
54
55 status = utils::checkCondition(input->type() == output->type());
56 if (status != Ok)
57 return status;
58
59 OMRuntimeShape input_shape(input);
61
62#ifndef DIS_DYN_SHAPES
63 auto is_dynamic =
64 runtime_context.isConstTensor(runtime_kernel.inputs_index[shapeTensorIdx]) == false;
65
66 if (is_dynamic)
67 {
68 auto input_shape_size = input_shape.flatSize();
69
70 status = utils::checkCondition(output_shape.flatSize() == 1);
71 if (status != Ok)
72 return status;
73
74 status = utils::checkCondition(input_shape_size != 1);
75 if (status != Ok)
76 return status;
77
78 runtime_storage.setDynamicRuntimeShape(runtime_kernel.outputs_index[outputTensorIdx],
79 input_shape);
80 }
81 else
82 {
83 status = utils::checkCondition(input_shape.flatSize() == output_shape.flatSize());
84 assert(status == Ok);
85 if (status != Ok)
86 return status;
87 }
88#else
89 status = utils::checkCondition(
90 runtime_context.getCircleReader().isConstTensor(runtime_kernel.inputs_index[shapeTensorIdx]));
91 assert(status == Ok);
92 if (status != Ok)
93 return status;
94#endif // DIS_DYN_SHAPES
95
96 return status;
97}
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