blob: e9a73607e6cf3d3ac404fcc9c7c7f2f189cee22a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/NEON/kernels/NECol2ImKernel.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/Helpers.h"
28#include "arm_compute/core/ITensor.h"
29#include "arm_compute/core/TensorInfo.h"
30#include "arm_compute/core/Types.h"
31#include "arm_compute/core/Validate.h"
32
33#include <arm_neon.h>
34#include <cstddef>
35#include <cstdint>
36
37using namespace arm_compute;
38
39template <typename T>
40void NECol2ImKernel::run_col2im(const Window &window)
41{
42 const int output_stride_x = _output->info()->strides_in_bytes().x();
43 const int output_stride_y = _output->info()->strides_in_bytes().y();
44 const int output_stride_z = _output->info()->strides_in_bytes().z();
45
46 Window window_out(window);
47 window_out.set(Window::DimX, Window::Dimension(0, 0, 0));
48 window_out.set(Window::DimY, Window::Dimension(0, 0, 0));
49 window_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
50
51 // Create iterators
52 Iterator in(_input, window);
53 Iterator out(_output, window_out);
54
55 execute_window_loop(window, [&](const Coordinates & id)
56 {
57 const int hidx = id.y();
58 const int idx = id.x() * output_stride_z + (hidx / _convolved_dims.first) * output_stride_y + (hidx % _convolved_dims.first) * output_stride_x;
59
60 *(reinterpret_cast<T *>(out.ptr() + idx)) = *(reinterpret_cast<const T *>(in.ptr()));
61 },
62 in, out);
63}
64
65NECol2ImKernel::NECol2ImKernel()
66 : _func(), _input(nullptr), _output(nullptr), _convolved_dims()
67{
68}
69
70void NECol2ImKernel::configure(const ITensor *input, ITensor *output, std::pair<unsigned int, unsigned int> convolved_dims)
71{
Gian Marco Iodiceec8b45e2017-06-22 13:00:39 +010072 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QS8, DataType::U16, DataType::S16, DataType::U32, DataType::S32, DataType::F16, DataType::F32);
73 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010074
75 TensorShape output_shape = input->info()->tensor_shape();
76 output_shape.set(0, convolved_dims.first);
77 output_shape.set(1, convolved_dims.second);
78 output_shape.set(2, input->info()->tensor_shape()[0]);
79
Gian Marco Iodiceec8b45e2017-06-22 13:00:39 +010080 // Output auto inizialitation if not yet initialized
81 auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type(), input->info()->fixed_point_position());
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082
83 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
Gian Marco Iodiceec8b45e2017-06-22 13:00:39 +010085 ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086
87 _input = input;
88 _output = output;
89 _convolved_dims = convolved_dims;
90
91 switch(input->info()->element_size())
92 {
93 case 1:
94 _func = &NECol2ImKernel::run_col2im<uint8_t>;
95 break;
96 case 2:
97 _func = &NECol2ImKernel::run_col2im<uint16_t>;
98 break;
99 case 4:
100 _func = &NECol2ImKernel::run_col2im<uint32_t>;
101 break;
102 default:
103 ARM_COMPUTE_ERROR("Element size not supported");
104 break;
105 }
106
107 // Configure kernel window
108 Window win = calculate_max_window(*input->info(), Steps());
109
110 // The NECol2ImKernel doesn't need padding so update_window_and_padding() can be skipped
111 Coordinates coord;
112 coord.set_num_dimensions(output->info()->num_dimensions());
113 output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
114
115 INEKernel::configure(win);
116}
117
118void NECol2ImKernel::run(const Window &window)
119{
120 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
121 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
122
123 (this->*_func)(window);
124}