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
33OMStatus onert_micro::import::configure_kernel_CircleSpaceToDepth(
34 const onert_micro::import::OMConfigureArgs &config_args)
35{
36 OMRuntimeContext &runtime_context = config_args.runtime_context;
37 uint16_t op_index = config_args.kernel_index;
38
40
41 OMStatus status = runtime_kernel.readKernel(op_index, runtime_context);
42 if (status != Ok)
43 return status;
44
45 const circle::Tensor *input = runtime_kernel.inputs[inputTensorIdx];
46 const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx];
47
48 assert(input != nullptr);
49 assert(output != nullptr);
50
51 status = utils::checkCondition(input->type() == output->type());
52 if (status != Ok)
53 return status;
54
55 OMRuntimeShape input_shape(input);
57
58 const auto *options = runtime_kernel.first_operator->builtin_options_as_SpaceToDepthOptions();
59 const int32_t block_size = options->block_size();
60
61 status = utils::checkCondition(block_size > 0);
62 if (status != Ok)
63 return status;
64
65 constexpr int kHeightRank = 1;
66 constexpr int kWidthRank = 2;
67
68 const int input_height = input_shape.dims(kHeightRank);
69 const int input_width = input_shape.dims(kWidthRank);
70 int output_height = output_shape.dims(kHeightRank);
71 int output_width = output_shape.dims(kWidthRank);
72
73 status = utils::checkCondition(input_height == output_height * block_size);
74 if (status != Ok)
75 return status;
76
77 status = utils::checkCondition(input_width == output_width * block_size);
78 if (status != Ok)
79 return status;
80 return status;
81}
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
core::OMRuntimeContext & runtime_context