ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SpaceToDepth.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __NNFW_CKER_SPACE_TO_DEPTH_H__
19#define __NNFW_CKER_SPACE_TO_DEPTH_H__
20
21#include "cker/Shape.h"
22#include "cker/Types.h"
23
24namespace nnfw
25{
26namespace cker
27{
28
29template <typename T>
30inline void SpaceToDepth(const SpaceToDepthParams &params, const Shape &unextended_input_shape,
31 const T *input_data, const Shape &unextended_output_shape, T *output_data)
32{
33 assert(unextended_input_shape.DimensionsCount() <= 4);
34 assert(unextended_output_shape.DimensionsCount() <= 4);
35 const Shape input_shape = Shape::ExtendedShape(4, unextended_input_shape);
36 const Shape output_shape = Shape::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
42 const int input_depth = input_shape.Dims(3);
43 const int batch_size = input_shape.Dims(0);
44
45 // Number of continuous values that we can copy in one interation.
46 const int stride = params.block_size * input_depth;
47
48 for (int batch = 0; batch < batch_size; ++batch)
49 {
50 for (int out_h = 0; out_h < output_height; ++out_h)
51 {
52 T *output_ptr = output_data + Offset(output_shape, batch, out_h, 0, 0);
53 for (int offset_h = 0; offset_h < params.block_size; ++offset_h)
54 {
55 T *dst = output_ptr;
56 for (int out_w = 0; out_w < output_width; ++out_w)
57 {
58 memcpy(dst, input_data, stride * sizeof(T));
59 input_data += stride;
60 dst += output_depth;
61 }
62 output_ptr += stride;
63 }
64 }
65 }
66}
67
68} // namespace cker
69} // namespace nnfw
70
71#endif // __NNFW_CKER_SPACE_TO_DEPTH_H__
int32_t DimensionsCount() const
Definition Shape.h:91
int32_t Dims(int i) const
Definition Shape.h:92
const luci_interpreter::RuntimeShape output_shape
int Offset(const Shape &shape, int i0, int i1, int i2, int i3)
Definition Shape.h:237
void SpaceToDepth(const SpaceToDepthParams &params, const Shape &unextended_input_shape, const T *input_data, const Shape &unextended_output_shape, T *output_data)
Definition topk_v2.h:30