Compute Library
 21.11
CpuWinogradConv2dKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 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  */
25 
26 #include "arm_compute/core/Error.h"
33 #include "src/core/NEON/kernels/convolution/common/utils.hpp"
34 #include "src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp"
37 
38 #include <memory>
39 
40 namespace arm_compute
41 {
42 namespace cpu
43 {
44 //Batched Gemms
45 
46 namespace
47 {
48 inline bool is_kernel_size_supported(DataType data_type, Size2D size)
49 {
50  const std::array<Size2D, 8> f32_support = { { Size2D(1, 3), Size2D(3, 1), Size2D(5, 5), Size2D(3, 3), Size2D(1, 5), Size2D(5, 1), Size2D(7, 1), Size2D(1, 7) } };
51  const std::array<Size2D, 8> f16_support = { { Size2D(3, 3) } };
52 
53  switch(data_type)
54  {
55  case DataType::F16:
56  return std::end(f16_support) != std::find(std::begin(f16_support), std::end(f16_support), size);
57  case DataType::F32:
58  return std::end(f32_support) != std::find(std::begin(f32_support), std::end(f32_support), size);
59  default:
60  return false;
61  }
62 }
63 
64 Status validate_arguments_winograd_weight_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
65 {
69 
70  const size_t idx_width = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH);
71  const size_t idx_height = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT);
72  const auto input_width = input->dimension(idx_width);
73  const auto input_height = input->dimension(idx_height);
74  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(input_width, input_height)),
75  "Only 1x3, 3x1, 1x5, 5x1, 7x1, 1x7, 3x3 and 5x5 kernels are supported");
76  ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > 4);
77  const Size2D &output_tile = winograd_info.output_tile_size;
78  const std::array<Size2D, 8> supported_tile_sizes = { { Size2D(2U, 2U), Size2D(4U, 4U), Size2D(1U, 6U), Size2D(6U, 1U), Size2D(4, 1), Size2D(1, 4), Size2D(2, 1), Size2D(1, 2) } };
79  ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_tile_sizes) == std::find(std::begin(supported_tile_sizes), std::end(supported_tile_sizes), output_tile));
80 
81  // Checks performed when output is configured
82  if(output->total_size() != 0)
83  {
84  const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info));
85 
86  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
88  }
89 
90  return Status{};
91 }
92 
93 std::pair<Status, Window> validate_and_configure_window_winograd_weight_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
94 {
95  // Output tensor auto inizialitation if not yet initialized
96  auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info)));
97  const Window win = calculate_max_window(*input, Steps(), true /* skip border*/);
98  return std::make_pair(Status{}, win);
99 }
100 
101 Status validate_arguments_winograd_input_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
102 {
103  const Size2D &kernel_dims = winograd_info.kernel_size;
104  const PadStrideInfo &conv_info = winograd_info.convolution_info;
108  ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd input transform only supports unit strides");
109  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(kernel_dims.width, kernel_dims.height)),
110  "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
111 
112  // Validate configured output
113  if(output->total_size() != 0)
114  {
115  const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info);
116 
119  }
120 
121  return Status{};
122 }
123 
124 std::pair<Status, Window> validate_and_configure_window_winograd_input_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
125 {
126  const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info);
127  // Output auto inizialitation if not yet initialized
128  auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape));
129  return std::make_pair(Status{}, calculate_max_window(*input, Steps(), true));
130 }
131 
132 Status validate_arguments_winograd_output_trans(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info)
133 {
134  const PadStrideInfo &conv_info = winograd_info.convolution_info;
135  const Size2D kernel_dims = winograd_info.kernel_size;
136 
137  // Number of tiles along the X and Y direction
138  const unsigned int num_tiles_x = std::ceil((winograd_info.input_dimensions.x() - (kernel_dims.width - 1) + conv_info.pad_left() + conv_info.pad_right()) / static_cast<float>
139  (winograd_info.output_tile_size.width));
140  const unsigned int num_tiles_y = std::ceil((winograd_info.input_dimensions.y() - (kernel_dims.height - 1) + conv_info.pad_top() + conv_info.pad_bottom()) / static_cast<float>
141  (winograd_info.output_tile_size.height));
142  const Size2D num_tiles = Size2D(num_tiles_x, num_tiles_y);
143 
147  ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != num_tiles.area());
148  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(kernel_dims.width, kernel_dims.height)),
149  "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
150 
151  const std::array<unsigned int, 3> supported_gemm_sizes = { { 8U, 16U, 36U } };
152  ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_gemm_sizes) == std::find(std::begin(supported_gemm_sizes), std::end(supported_gemm_sizes), input->dimension(2)));
153  ARM_COMPUTE_UNUSED(kernel_dims);
154  if(bias != nullptr)
155  {
157  ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0));
158  ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() != size_t(1));
159  }
160 
161  // Checks performed when output is configured
162  if(output->total_size() != 0)
163  {
164  const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info));
165  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
167  }
168  return Status{};
169 }
170 
171 std::pair<Status, Window> validate_and_configure_window_winograd_output_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
172 {
173  // Output tensor auto initialization if not yet initialized
174  auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info)));
175 
176  return std::make_pair(Status{}, calculate_max_window(*input, Steps(), true));
177 }
178 } // namespace
179 
181 {
184  const DataLayout data_layout = input->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  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(weights->dimension(width_idx), weights->dimension(height_idx))),
188  "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
190  return Status{};
191 }
192 
193 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
195 {
196  const KernelShape shape(num_output_channels, KernelRows, KernelCols, num_input_channels);
197  // WinogradConv returns the size in bytes, we divide by `sizeof(T)` to express that in units of T
198  return static_cast<unsigned int>(WinogradConv::get_kernel_storage_size(num_input_channels, num_output_channels) / sizeof(T));
199 }
200 
201 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
203  : _transform(nullptr), _num_output_channels(0), _matrix_stride(0)
204 {
205 }
206 
207 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
209 {
210  return WinogradConv::get_kernel_matrix_stride(num_input_channels, num_output_channels);
211 }
212 
213 #ifndef DOXYGEN_SKIP_THIS
214 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
216  const ITensorInfo *weights_hwio,
217  ITensorInfo *output,
218  const int matrix_stride, /** Stride across matrices in the output. */
219  const int num_output_channels, /** Number of filters. */
220  const int num_input_channels) /** Number of channels in each filter. */
221 {
222  ARM_COMPUTE_UNUSED(weights_hwio, output);
223 
224  _transform = std::make_unique<WeightsTransform>(num_output_channels, num_input_channels);
225  _num_output_channels = num_output_channels;
226  _matrix_stride = matrix_stride;
227 
228  Window win;
229  auto win_last = _transform->get_window();
230  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
231  ICpuKernel::configure(win);
232 }
233 #endif /* DOXYGEN_SKIP_THIS */
234 
235 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
237 {
238  ARM_COMPUTE_UNUSED(info);
240  ARM_COMPUTE_ERROR_ON(tensors.empty());
241 
242  const size_t fst = window.x().start();
243  const size_t lst = window.x().end();
244 
245  const ITensor *weights_hwio = tensors.get_const_tensor(TensorType::ACL_SRC);
246  ITensor *output = tensors.get_tensor(TensorType::ACL_DST);
247 
248  _transform->set_weight_tensor(weights_hwio->buffer());
249  const int matrix_row_stride = roundup(_num_output_channels, WinogradConv::N_BLOCK);
250  _transform->set_output_matrices(output->buffer(), _matrix_stride, matrix_row_stride);
251  _transform->set_working_space(output->buffer());
252 
253  _transform->run(fst, lst);
254 }
255 
256 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
258 {
259  return false;
260 }
261 
262 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
264  const WinogradInfo &winograd_info)
265 {
266  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_weight_trans(input, output, winograd_info));
267  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_weight_trans(input->clone().get(), output->clone().get(), winograd_info).first);
268  return Status{};
269 }
270 
276 
281 
282 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
284 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
285 
286 // Input transform
287 
288 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
290  int num_batches, /* Number of batches in the input tensor. */
291  int num_channels, /* Number of feature maps in the input tensor. */
292  int num_rows, /* Number of rows in each feature map. */
293  int num_cols, /* Number of columns in each feature map. */
294  bool same_padding /* Use "SAME" padding, otherwise use "VALID". */
295 ) const
296 {
297  // Construct shapes for the input and kernel tensors.
298  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels);
299  const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
300  // Return the size, converted into units of TIn
301  return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding) / sizeof(T));
302 }
303 
304 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
306 {
307  return _transform->get_working_space_size(num_threads);
308 }
309 
310 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
312  int num_batches, /* Number of batches in the input tensor. */
313  int num_channels, /* Number of feature maps in the input tensor. */
314  int num_rows, /* Number of rows in each feature map. */
315  int num_cols, /* Number of columns in each feature map. */
316  bool same_padding /* Use "SAME" padding, otherwise use "VALID". */) const
317 {
318  return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
319 }
320 
321 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
323  : _transform(nullptr), _num_channels(0), _matrix_stride(0)
324 {
325 }
326 
327 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
329  const ITensorInfo *input_nhwc,
330  const int num_batches, /* Number of batches in input tensor. */
331  const int num_rows, /* Number of rows in input tensor. */
332  const int num_cols, /* Number of columns in input tensor. */
333  const int num_channels, /* Number of channels in input tensor. */
334  const PaddingType padding, /* Padding type. */
335  ITensorInfo *output, /* Base of output matrices. */
336  const int matrix_stride, /* Stride between output matrices. */
337  ITensorInfo *workspace)
338 {
339  ARM_COMPUTE_UNUSED(input_nhwc, output, matrix_stride, workspace);
340 
341  _num_channels = num_channels;
342  _matrix_stride = matrix_stride;
343 
344  const int padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
345  const int padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
346  const int padding_bottom = (padding == PADDING_SAME) ? iceildiv(KernelRows - 1, 2) : 0;
347  const int padding_right = (padding == PADDING_SAME) ? iceildiv(KernelCols - 1, 2) : 0;
348 
349  _transform = std::make_unique<InputTransform>(
350  KernelRows,
351  KernelCols,
352  num_batches,
353  num_rows,
354  num_cols,
355  num_channels,
356  padding_top, /**< Padding to apply to the top of the image. */
357  padding_left, /**< Padding to apply to the left of the image. */
358  padding_bottom, /**< Padding to apply to the bottom of the image. */
359  padding_right /**< Padding to apply to the right of the image. */
360  );
361 
362  Window win;
363  auto win_last = _transform->get_window();
364  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
365  ICpuKernel::configure(win);
366 }
367 
368 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
370 {
371  ARM_COMPUTE_UNUSED(info);
373  ARM_COMPUTE_ERROR_ON(tensors.empty());
374 
375  const ITensor *input_nhwc = tensors.get_const_tensor(TensorType::ACL_SRC);
376  const ITensor *workspace = tensors.get_const_tensor(TensorType::ACL_INT);
377  ITensor *output = tensors.get_tensor(TensorType::ACL_DST);
378 
379  const int element_size_in_bytes = input_nhwc->info()->element_size();
380  const int input_col_stride = input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
381  const int input_row_stride = input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
382  const int input_batch_stride = input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
383  const auto input_nhwc_ptr = reinterpret_cast<const T *>(input_nhwc->buffer() + input_nhwc->info()->offset_first_element_in_bytes());
384  auto output_ptr = reinterpret_cast<T *>(output->buffer() + output->info()->offset_first_element_in_bytes());
385  ARM_COMPUTE_ERROR_ON_NULLPTR(output_ptr);
386 
387  _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
388  _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
389 
390  _transform->set_working_space(workspace->buffer());
391 
392  // The code below cannot be moved to configure because biases hasn't been allocated at that point
393  const size_t fst = window.x().start();
394  const size_t lst = window.x().end();
395  _transform->run(fst, lst, info.thread_id);
396 }
397 
398 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
400  const WinogradInfo &winograd_info)
401 {
402  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info));
403  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_input_trans(input->clone().get(), output->clone().get(), winograd_info).first);
404 
405  return Status{};
406 }
407 
413 
418 
419 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
421 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
422 
423 // Output transform
424 
425 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
427  int num_batches, /* Number of batches in the output tensor. */
428  int num_rows, /* Number of rows in each feature map of the input tensor. */
429  int num_cols, /* Number of columns in each feature map of the input tensor. */
430  int num_output_channels /* Number of feature maps in the output tensor. */
431 ) const
432 {
433  // Construct shapes for the input and kernel tensors.
434  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1);
435  const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
436  // Return the size, converted into units of TOut
437  return static_cast<unsigned int>(
438  WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels) / sizeof(T));
439 }
440 
441 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
443  : _transform(nullptr), _matrix_stride(0), _matrix_row_stride(0)
444 {
445 }
446 
447 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
449 {
450  return _transform->get_working_space_size(num_threads);
451 }
452 
453 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
455  int num_batches, /* Number of batches in the output tensor. */
456  int num_rows, /* Number of rows in each feature map of the input tensor. */
457  int num_cols, /* Number of columns in each feature map of the input tensor. */
458  int num_output_channels /* Number of feature maps in the output tensor. */
459 ) const
460 {
461  return WinogradConv::get_output_matrix_stride(num_batches, num_rows, num_cols, num_output_channels);
462 }
463 
464 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
466  int num_rows, /* Number of rows in each feature map of the input tensor. */
467  int num_cols, /* Number of columns in each feature map of the input tensor. */
468  bool padding_same) const
469 {
470  return WinogradConv::get_output_shape(std::make_pair<unsigned int, unsigned int>(num_rows, num_cols), padding_same);
471 }
472 
473 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
475  const ITensorInfo *biases,
476  const ITensorInfo *transformed_output,
477  const int matrix_stride,
478  ITensorInfo *output_nhwc,
479  const int num_batches,
480  const int num_rows,
481  const int num_cols,
482  const int num_channels,
483  ITensorInfo *workspace,
484  const arm_gemm::Activation &activation)
485 {
486  ARM_COMPUTE_UNUSED(biases, transformed_output, output_nhwc, num_batches, num_rows, num_cols, workspace, activation);
487 
488  _matrix_stride = matrix_stride;
489  _matrix_row_stride = roundup(num_channels, WinogradConv::N_BLOCK);
490 
491  // We don't have the biases buffer at this stage as it hasn't been allocated, we pass in nullptr OutputTransform is only used here to compute the window
492  _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
493  Window win;
494  auto win_last = _transform->get_window();
495  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
496 
497  ICpuKernel::configure(win);
498 }
499 
500 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
502 {
504  ARM_COMPUTE_ERROR_ON(tensors.empty());
505 
506  const ITensor *biases = tensors.get_const_tensor(TensorType::ACL_SRC_0);
507  const ITensor *transformed_output = tensors.get_const_tensor(TensorType::ACL_SRC_1);
508  ITensor *workspace = tensors.get_tensor(TensorType::ACL_INT);
509  ITensor *dst_nhwc = tensors.get_tensor(TensorType::ACL_DST);
510 
511  const int out_batch_stride = dst_nhwc->info()->strides_in_bytes()[3] / sizeof(T);
512  const int out_row_stride = dst_nhwc->info()->strides_in_bytes()[2] / sizeof(T);
513  const int out_col_stride = dst_nhwc->info()->strides_in_bytes()[1] / sizeof(T);
514 
515  _transform->set_input_matrices(transformed_output->buffer(), _matrix_stride, _matrix_row_stride);
516  _transform->set_bias((biases ? reinterpret_cast<T *>(biases->buffer() + biases->info()->offset_first_element_in_bytes()) : nullptr));
517  _transform->set_output_tensor(dst_nhwc->buffer() + dst_nhwc->info()->offset_first_element_in_bytes(), out_batch_stride, out_row_stride, out_col_stride);
518  _transform->set_working_space(workspace->buffer());
519 
520  // The code below cannot be moved to configure because biases hasn't been allocated at that point
521  const size_t fst = window.x().start();
522  const size_t lst = window.x().end();
523  _transform->run(fst, lst, info.thread_id);
524 }
525 
526 template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
528  const WinogradInfo &winograd_info)
529 {
530  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_output_trans(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info));
531  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_output_trans(input->clone().get(), output->clone().get(), winograd_info).first);
532 
533  return Status{};
534 }
535 
541 
546 
547 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
549 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
550 } // namespace cpu
551 } // namespace arm_compute
virtual void configure(const ITensorInfo *weights_hwio, ITensorInfo *output, const int matrix_stride, const int num_output_channels, const int num_input_channels)=0
Configure the weights transform kernel.
T roundup(const T a, const T b)
Definition: utils.hpp:70
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
unsigned int get_weight_storage_size(int num_output_channels, int num_input_channels) const override
Determine how much memory (in units of T) to allocate for the transformed weights.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd input transform shape.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
Static function to check if given info will lead to a valid configuration of CpuWinogradConv2dTransfo...
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
bool empty() const
Checks if pack is empty.
Definition: ITensorPack.cpp:80
Winograd information.
Definition: Types.h:2193
void configure(const ITensorInfo *biases, const ITensorInfo *transformed_output, const int matrix_stride, ITensorInfo *output_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, ITensorInfo *workspace, const arm_gemm::Activation &activation) override
Configure the output transform kernel.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
virtual DataType data_type() const =0
Data type used for each element of the tensor.
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
unsigned int get_working_space_size(unsigned int num_threads) const override
Get the working space required to perform the transformation.
unsigned int get_working_space_size(unsigned int num_threads) const override
Get the working space required to perform the transformation.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
Status class.
Definition: Error.h:52
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
Interface for CPU tensor.
Definition: ITensor.h:36
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:284
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
const DataType data_type
Definition: Im2Col.cpp:150
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
void configure(const ITensorInfo *input_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, const PaddingType padding, ITensorInfo *output, const int matrix_stride, ITensorInfo *workspace) override
Configure the output transform kernel.
int get_matrix_stride(int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const override
Gets the stride between matrices in the input worspace.
const size_t input_width
const auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static Status validate(const ITensorInfo *input, const ITensorInfo *weights)
Static function to check if given info will lead to a valid configuration of CpuWinogradConv2dTransfo...
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
Static function to check if given info will lead to a valid configuration of CpuWinogradConv2dTransfo...
Kernel to perform Winograd weights transform.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
int get_matrix_stride(int num_batches, int num_rows, int num_cols, int num_output_channels) const override
Gets the stride between matrices in the output worspace.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
TensorShape compute_winograd_filter_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd filter transform shape.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor...
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info)
Static function to check if given info will lead to a valid configuration of CpuWinogradConv2dTransfo...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:64
Information about executing thread and CPU.
Definition: CPPTypes.h:158
TensorShape compute_winograd_output_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd output transform shape.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
unsigned int get_input_storage_size(int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const override
Determine how much memory (in units of TIn) to allocate for the transformed input.
const size_t input_height
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
Kernel to perform Winograd input transform.
int get_matrix_stride(int num_output_channels, int num_input_channels) const override
Gets the stride between matrices in the input worspace.
bool is_parallelisable() const override
Indicates whether or not the kernel is parallelisable.
Kernel to perform Winograd output transform.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
unsigned int get_output_storage_size(int num_batches, int num_rows, int num_cols, int num_output_channels) const override
Determine how much memory (in units of TOut) to allocate for the (Winograd domain) output...
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
DataType
Available data types.
Definition: Types.h:79
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
std::pair< unsigned int, unsigned int > get_output_shape(int num_rows, int num_cols, bool padding_same) const override
Get the output shape of a convolution.
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
Describe a multidimensional execution window.
Definition: Window.h:39
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145