blob: 5e165a641ccc92f9bf5a6dee3b5ea80d0361f5be [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Isabella Gottardie6630e42018-01-18 15:50:39 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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/NEIm2ColKernel.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/FixedPoint.h"
28#include "arm_compute/core/Helpers.h"
29#include "arm_compute/core/ITensor.h"
Gian Marco Iodice13edbff2017-06-26 17:20:16 +010030#include "arm_compute/core/Size2D.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/TensorInfo.h"
32#include "arm_compute/core/Types.h"
33#include "arm_compute/core/Validate.h"
34
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000035#include "arm_compute/core/utils/misc/ShapeCalculator.h"
36
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037#include <arm_neon.h>
38#include <cstddef>
39#include <cstdint>
40#include <cstring>
41#include <tuple>
42
43using namespace arm_compute;
44
45namespace
46{
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000047Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info,
Alex Gilday7da29b62018-03-23 14:16:00 +000048 bool has_bias, bool is_fully_connected, bool is_flatten, const Size2D &dilation)
Georgios Pinitasd912fd82017-11-27 21:00:13 +000049{
50 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F16, DataType::F32);
51 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
52 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, output);
53 ARM_COMPUTE_RETURN_ERROR_ON(input->data_type() == DataType::QASYMM8 && has_bias);
Alex Gilday7da29b62018-03-23 14:16:00 +000054 ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1));
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000055
Giorgio Arena156fcf32018-03-09 15:30:43 +000056 TensorShape expected_output_shape;
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000057 if(is_flatten) /* Called by FlattenLayer */
58 {
Giorgio Arena156fcf32018-03-09 15:30:43 +000059 expected_output_shape = misc::shape_calculator::compute_im2col_flatten_shape(input);
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000060 }
61 else if(!is_fully_connected) /* Called by ConvolutionLayer */
62 {
Giorgio Arena156fcf32018-03-09 15:30:43 +000063 expected_output_shape = misc::shape_calculator::compute_im2col_conv_shape(input, kernel_dims, conv_info, has_bias, dilation);
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000064 }
65 else /* Called by FullyConnectedLayer */
66 {
67 const int num_batch_dimensions = std::max(0, static_cast<int>(output->tensor_shape().num_dimensions()) - 1);
68 const int num_input_dimensions = input->tensor_shape().num_dimensions() - num_batch_dimensions;
69
Giorgio Arena156fcf32018-03-09 15:30:43 +000070 expected_output_shape = misc::shape_calculator::compute_im2col_fc_shape(input, num_input_dimensions);
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000071 }
Georgios Pinitasd912fd82017-11-27 21:00:13 +000072
Giorgio Arena156fcf32018-03-09 15:30:43 +000073 TensorInfo expected_output = output->clone()->set_tensor_shape(expected_output_shape);
74 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(&expected_output, output);
75
Georgios Pinitas631c41a2017-12-06 11:53:03 +000076 return Status{};
Georgios Pinitasd912fd82017-11-27 21:00:13 +000077}
78
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079template <typename T, bool has_pads>
80inline void linearize_volume(const uint8_t *const in_ptr,
81 T *out_ptr,
82 bool has_bias,
83 int top_left_x,
84 int top_left_y,
Gian Marco Iodice13edbff2017-06-26 17:20:16 +010085 int kernel_width,
86 int kernel_height,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087 int kernel_depth,
88 int input_w,
89 int input_h,
90 int input_stride_x,
91 int input_stride_y,
92 int input_stride_z,
Isabella Gottardie6630e42018-01-18 15:50:39 +000093 int fixed_point_position,
Alex Gilday7da29b62018-03-23 14:16:00 +000094 int pad_value,
95 int dilation_x,
96 int dilation_y)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097{
Gian Marco Iodice13edbff2017-06-26 17:20:16 +010098 const int kernel_size2 = kernel_width * kernel_height;
Alex Gilday7da29b62018-03-23 14:16:00 +000099 const int x_e = top_left_x + kernel_width * dilation_x;
100 const int y_e = top_left_y + kernel_height * dilation_y;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101
102 // Linearize volume
103 int d = 0;
104 // This for loop linearize a volume with 3 slices. This allows:
105 // 1) to reduce the iterations of the outer for loop "d"
106 // 2) to have an optimized im2col for the first convolution layer where usually we have 3 IFMs
107 for(; d <= (kernel_depth - 3); d += 3)
108 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000109 for(int y = top_left_y; y < y_e; y += dilation_y)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110 {
111 if((y < 0 || y >= input_h) && has_pads)
112 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000113 // All the values will be the offset (will be zeros when not quantized)
Alex Gilday7da29b62018-03-23 14:16:00 +0000114 for(int x = top_left_x; x < x_e; x += dilation_x, ++out_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000116 *(out_ptr + 0 * kernel_size2) = pad_value;
117 *(out_ptr + 1 * kernel_size2) = pad_value;
118 *(out_ptr + 2 * kernel_size2) = pad_value;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100119 }
120 }
121 else
122 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000123 for(int x = top_left_x; x < x_e; x += dilation_x, ++out_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124 {
125 if((x < 0 || x >= input_w) && has_pads)
126 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000127 *(out_ptr + 0 * kernel_size2) = pad_value;
128 *(out_ptr + 1 * kernel_size2) = pad_value;
129 *(out_ptr + 2 * kernel_size2) = pad_value;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100130 }
131 else
132 {
133 *(out_ptr + 0 * kernel_size2) = *(reinterpret_cast<const T *>(in_ptr + ((d + 0) * input_stride_z + y * input_stride_y + x * input_stride_x)));
134 *(out_ptr + 1 * kernel_size2) = *(reinterpret_cast<const T *>(in_ptr + ((d + 1) * input_stride_z + y * input_stride_y + x * input_stride_x)));
135 *(out_ptr + 2 * kernel_size2) = *(reinterpret_cast<const T *>(in_ptr + ((d + 2) * input_stride_z + y * input_stride_y + x * input_stride_x)));
136 }
137 }
138 }
139 }
140 out_ptr += 2 * kernel_size2;
141 }
142
143 // Left over
144 for(; d < kernel_depth; d++)
145 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000146 for(int y = top_left_y; y < y_e; y += dilation_y)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100147 {
148 if((y < 0 || y >= input_h) && has_pads)
149 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000150 // All the values will be the offset (will be zeros when not quantized)
151 memset(out_ptr, pad_value, kernel_width * sizeof(T));
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100152 out_ptr += kernel_width;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100153 }
154 else
155 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000156 for(int x = top_left_x; x < x_e; x += dilation_x, ++out_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100157 {
158 if((x < 0 || x >= input_w) && has_pads)
159 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000160 *out_ptr = pad_value;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100161 }
162 else
163 {
164 *out_ptr = *(reinterpret_cast<const T *>(in_ptr + (d * input_stride_z + y * input_stride_y + x * input_stride_x)));
165 }
166 }
167 }
168 }
169 }
170
171 // Append 1 if the convolution layer has biases
172 if(has_bias)
173 {
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100174 if(std::is_same<T, qint8_t>::value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100175 {
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100176 *out_ptr = sqcvt_qs8_f32(1.0f, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177 }
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100178 else if(std::is_same<T, qint16_t>::value)
179 {
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100180 *out_ptr = sqcvt_qs16_f32(1.0f, fixed_point_position);
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100181 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100182 else
183 {
184 *out_ptr = static_cast<T>(1);
185 }
186 }
187}
188} // namespace
189
190template <typename T, bool has_pads>
191void NEIm2ColKernel::run_generic(const Window &window)
192{
193 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
194 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
195
Giorgio Arena156fcf32018-03-09 15:30:43 +0000196 const DataLayout data_layout = _input->info()->data_layout();
197 const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
198 const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
199 const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
200
201 const int kernel_depth = _input->info()->dimension(channel_idx);
202 const int input_w = _input->info()->dimension(width_idx);
203 const int input_h = _input->info()->dimension(height_idx);
204 const int input_stride_x = _input->info()->strides_in_bytes()[width_idx];
205 const int input_stride_y = _input->info()->strides_in_bytes()[height_idx];
206 const int input_stride_z = _input->info()->strides_in_bytes()[channel_idx];
Isabella Gottardie6630e42018-01-18 15:50:39 +0000207 const int offset = is_data_type_quantized(_input->info()->data_type()) ? _input->info()->quantization_info().offset : 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100209 int pad_left = 0;
210 int pad_top = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100211 int stride_x = 0;
212 int stride_y = 0;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100213 pad_left = _conv_info.pad_left();
214 pad_top = _conv_info.pad_top();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215 std::tie(stride_x, stride_y) = _conv_info.stride();
216
217 // Setup input window
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100218 const int start_x = -pad_left;
219 const int start_y = -pad_top;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100220
221 Window window_in(window);
222 // The first three dimensions of the input are increased by the inner loops
223 window_in.set(Window::DimX, Window::Dimension(0, 0, 0));
224 window_in.set(Window::DimY, Window::Dimension(0, 0, 0));
225 window_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
226
227 // Setup output window
228 Window window_out(window);
Giorgio Arena156fcf32018-03-09 15:30:43 +0000229 window_out.set(width_idx, Window::Dimension(0, _output->info()->dimension(width_idx), _output->info()->strides_in_bytes()[width_idx + 1] / _output->info()->strides_in_bytes()[width_idx]));
230 window_out.set(height_idx, Window::Dimension(window[height_idx].start() * _convolved_dims.first, window[height_idx].end() * _convolved_dims.first, _convolved_dims.first));
231 window_out.set(channel_idx, Window::Dimension(0, 1, 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100232
233 // Create iterators
234 Iterator in(_input, window_in);
235 Iterator out(_output, window_out);
236
237 execute_window_loop(window, [&](const Coordinates & id)
238 {
Giorgio Arena156fcf32018-03-09 15:30:43 +0000239 const int top_left_x = id[width_idx] * stride_x + start_x;
240 const int top_left_y = id[height_idx] * stride_y + start_y;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241
242 // Get pointers
243 const uint8_t *const input_ptr = in.ptr();
244 auto output_ptr = reinterpret_cast<T *>(out.ptr());
245
246 // Linearize volume
247 linearize_volume<T, has_pads>(input_ptr,
248 output_ptr,
249 _has_bias,
250 top_left_x,
251 top_left_y,
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100252 static_cast<int>(_kernel_width),
253 static_cast<int>(_kernel_height),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100254 kernel_depth,
255 input_w,
256 input_h,
257 input_stride_x,
258 input_stride_y,
259 input_stride_z,
Isabella Gottardie6630e42018-01-18 15:50:39 +0000260 _input->info()->fixed_point_position(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000261 offset,
262 _dilation.x(),
263 _dilation.y());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100264 },
265 in, out);
266}
267
268template <typename T>
269void NEIm2ColKernel::run_reduced(const Window &window)
270{
271 const size_t in_width = _input->info()->dimension(0);
272 const size_t in_height = _input->info()->dimension(1);
273 const size_t out_step_x = in_width * _input->info()->element_size();
274 const size_t out_step_y = out_step_x * in_height;
275 const size_t out_width = _output->info()->dimension(0);
276
277 Window in_window(window);
278 in_window.set(Window::DimX, Window::Dimension(0, 1, 1));
279
280 Window out_window;
SiCong Li86b53332017-08-23 11:02:43 +0100281 out_window.use_tensor_dimensions(_output->info()->tensor_shape());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100282 out_window.set(Window::DimX, Window::Dimension(out_window.x().start(), out_window.x().end(), in_width));
283
284 Window in_slice = in_window.first_slice_window_3D();
285 Window out_slice = out_window.first_slice_window_1D();
286
287 do
288 {
289 Iterator in(_input, in_slice);
290 Iterator out(_output, out_slice);
291
292 uint8_t *out_ptr = out.ptr();
293
294 execute_window_loop(in_slice, [&](const Coordinates & id)
295 {
296 memcpy(out_ptr + id.y() * out_step_x + id.z() * out_step_y, in.ptr(), out_step_x);
297 },
298 in);
299
300 // Add bias
301 if(_has_bias)
302 {
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100303 if(std::is_same<T, qint8_t>::value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100304 {
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100305 *(reinterpret_cast<T *>(out_ptr) + out_width - 1) = sqcvt_qs8_f32(1.0f, _input->info()->fixed_point_position());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100306 }
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100307 else if(std::is_same<T, qint16_t>::value)
308 {
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100309 *(reinterpret_cast<T *>(out_ptr) + out_width - 1) = sqcvt_qs16_f32(1.0f, _input->info()->fixed_point_position());
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100310 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100311 else
312 {
313 *(reinterpret_cast<T *>(out_ptr) + out_width - 1) = static_cast<T>(1);
314 }
315 }
316 }
317 while(in_window.slide_window_slice_3D(in_slice) && out_window.slide_window_slice_1D(out_slice));
318}
319
320NEIm2ColKernel::NEIm2ColKernel()
Alex Gilday7da29b62018-03-23 14:16:00 +0000321 : _func(), _input(nullptr), _output(nullptr), _convolved_dims(), _conv_info(), _kernel_width(0), _kernel_height(0), _has_bias(false), _dilation(1U, 1U)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100322{
323}
324
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000325void NEIm2ColKernel::configure(const ITensor *input, ITensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info,
Alex Gilday7da29b62018-03-23 14:16:00 +0000326 bool has_bias, bool is_fully_connected, bool is_flatten, const Size2D &dilation)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100327{
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000328 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
329
330 // Perform validation step
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000331 ARM_COMPUTE_UNUSED(is_fully_connected, is_flatten);
Alex Gilday7da29b62018-03-23 14:16:00 +0000332 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), kernel_dims, conv_info, has_bias, is_fully_connected, is_flatten, dilation));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333
Giorgio Arena156fcf32018-03-09 15:30:43 +0000334 const DataLayout data_layout = input->info()->data_layout();
335 const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
336 const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
337 const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
338
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100339 _input = input;
340 _output = output;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100341 _conv_info = conv_info;
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100342 _kernel_width = kernel_dims.width;
Alex Gilday7da29b62018-03-23 14:16:00 +0000343 _kernel_height = kernel_dims.height;
344 _dilation = dilation;
Giorgio Arena156fcf32018-03-09 15:30:43 +0000345 _convolved_dims = scaled_dimensions(input->info()->dimension(width_idx), input->info()->dimension(height_idx),
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100346 _kernel_width, _kernel_height,
Alex Gilday7da29b62018-03-23 14:16:00 +0000347 _conv_info, _dilation);
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100348 _has_bias = has_bias;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349
Moritz Pflanzer484e7b32017-08-09 11:43:18 +0100350 unsigned int stride_x = 0;
351 unsigned int stride_y = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352 std::tie(stride_x, stride_y) = conv_info.stride();
353
354 bool run_img2col_reduced = (output->info()->dimension(0) == (input->info()->dimension(0) * input->info()->dimension(1) * input->info()->dimension(2))) && (TensorShape::num_max_dimensions >= 4)
355 && (std::equal(input->info()->tensor_shape().cbegin() + 3,
356 input->info()->tensor_shape().cend(),
357 output->info()->tensor_shape().cbegin() + 1))
Alex Gilday7da29b62018-03-23 14:16:00 +0000358 && ((stride_x == 1) && (stride_y == 1) && !conv_info.has_padding())
359 && ((dilation.x() == 1) && (dilation.y() == 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100360
361 Window window = calculate_max_window(*input->info(), Steps());
362
363 if(run_img2col_reduced)
364 {
365 switch(_input->info()->data_type())
366 {
367 case DataType::F32:
368 _func = &NEIm2ColKernel::run_reduced<float>;
369 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000370#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello659abc02017-06-22 16:00:16 +0100371 case DataType::F16:
372 _func = &NEIm2ColKernel::run_reduced<float16_t>;
373 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000374#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100375 case DataType::QS8:
376 _func = &NEIm2ColKernel::run_reduced<qint8_t>;
377 break;
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100378 case DataType::QS16:
379 _func = &NEIm2ColKernel::run_reduced<qint16_t>;
380 break;
Isabella Gottardie6630e42018-01-18 15:50:39 +0000381 case DataType::QASYMM8:
382 _func = &NEIm2ColKernel::run_reduced<qasymm8_t>;
383 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100384 default:
385 ARM_COMPUTE_ERROR("Data type not supported");
386 break;
387 }
388 }
389 else
390 {
391 switch(_input->info()->data_type())
392 {
393 case DataType::F32:
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100394 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<float, false> : &NEIm2ColKernel::run_generic<float, true>;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100395 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000396#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello659abc02017-06-22 16:00:16 +0100397 case DataType::F16:
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100398 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<float16_t, false> : &NEIm2ColKernel::run_generic<float16_t, true>;
Pablo Tello659abc02017-06-22 16:00:16 +0100399 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000400#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401 case DataType::QS8:
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100402 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<qint8_t, false> : &NEIm2ColKernel::run_generic<qint8_t, true>;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100403 break;
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100404 case DataType::QS16:
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100405 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<qint16_t, false> : &NEIm2ColKernel::run_generic<qint16_t, true>;
Gian Marco Iodice2bbd9642017-07-04 16:46:32 +0100406 break;
Isabella Gottardie6630e42018-01-18 15:50:39 +0000407 case DataType::QASYMM8:
408 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<qasymm8_t, false> : &NEIm2ColKernel::run_generic<qasymm8_t, true>;
409 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100410 default:
411 ARM_COMPUTE_ERROR("Data type not supported");
412 break;
413 }
Giorgio Arena156fcf32018-03-09 15:30:43 +0000414 window.set(width_idx, Window::Dimension(0, _convolved_dims.first, 1));
415 window.set(height_idx, Window::Dimension(0, _convolved_dims.second, 1));
416 window.set(channel_idx, Window::Dimension(0, 1, 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100417 }
418
419 // The NEIm2ColKernel doesn't need padding so update_window_and_padding() can be skipped
420 output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
421
422 IKernel::configure(window);
423}
424
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000425Status NEIm2ColKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info,
Alex Gilday7da29b62018-03-23 14:16:00 +0000426 bool has_bias, bool is_fully_connected, bool is_flatten, const Size2D &dilation)
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000427{
Alex Gilday7da29b62018-03-23 14:16:00 +0000428 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, kernel_dims, conv_info, has_bias, is_fully_connected, is_flatten, dilation));
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000429 return Status{};
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000430}
431
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100432void NEIm2ColKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100433{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100434 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100435 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
436 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
437
438 (this->*_func)(window);
439}