ONE - On-device Neural Engine
Loading...
Searching...
No Matches
DepthToSpace.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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 "Builders.h"
18#include "kernels/Utils.h"
19#include "SISOKernel.h"
20
21#include "PALDepthToSpace.h"
22
23namespace luci_interpreter
24{
25
26void configure_kernel_CircleDepthToSpace(const circle::Operator *cur_op,
27 BaseRuntimeGraph *runtime_graph)
28{
29 kernels::SISOKernel kernel(cur_op, runtime_graph);
30
31 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) ==
32 Tensor::element_type(kernel.output()));
33
34 const auto *options = cur_op->builtin_options_as_DepthToSpaceOptions();
35
36 const int32_t block_size = options->block_size();
37 LUCI_INTERPRETER_CHECK(block_size > 0);
38
39 constexpr int kHeightRank = 1;
40 constexpr int kWidthRank = 2;
41 constexpr int kDepthRank = 3;
42
43 const int input_height = Tensor::dim(kernel.input(), kHeightRank);
44 const int input_width = Tensor::dim(kernel.input(), kWidthRank);
45 const int input_channels = Tensor::dim(kernel.input(), kDepthRank);
46 int output_height = input_height * block_size;
47 int output_width = input_width * block_size;
48 int output_channels = input_channels / block_size / block_size;
49
50 LUCI_INTERPRETER_CHECK(input_height == output_height / block_size);
51 LUCI_INTERPRETER_CHECK(input_width == output_width / block_size);
52 LUCI_INTERPRETER_CHECK(input_channels == output_channels * block_size * block_size);
53}
54
55void execute_kernel_CircleDepthToSpace(const circle::Operator *cur_op,
56 BaseRuntimeGraph *runtime_graph)
57{
58 kernels::SISOKernel kernel(cur_op, runtime_graph);
59
60 const auto *options = cur_op->builtin_options_as_DepthToSpaceOptions();
61 const int32_t block_size = options->block_size();
62
63 switch (Tensor::element_type(kernel.input()))
64 {
65#ifndef DIS_FLOAT
66 case DataType::FLOAT32:
67 {
68 assert(block_size != 0);
69 luci_interpreter_pal::DepthToSpace(
70 block_size, kernels::getTensorRuntimeShape(kernel.input(), runtime_graph),
71 kernels::getTensorData<float>(runtime_graph->getDataByTensor(kernel.input())),
72 kernels::getTensorRuntimeShape(kernel.output(), runtime_graph),
73 kernels::getTensorData<float>(runtime_graph->getDataByTensor(kernel.output())));
74 break;
75 }
76#endif // DIS_FLOAT
77 default:
78 assert(false && "Unsupported type");
79 }
80}
81} // namespace luci_interpreter
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition SISOKernel.h:47
const circle::Tensor * input() const
Definition SISOKernel.h:46
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void execute_kernel_CircleDepthToSpace(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void configure_kernel_CircleDepthToSpace(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
const loco::Dimension & dim(uint32_t axis) const
Definition Tensor.h:44