blob: 16525ac22e642c8a64312aa9b505fea7079dd8fd [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
Anthony Barbiereaefd002018-07-20 17:49:35 +010026#include "arm_compute/core/CPP/Validate.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Error.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#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{
Anthony Barbiereaefd002018-07-20 17:49:35 +010050 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010051 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32);
Georgios Pinitasd912fd82017-11-27 21:00:13 +000052 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
Georgios Pinitasd912fd82017-11-27 21:00:13 +000053 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,
Alex Gilday7da29b62018-03-23 14:16:00 +000093 int pad_value,
94 int dilation_x,
95 int dilation_y)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096{
Gian Marco Iodice13edbff2017-06-26 17:20:16 +010097 const int kernel_size2 = kernel_width * kernel_height;
Alex Gilday7da29b62018-03-23 14:16:00 +000098 const int x_e = top_left_x + kernel_width * dilation_x;
99 const int y_e = top_left_y + kernel_height * dilation_y;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100
101 // Linearize volume
102 int d = 0;
103 // This for loop linearize a volume with 3 slices. This allows:
104 // 1) to reduce the iterations of the outer for loop "d"
105 // 2) to have an optimized im2col for the first convolution layer where usually we have 3 IFMs
106 for(; d <= (kernel_depth - 3); d += 3)
107 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000108 for(int y = top_left_y; y < y_e; y += dilation_y)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109 {
110 if((y < 0 || y >= input_h) && has_pads)
111 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000112 // All the values will be the offset (will be zeros when not quantized)
Alex Gilday7da29b62018-03-23 14:16:00 +0000113 for(int x = top_left_x; x < x_e; x += dilation_x, ++out_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000115 *(out_ptr + 0 * kernel_size2) = pad_value;
116 *(out_ptr + 1 * kernel_size2) = pad_value;
117 *(out_ptr + 2 * kernel_size2) = pad_value;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118 }
119 }
120 else
121 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000122 for(int x = top_left_x; x < x_e; x += dilation_x, ++out_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123 {
124 if((x < 0 || x >= input_w) && has_pads)
125 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000126 *(out_ptr + 0 * kernel_size2) = pad_value;
127 *(out_ptr + 1 * kernel_size2) = pad_value;
128 *(out_ptr + 2 * kernel_size2) = pad_value;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100129 }
130 else
131 {
132 *(out_ptr + 0 * kernel_size2) = *(reinterpret_cast<const T *>(in_ptr + ((d + 0) * input_stride_z + y * input_stride_y + x * input_stride_x)));
133 *(out_ptr + 1 * kernel_size2) = *(reinterpret_cast<const T *>(in_ptr + ((d + 1) * input_stride_z + y * input_stride_y + x * input_stride_x)));
134 *(out_ptr + 2 * kernel_size2) = *(reinterpret_cast<const T *>(in_ptr + ((d + 2) * input_stride_z + y * input_stride_y + x * input_stride_x)));
135 }
136 }
137 }
138 }
139 out_ptr += 2 * kernel_size2;
140 }
141
142 // Left over
143 for(; d < kernel_depth; d++)
144 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000145 for(int y = top_left_y; y < y_e; y += dilation_y)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 {
147 if((y < 0 || y >= input_h) && has_pads)
148 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000149 // All the values will be the offset (will be zeros when not quantized)
150 memset(out_ptr, pad_value, kernel_width * sizeof(T));
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100151 out_ptr += kernel_width;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 }
153 else
154 {
Alex Gilday7da29b62018-03-23 14:16:00 +0000155 for(int x = top_left_x; x < x_e; x += dilation_x, ++out_ptr)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156 {
157 if((x < 0 || x >= input_w) && has_pads)
158 {
Isabella Gottardie6630e42018-01-18 15:50:39 +0000159 *out_ptr = pad_value;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100160 }
161 else
162 {
163 *out_ptr = *(reinterpret_cast<const T *>(in_ptr + (d * input_stride_z + y * input_stride_y + x * input_stride_x)));
164 }
165 }
166 }
167 }
168 }
169
170 // Append 1 if the convolution layer has biases
171 if(has_bias)
172 {
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100173 *out_ptr = static_cast<T>(1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174 }
175}
176} // namespace
177
178template <typename T, bool has_pads>
179void NEIm2ColKernel::run_generic(const Window &window)
180{
181 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
182 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
183
Giorgio Arena156fcf32018-03-09 15:30:43 +0000184 const DataLayout data_layout = _input->info()->data_layout();
185 const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
186 const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
187 const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
188
189 const int kernel_depth = _input->info()->dimension(channel_idx);
190 const int input_w = _input->info()->dimension(width_idx);
191 const int input_h = _input->info()->dimension(height_idx);
192 const int input_stride_x = _input->info()->strides_in_bytes()[width_idx];
193 const int input_stride_y = _input->info()->strides_in_bytes()[height_idx];
194 const int input_stride_z = _input->info()->strides_in_bytes()[channel_idx];
Isabella Gottardie6630e42018-01-18 15:50:39 +0000195 const int offset = is_data_type_quantized(_input->info()->data_type()) ? _input->info()->quantization_info().offset : 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100196
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100197 int pad_left = 0;
198 int pad_top = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199 int stride_x = 0;
200 int stride_y = 0;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100201 pad_left = _conv_info.pad_left();
202 pad_top = _conv_info.pad_top();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203 std::tie(stride_x, stride_y) = _conv_info.stride();
204
205 // Setup input window
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100206 const int start_x = -pad_left;
207 const int start_y = -pad_top;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208
Giorgio Arenaf485a102018-04-20 16:06:21 +0100209 Window window_in_out(window);
210 // The first three dimensions of the input and output are increased by the inner loops
211 window_in_out.set(Window::DimX, Window::Dimension(0, 0, 0));
212 window_in_out.set(Window::DimY, Window::Dimension(0, 0, 0));
213 window_in_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100214
215 // Create iterators
Giorgio Arenaf485a102018-04-20 16:06:21 +0100216 Iterator in(_input, window_in_out);
217 Iterator out(_output, window_in_out);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100218
219 execute_window_loop(window, [&](const Coordinates & id)
220 {
Giorgio Arena156fcf32018-03-09 15:30:43 +0000221 const int top_left_x = id[width_idx] * stride_x + start_x;
222 const int top_left_y = id[height_idx] * stride_y + start_y;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100223
224 // Get pointers
225 const uint8_t *const input_ptr = in.ptr();
Giorgio Arenaf485a102018-04-20 16:06:21 +0100226 auto output_ptr = reinterpret_cast<T *>(out.ptr() + (id[width_idx] + id[height_idx] * _convolved_dims.first) * _output->info()->strides_in_bytes().y());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227
228 // Linearize volume
229 linearize_volume<T, has_pads>(input_ptr,
230 output_ptr,
231 _has_bias,
232 top_left_x,
233 top_left_y,
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100234 static_cast<int>(_kernel_width),
235 static_cast<int>(_kernel_height),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100236 kernel_depth,
237 input_w,
238 input_h,
239 input_stride_x,
240 input_stride_y,
241 input_stride_z,
Alex Gilday7da29b62018-03-23 14:16:00 +0000242 offset,
243 _dilation.x(),
244 _dilation.y());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245 },
246 in, out);
247}
248
249template <typename T>
250void NEIm2ColKernel::run_reduced(const Window &window)
251{
252 const size_t in_width = _input->info()->dimension(0);
253 const size_t in_height = _input->info()->dimension(1);
254 const size_t out_step_x = in_width * _input->info()->element_size();
255 const size_t out_step_y = out_step_x * in_height;
256 const size_t out_width = _output->info()->dimension(0);
257
258 Window in_window(window);
259 in_window.set(Window::DimX, Window::Dimension(0, 1, 1));
260
261 Window out_window;
SiCong Li86b53332017-08-23 11:02:43 +0100262 out_window.use_tensor_dimensions(_output->info()->tensor_shape());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100263 out_window.set(Window::DimX, Window::Dimension(out_window.x().start(), out_window.x().end(), in_width));
264
265 Window in_slice = in_window.first_slice_window_3D();
266 Window out_slice = out_window.first_slice_window_1D();
267
268 do
269 {
270 Iterator in(_input, in_slice);
271 Iterator out(_output, out_slice);
272
273 uint8_t *out_ptr = out.ptr();
274
275 execute_window_loop(in_slice, [&](const Coordinates & id)
276 {
277 memcpy(out_ptr + id.y() * out_step_x + id.z() * out_step_y, in.ptr(), out_step_x);
278 },
279 in);
280
281 // Add bias
282 if(_has_bias)
283 {
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100284 *(reinterpret_cast<T *>(out_ptr) + out_width - 1) = static_cast<T>(1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100285 }
286 }
287 while(in_window.slide_window_slice_3D(in_slice) && out_window.slide_window_slice_1D(out_slice));
288}
289
290NEIm2ColKernel::NEIm2ColKernel()
Alex Gilday7da29b62018-03-23 14:16:00 +0000291 : _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 +0100292{
293}
294
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000295void NEIm2ColKernel::configure(const ITensor *input, ITensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info,
Alex Gilday7da29b62018-03-23 14:16:00 +0000296 bool has_bias, bool is_fully_connected, bool is_flatten, const Size2D &dilation)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100297{
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000298 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
299
300 // Perform validation step
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000301 ARM_COMPUTE_UNUSED(is_fully_connected, is_flatten);
Alex Gilday7da29b62018-03-23 14:16:00 +0000302 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 +0100303
Giorgio Arena156fcf32018-03-09 15:30:43 +0000304 const DataLayout data_layout = input->info()->data_layout();
305 const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
306 const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
307 const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
308
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100309 _input = input;
310 _output = output;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100311 _conv_info = conv_info;
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100312 _kernel_width = kernel_dims.width;
Alex Gilday7da29b62018-03-23 14:16:00 +0000313 _kernel_height = kernel_dims.height;
314 _dilation = dilation;
Giorgio Arena156fcf32018-03-09 15:30:43 +0000315 _convolved_dims = scaled_dimensions(input->info()->dimension(width_idx), input->info()->dimension(height_idx),
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100316 _kernel_width, _kernel_height,
Alex Gilday7da29b62018-03-23 14:16:00 +0000317 _conv_info, _dilation);
Gian Marco Iodice13edbff2017-06-26 17:20:16 +0100318 _has_bias = has_bias;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100319
Moritz Pflanzer484e7b32017-08-09 11:43:18 +0100320 unsigned int stride_x = 0;
321 unsigned int stride_y = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100322 std::tie(stride_x, stride_y) = conv_info.stride();
323
324 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)
325 && (std::equal(input->info()->tensor_shape().cbegin() + 3,
326 input->info()->tensor_shape().cend(),
327 output->info()->tensor_shape().cbegin() + 1))
Alex Gilday7da29b62018-03-23 14:16:00 +0000328 && ((stride_x == 1) && (stride_y == 1) && !conv_info.has_padding())
329 && ((dilation.x() == 1) && (dilation.y() == 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100330
331 Window window = calculate_max_window(*input->info(), Steps());
332
333 if(run_img2col_reduced)
334 {
335 switch(_input->info()->data_type())
336 {
337 case DataType::F32:
338 _func = &NEIm2ColKernel::run_reduced<float>;
339 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000340#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello659abc02017-06-22 16:00:16 +0100341 case DataType::F16:
342 _func = &NEIm2ColKernel::run_reduced<float16_t>;
343 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000344#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Isabella Gottardie6630e42018-01-18 15:50:39 +0000345 case DataType::QASYMM8:
346 _func = &NEIm2ColKernel::run_reduced<qasymm8_t>;
347 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348 default:
349 ARM_COMPUTE_ERROR("Data type not supported");
350 break;
351 }
352 }
353 else
354 {
355 switch(_input->info()->data_type())
356 {
357 case DataType::F32:
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100358 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<float, false> : &NEIm2ColKernel::run_generic<float, true>;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100359 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000360#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello659abc02017-06-22 16:00:16 +0100361 case DataType::F16:
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100362 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<float16_t, false> : &NEIm2ColKernel::run_generic<float16_t, true>;
Pablo Tello659abc02017-06-22 16:00:16 +0100363 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000364#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Isabella Gottardie6630e42018-01-18 15:50:39 +0000365 case DataType::QASYMM8:
366 _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_generic<qasymm8_t, false> : &NEIm2ColKernel::run_generic<qasymm8_t, true>;
367 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368 default:
369 ARM_COMPUTE_ERROR("Data type not supported");
370 break;
371 }
Giorgio Arena156fcf32018-03-09 15:30:43 +0000372 window.set(width_idx, Window::Dimension(0, _convolved_dims.first, 1));
373 window.set(height_idx, Window::Dimension(0, _convolved_dims.second, 1));
374 window.set(channel_idx, Window::Dimension(0, 1, 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100375 }
376
377 // The NEIm2ColKernel doesn't need padding so update_window_and_padding() can be skipped
378 output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
379
380 IKernel::configure(window);
381}
382
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000383Status NEIm2ColKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info,
Alex Gilday7da29b62018-03-23 14:16:00 +0000384 bool has_bias, bool is_fully_connected, bool is_flatten, const Size2D &dilation)
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000385{
Alex Gilday7da29b62018-03-23 14:16:00 +0000386 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 +0000387 return Status{};
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000388}
389
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100390void NEIm2ColKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100392 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100393 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
394 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
395
396 (this->*_func)(window);
397}