blob: 95a93640825a68e805b491bd5c46e167f3b94924 [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 Iodice2bbd9642017-07-04 16:46:32 +010072 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QS8, DataType::U16, DataType::S16, DataType::QS16, DataType::U32, DataType::S32, DataType::F16,
73 DataType::F32);
Gian Marco Iodiceec8b45e2017-06-22 13:00:39 +010074 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075
76 TensorShape output_shape = input->info()->tensor_shape();
77 output_shape.set(0, convolved_dims.first);
78 output_shape.set(1, convolved_dims.second);
79 output_shape.set(2, input->info()->tensor_shape()[0]);
80
Gian Marco Iodiceec8b45e2017-06-22 13:00:39 +010081 // Output auto inizialitation if not yet initialized
82 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 +010083
84 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
Gian Marco Iodiceec8b45e2017-06-22 13:00:39 +010086 ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087
88 _input = input;
89 _output = output;
90 _convolved_dims = convolved_dims;
91
92 switch(input->info()->element_size())
93 {
94 case 1:
95 _func = &NECol2ImKernel::run_col2im<uint8_t>;
96 break;
97 case 2:
98 _func = &NECol2ImKernel::run_col2im<uint16_t>;
99 break;
100 case 4:
101 _func = &NECol2ImKernel::run_col2im<uint32_t>;
102 break;
103 default:
104 ARM_COMPUTE_ERROR("Element size not supported");
105 break;
106 }
107
108 // Configure kernel window
109 Window win = calculate_max_window(*input->info(), Steps());
110
111 // The NECol2ImKernel doesn't need padding so update_window_and_padding() can be skipped
112 Coordinates coord;
113 coord.set_num_dimensions(output->info()->num_dimensions());
114 output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
115
116 INEKernel::configure(win);
117}
118
119void NECol2ImKernel::run(const Window &window)
120{
121 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
122 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
123
124 (this->*_func)(window);
125}