ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SpaceToDepth.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
18#include "core/OMUtils.h"
19#include "OMStatus.h"
21
22using namespace onert_micro;
23using namespace onert_micro::core;
24
25namespace
26{
27
28constexpr uint32_t inputTensorIdx = 0;
29constexpr uint32_t outputTensorIdx = 0;
30
31} // namespace
32
33namespace onert_micro
34{
35namespace import
36{
37
40{
41 OMRuntimeContext &runtime_context = config_args.runtime_context;
42 uint16_t op_index = config_args.kernel_index;
43
45
46 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
47 if (status != Ok)
48 return status;
49
50 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
51 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
52
53 assert(input != nullptr);
54 assert(output != nullptr);
55
56 status = utils::checkCondition(input->type() == output->type());
57 if (status != Ok)
58 return status;
59
60 OMRuntimeShape input_shape(input);
62
63 const auto *options = runtime_kernel.first_operator->builtin_options_as_SpaceToDepthOptions();
64 const int32_t block_size = options->block_size();
65
66 status = utils::checkCondition(block_size > 0);
67 if (status != Ok)
68 return status;
69
70 constexpr int kHeightRank = 1;
71 constexpr int kWidthRank = 2;
72
73 const int input_height = input_shape.dims(kHeightRank);
74 const int input_width = input_shape.dims(kWidthRank);
75 int output_height = output_shape.dims(kHeightRank);
76 int output_width = output_shape.dims(kWidthRank);
77
78 status = utils::checkCondition(input_height == output_height * block_size);
79 if (status != Ok)
80 return status;
81
82 status = utils::checkCondition(input_width == output_width * block_size);
83 if (status != Ok)
84 return status;
85 return status;
86}
87
88} // namespace import
89} // namespace onert_micro
int32_t dims(int i) const
Definition Tensor.h:108
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_CircleSpaceToDepth(const onert_micro::import::OMConfigureArgs &config_args)
core::OMRuntimeContext & runtime_context