ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALDepthToSpace.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 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#ifndef LUCI_INTERPRETER_PAL_DEPTH_TO_SPACE_COMMON_H
18#define LUCI_INTERPRETER_PAL_DEPTH_TO_SPACE_COMMON_H
19
20#include "PALUtils.h"
21
22#include <cmath>
23
25{
26
27template <typename T>
28inline void
29DepthToSpace(const int32_t block_size, const luci_interpreter::RuntimeShape &unextended_input_shape,
30 const T *input_data, const luci_interpreter::RuntimeShape &unextended_output_shape,
31 T *output_data)
32{
33 const luci_interpreter::RuntimeShape input_shape =
34 luci_interpreter::RuntimeShape::extendedShape(4, unextended_input_shape);
36 luci_interpreter::RuntimeShape::extendedShape(4, unextended_output_shape);
37
38 const int output_depth = output_shape.dims(3);
39 const int output_width = output_shape.dims(2);
40 const int output_height = output_shape.dims(1);
41 const int output_batch = output_shape.dims(0);
42
43 for (int out_b = 0; out_b < output_batch; ++out_b)
44 {
45 for (int out_h = 0; out_h < output_height; ++out_h)
46 {
47 for (int out_w = 0; out_w < output_width; ++out_w)
48 {
49 for (int out_d = 0; out_d < output_depth; ++out_d)
50 {
51 const int in_d =
52 out_d + ((out_h % block_size) * block_size + out_w % block_size) * output_depth;
53
54 const int in_w = out_w / block_size;
55 const int in_h = out_h / block_size;
56 const int in_b = out_b;
57
58 const int input_index = offset(input_shape.dimsData(), in_b, in_h, in_w, in_d);
59 const int output_index = offset(output_shape.dimsData(), out_b, out_h, out_w, out_d);
60
61 output_data[output_index] = input_data[input_index];
62 }
63 }
64 }
65 }
66}
67
68} // namespace luci_interpreter_pal
69
70#endif // LUCI_INTERPRETER_PAL_DEPTH_TO_SPACE_COMMON_H
int32_t dims(int i) const
Definition Tensor.h:108
static RuntimeShape extendedShape(int new_shape_size, const RuntimeShape &shape)
Definition Tensor.h:95
const luci_interpreter::RuntimeShape output_shape
int offset(const int32_t *dims_data, int i0, int i1, int i2, int i3)
Definition PALUtils.h:193