ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALSpaceToDepth.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_SPACE_TO_DEPTH_COMMON_H
18#define LUCI_INTERPRETER_PAL_SPACE_TO_DEPTH_COMMON_H
19
20#include "PALUtils.h"
21
22#include <cmath>
23
25{
26
27template <typename T>
28inline void
29SpaceToDepth(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 input_depth = input_shape.dims(3);
39 const int input_width = input_shape.dims(2);
40 const int input_height = input_shape.dims(1);
41 const int input_batch = input_shape.dims(0);
42
43 for (int in_b = 0; in_b < input_batch; ++in_b)
44 {
45 for (int in_h = 0; in_h < input_height; ++in_h)
46 {
47 for (int in_w = 0; in_w < input_width; ++in_w)
48 {
49 for (int in_d = 0; in_d < input_depth; ++in_d)
50 {
51 const int out_d =
52 in_d + ((in_h % block_size) * block_size + in_w % block_size) * input_depth;
53 const int out_w = in_w / block_size;
54 const int out_h = in_h / block_size;
55 const int out_b = in_b;
56
57 const int input_index = offset(input_shape.dimsData(), in_b, in_h, in_w, in_d);
58 const int output_index = offset(output_shape.dimsData(), out_b, out_h, out_w, out_d);
59
60 output_data[output_index] = input_data[input_index];
61 }
62 }
63 }
64 }
65}
66
67} // namespace luci_interpreter_pal
68
69#endif // LUCI_INTERPRETER_PAL_SPACE_TO_DEPTH_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