blob: 803af09a674c744456076e83810681ea16c1f396 [file] [log] [blame]
Pablo Tello89519332017-11-17 11:52:36 +00001/*
SiCongLib88272e2021-02-24 15:40:57 +00002 * Copyright (c) 2017-2021 Arm Limited.
Pablo Tello89519332017-11-17 11:52:36 +00003 *
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 */
Georgios Pinitas7891a732021-08-20 21:39:25 +010024#include "src/cpu/kernels/CpuWinogradConv2dKernel.h"
Pablo Tello89519332017-11-17 11:52:36 +000025
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"
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010030#include "arm_compute/core/Validate.h"
31#include "arm_compute/core/Window.h"
32#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010033#include "src/core/NEON/kernels/convolution/common/utils.hpp"
Georgios Pinitas40f51a62020-11-21 03:04:18 +000034#include "src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010035#include "src/core/helpers/AutoConfiguration.h"
36#include "src/core/helpers/WindowHelpers.h"
Pablo Tello3d4968a2017-12-04 15:03:35 +000037
Georgios Pinitas40f51a62020-11-21 03:04:18 +000038#include <memory>
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +010039
Pablo Tello89519332017-11-17 11:52:36 +000040namespace arm_compute
41{
Michalis Spyrou96f977e2021-07-01 12:20:56 +010042namespace cpu
43{
Pablo Tello52140b42018-01-30 14:48:11 +000044//Batched Gemms
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010045
46namespace
47{
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010048inline bool is_kernel_size_supported(DataType data_type, Size2D size)
Pablo Tellobda6e4b2018-08-22 11:40:33 +010049{
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010050 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 }
Pablo Tellobda6e4b2018-08-22 11:40:33 +010062}
63
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +010064Status validate_arguments_winograd_weight_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010065{
66 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
67 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010068 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010069
Pablo Tellobda6e4b2018-08-22 11:40:33 +010070 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);
Georgios Pinitas5ce897f2020-04-29 11:44:10 +010074 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");
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010076 ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > 4);
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +010077 const Size2D &output_tile = winograd_info.output_tile_size;
Pablo Tello000d33a2018-09-03 16:59:20 +010078 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) } };
Pablo Tellobda6e4b2018-08-22 11:40:33 +010079 ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_tile_sizes) == std::find(std::begin(supported_tile_sizes), std::end(supported_tile_sizes), output_tile));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010080
81 // Checks performed when output is configured
82 if(output->total_size() != 0)
83 {
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +010084 const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010085
86 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
87 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
88 }
89
90 return Status{};
91}
92
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +010093std::pair<Status, Window> validate_and_configure_window_winograd_weight_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010094{
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010095 // Output tensor auto inizialitation if not yet initialized
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +010096 auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info)));
morgolockc6d9a8b2019-12-23 10:45:59 +000097 const Window win = calculate_max_window(*input, Steps(), true /* skip border*/);
98 return std::make_pair(Status{}, win);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +010099}
100
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100101Status validate_arguments_winograd_input_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100102{
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100103 const Size2D &kernel_dims = winograd_info.kernel_size;
104 const PadStrideInfo &conv_info = winograd_info.convolution_info;
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100105 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
106 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100107 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100108 ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd input transform only supports unit strides");
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100109 ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(kernel_dims.width, kernel_dims.height)),
Pablo Tellobda6e4b2018-08-22 11:40:33 +0100110 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100111
112 // Validate configured output
113 if(output->total_size() != 0)
114 {
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100115 const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100116
117 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape);
118 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
119 }
120
121 return Status{};
122}
123
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100124std::pair<Status, Window> validate_and_configure_window_winograd_input_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100125{
morgolockc6d9a8b2019-12-23 10:45:59 +0000126 const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100127 // Output auto inizialitation if not yet initialized
128 auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape));
morgolockc6d9a8b2019-12-23 10:45:59 +0000129 return std::make_pair(Status{}, calculate_max_window(*input, Steps(), true));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100130}
131
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100132Status validate_arguments_winograd_output_trans(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100133{
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100134 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
Vidhya Sudhan Loganathancb0010b2018-05-11 16:23:53 +0100138 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));
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100142 const Size2D num_tiles = Size2D(num_tiles_x, num_tiles_y);
143
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100144 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
145 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100146 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100147 ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != num_tiles.area());
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100148 ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(kernel_dims.width, kernel_dims.height)),
Pablo Tellobda6e4b2018-08-22 11:40:33 +0100149 "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)));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100153 ARM_COMPUTE_UNUSED(kernel_dims);
154 if(bias != nullptr)
155 {
156 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias);
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 {
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100164 const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100165 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
166 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
167 }
168 return Status{};
169}
170
morgolockc6d9a8b2019-12-23 10:45:59 +0000171std::pair<Status, Window> validate_and_configure_window_winograd_output_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100172{
173 // Output tensor auto initialization if not yet initialized
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100174 auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info)));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100175
morgolockc6d9a8b2019-12-23 10:45:59 +0000176 return std::make_pair(Status{}, calculate_max_window(*input, Steps(), true));
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100177}
178} // namespace
Pablo Tellod6ca4782018-01-23 09:36:04 +0000179
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100180Status ICpuWinogradConv2dTransformWeightsKernel::validate(const ITensorInfo *input, const ITensorInfo *weights)
Pablo Tellobda6e4b2018-08-22 11:40:33 +0100181{
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100182 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
Pablo Tellobda6e4b2018-08-22 11:40:33 +0100183 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
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);
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100187 ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(weights->dimension(width_idx), weights->dimension(height_idx))),
Pablo Tellobda6e4b2018-08-22 11:40:33 +0100188 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
189 ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4);
190 return Status{};
191}
192
Pablo Tellof6c572c2018-02-14 12:47:30 +0000193template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100194unsigned int CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_weight_storage_size(int num_output_channels, int num_input_channels) const
Pablo Tellod6ca4782018-01-23 09:36:04 +0000195{
Pablo Tello7df27862018-05-30 11:44:26 +0100196 const KernelShape shape(num_output_channels, KernelRows, KernelCols, num_input_channels);
Georgios Pinitas87a74ef2021-08-20 17:26:45 +0100197 // 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));
Pablo Tello52140b42018-01-30 14:48:11 +0000199}
200
Pablo Tellof6c572c2018-02-14 12:47:30 +0000201template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100202CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::CpuWinogradConv2dTransformWeightsKernel()
203 : _transform(nullptr), _num_output_channels(0), _matrix_stride(0)
Pablo Tello52140b42018-01-30 14:48:11 +0000204{
205}
206
Pablo Tellof6c572c2018-02-14 12:47:30 +0000207template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100208int CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(int num_output_channels, int num_input_channels) const
Pablo Tellof6c572c2018-02-14 12:47:30 +0000209{
Pablo Tello5264b7d2019-10-21 14:25:41 +0100210 return WinogradConv::get_kernel_matrix_stride(num_input_channels, num_output_channels);
Pablo Tellof6c572c2018-02-14 12:47:30 +0000211}
212
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000213#ifndef DOXYGEN_SKIP_THIS
Pablo Tellof6c572c2018-02-14 12:47:30 +0000214template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100215void CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure(
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. */
Pablo Tello52140b42018-01-30 14:48:11 +0000221{
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100222 ARM_COMPUTE_UNUSED(weights_hwio, output);
223
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000224 _transform = std::make_unique<WeightsTransform>(num_output_channels, num_input_channels);
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100225 _num_output_channels = num_output_channels;
226 _matrix_stride = matrix_stride;
Pablo Tello7df27862018-05-30 11:44:26 +0100227
Pablo Tello8f43d742019-03-27 09:28:32 +0000228 Window win;
229 auto win_last = _transform->get_window();
Pablo Tellod6ca4782018-01-23 09:36:04 +0000230 win.set(Window::DimX, Window::Dimension(0, win_last, 1));
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100231 ICpuKernel::configure(win);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000232}
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000233#endif /* DOXYGEN_SKIP_THIS */
Pablo Tellod6ca4782018-01-23 09:36:04 +0000234
Pablo Tellof6c572c2018-02-14 12:47:30 +0000235template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100236void CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
Pablo Tellod6ca4782018-01-23 09:36:04 +0000237{
238 ARM_COMPUTE_UNUSED(info);
239 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100240 ARM_COMPUTE_ERROR_ON(tensors.empty());
241
Pablo Tello8f43d742019-03-27 09:28:32 +0000242 const size_t fst = window.x().start();
243 const size_t lst = window.x().end();
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100244
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());
Pablo Tello8f43d742019-03-27 09:28:32 +0000249 const int matrix_row_stride = roundup(_num_output_channels, WinogradConv::N_BLOCK);
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100250 _transform->set_output_matrices(output->buffer(), _matrix_stride, matrix_row_stride);
251 _transform->set_working_space(output->buffer());
Pablo Tello7df27862018-05-30 11:44:26 +0100252
Pablo Tello8f43d742019-03-27 09:28:32 +0000253 _transform->run(fst, lst);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000254}
255
Pablo Tellof6c572c2018-02-14 12:47:30 +0000256template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100257bool CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::is_parallelisable() const
Pablo Tellod6ca4782018-01-23 09:36:04 +0000258{
259 return false;
260}
261
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100262template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100263Status CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output,
264 const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100265{
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100266 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);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100268 return Status{};
269}
270
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100271template class CpuWinogradConv2dTransformWeightsKernel<float, 2, 2, 3, 3>;
272template class CpuWinogradConv2dTransformWeightsKernel<float, 4, 4, 3, 3>;
273template class CpuWinogradConv2dTransformWeightsKernel<float, 2, 2, 5, 5>;
274template class CpuWinogradConv2dTransformWeightsKernel<float, 1, 6, 1, 3>;
275template class CpuWinogradConv2dTransformWeightsKernel<float, 6, 1, 3, 1>;
Pablo Tello52140b42018-01-30 14:48:11 +0000276
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100277template class CpuWinogradConv2dTransformWeightsKernel<float, 1, 4, 1, 5>;
278template class CpuWinogradConv2dTransformWeightsKernel<float, 4, 1, 5, 1>;
279template class CpuWinogradConv2dTransformWeightsKernel<float, 1, 2, 1, 7>;
280template class CpuWinogradConv2dTransformWeightsKernel<float, 2, 1, 7, 1>;
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100281
282#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100283template class CpuWinogradConv2dTransformWeightsKernel<__fp16, 4, 4, 3, 3>;
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100284#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
285
Pablo Tellod6ca4782018-01-23 09:36:04 +0000286// Input transform
287
Pablo Tellof6c572c2018-02-14 12:47:30 +0000288template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100289unsigned int CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_input_storage_size(
Pablo Tello7df27862018-05-30 11:44:26 +0100290 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". */
Pablo Tellof6c572c2018-02-14 12:47:30 +0000295) const
Pablo Tellod6ca4782018-01-23 09:36:04 +0000296{
Pablo Tello52140b42018-01-30 14:48:11 +0000297 // Construct shapes for the input and kernel tensors.
Pablo Tello7df27862018-05-30 11:44:26 +0100298 const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels);
299 const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
Georgios Pinitas87a74ef2021-08-20 17:26:45 +0100300 // 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));
Pablo Tello52140b42018-01-30 14:48:11 +0000302}
303
Pablo Tellof6c572c2018-02-14 12:47:30 +0000304template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100305unsigned int CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_working_space_size(unsigned int num_threads) const
Pablo Tello8f43d742019-03-27 09:28:32 +0000306{
Georgios Pinitas66341942021-07-30 12:21:07 +0100307 return _transform->get_working_space_size(num_threads);
Pablo Tello8f43d742019-03-27 09:28:32 +0000308}
309
310template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100311int CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(
Pablo Tello5264b7d2019-10-21 14:25:41 +0100312 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
Pablo Tellof6c572c2018-02-14 12:47:30 +0000317{
Pablo Tello5264b7d2019-10-21 14:25:41 +0100318 return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
Pablo Tellof6c572c2018-02-14 12:47:30 +0000319}
320
321template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100322CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::CpuWinogradConv2dTransformInputKernel()
323 : _transform(nullptr), _num_channels(0), _matrix_stride(0)
Pablo Tello52140b42018-01-30 14:48:11 +0000324{
325}
326
Pablo Tellof6c572c2018-02-14 12:47:30 +0000327template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100328void CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure(
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)
Pablo Tello52140b42018-01-30 14:48:11 +0000338{
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100339 ARM_COMPUTE_UNUSED(input_nhwc, output, matrix_stride, workspace);
Pablo Tello8f43d742019-03-27 09:28:32 +0000340
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100341 _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;
Pablo Tello8f43d742019-03-27 09:28:32 +0000348
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000349 _transform = std::make_unique<InputTransform>(
Pablo Tello8f43d742019-03-27 09:28:32 +0000350 KernelRows,
351 KernelCols,
352 num_batches,
353 num_rows,
354 num_cols,
355 num_channels,
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100356 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. */
Pablo Tello8f43d742019-03-27 09:28:32 +0000360 );
361
362 Window win;
363 auto win_last = _transform->get_window();
Pablo Tellod6ca4782018-01-23 09:36:04 +0000364 win.set(Window::DimX, Window::Dimension(0, win_last, 1));
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100365 ICpuKernel::configure(win);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000366}
367
Pablo Tellof6c572c2018-02-14 12:47:30 +0000368template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100369void CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
Pablo Tellod6ca4782018-01-23 09:36:04 +0000370{
371 ARM_COMPUTE_UNUSED(info);
372 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100373 ARM_COMPUTE_ERROR_ON(tensors.empty());
Pablo Tello7df27862018-05-30 11:44:26 +0100374
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100375 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());
Pablo Tello8f43d742019-03-27 09:28:32 +0000385 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
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100390 _transform->set_working_space(workspace->buffer());
Pablo Tello7df27862018-05-30 11:44:26 +0100391
392 // The code below cannot be moved to configure because biases hasn't been allocated at that point
Pablo Tellod6ca4782018-01-23 09:36:04 +0000393 const size_t fst = window.x().start();
394 const size_t lst = window.x().end();
Pablo Tello8f43d742019-03-27 09:28:32 +0000395 _transform->run(fst, lst, info.thread_id);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000396}
Pablo Tello52140b42018-01-30 14:48:11 +0000397
Pablo Tellof6c572c2018-02-14 12:47:30 +0000398template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100399Status CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output,
400 const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100401{
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100402 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);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100404
405 return Status{};
406}
407
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100408template class CpuWinogradConv2dTransformInputKernel<float, 2, 2, 3, 3>;
409template class CpuWinogradConv2dTransformInputKernel<float, 4, 4, 3, 3>;
410template class CpuWinogradConv2dTransformInputKernel<float, 2, 2, 5, 5>;
411template class CpuWinogradConv2dTransformInputKernel<float, 1, 6, 1, 3>;
412template class CpuWinogradConv2dTransformInputKernel<float, 6, 1, 3, 1>;
Pablo Tello52140b42018-01-30 14:48:11 +0000413
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100414template class CpuWinogradConv2dTransformInputKernel<float, 1, 4, 1, 5>;
415template class CpuWinogradConv2dTransformInputKernel<float, 4, 1, 5, 1>;
416template class CpuWinogradConv2dTransformInputKernel<float, 1, 2, 1, 7>;
417template class CpuWinogradConv2dTransformInputKernel<float, 2, 1, 7, 1>;
Pablo Tello000d33a2018-09-03 16:59:20 +0100418
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100419#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100420template class CpuWinogradConv2dTransformInputKernel<__fp16, 4, 4, 3, 3>;
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100421#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
422
Pablo Tellod6ca4782018-01-23 09:36:04 +0000423// Output transform
Pablo Tello52140b42018-01-30 14:48:11 +0000424
Pablo Tellof6c572c2018-02-14 12:47:30 +0000425template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100426unsigned int CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_storage_size(
Pablo Tello5264b7d2019-10-21 14:25:41 +0100427 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. */
Pablo Tellof6c572c2018-02-14 12:47:30 +0000431) const
Pablo Tello52140b42018-01-30 14:48:11 +0000432{
433 // Construct shapes for the input and kernel tensors.
Pablo Tello7df27862018-05-30 11:44:26 +0100434 const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1);
435 const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
Georgios Pinitas87a74ef2021-08-20 17:26:45 +0100436 // Return the size, converted into units of TOut
Pablo Tello52140b42018-01-30 14:48:11 +0000437 return static_cast<unsigned int>(
Georgios Pinitas87a74ef2021-08-20 17:26:45 +0100438 WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels) / sizeof(T));
Pablo Tello52140b42018-01-30 14:48:11 +0000439}
440
Pablo Tellof6c572c2018-02-14 12:47:30 +0000441template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100442CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::CpuWinogradConv2dTransformOutputKernel()
443 : _transform(nullptr), _matrix_stride(0), _matrix_row_stride(0)
Pablo Tellod6ca4782018-01-23 09:36:04 +0000444{
445}
446
Pablo Tellof6c572c2018-02-14 12:47:30 +0000447template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100448unsigned int CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_working_space_size(unsigned int num_threads) const
Pablo Tello8f43d742019-03-27 09:28:32 +0000449{
Georgios Pinitas66341942021-07-30 12:21:07 +0100450 return _transform->get_working_space_size(num_threads);
Pablo Tello8f43d742019-03-27 09:28:32 +0000451}
452
453template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100454int CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(
Pablo Tello5264b7d2019-10-21 14:25:41 +0100455 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
Pablo Tellof6c572c2018-02-14 12:47:30 +0000460{
Pablo Tello5264b7d2019-10-21 14:25:41 +0100461 return WinogradConv::get_output_matrix_stride(num_batches, num_rows, num_cols, num_output_channels);
Pablo Tellof6c572c2018-02-14 12:47:30 +0000462}
Pablo Tello5264b7d2019-10-21 14:25:41 +0100463
Pablo Tellof6c572c2018-02-14 12:47:30 +0000464template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100465std::pair<unsigned int, unsigned int> CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_shape(
Pablo Tello5264b7d2019-10-21 14:25:41 +0100466 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
Pablo Tellof6c572c2018-02-14 12:47:30 +0000469{
Pablo Tello5264b7d2019-10-21 14:25:41 +0100470 return WinogradConv::get_output_shape(std::make_pair<unsigned int, unsigned int>(num_rows, num_cols), padding_same);
Pablo Tellof6c572c2018-02-14 12:47:30 +0000471}
472
473template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100474void CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure(
475 const ITensorInfo *biases,
476 const ITensorInfo *transformed_output,
Pablo Tello5264b7d2019-10-21 14:25:41 +0100477 const int matrix_stride,
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100478 ITensorInfo *output_nhwc,
Pablo Tello5264b7d2019-10-21 14:25:41 +0100479 const int num_batches,
480 const int num_rows,
481 const int num_cols,
482 const int num_channels,
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100483 ITensorInfo *workspace,
Pablo Tello5264b7d2019-10-21 14:25:41 +0100484 const arm_gemm::Activation &activation)
Pablo Tellod6ca4782018-01-23 09:36:04 +0000485{
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100486 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
Pablo Tellod6ca4782018-01-23 09:36:04 +0000491 // 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
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000492 _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
Pablo Tello7282d562018-06-14 15:35:49 +0100493 Window win;
Pablo Tello8f43d742019-03-27 09:28:32 +0000494 auto win_last = _transform->get_window();
Pablo Tellod6ca4782018-01-23 09:36:04 +0000495 win.set(Window::DimX, Window::Dimension(0, win_last, 1));
Pablo Tello7282d562018-06-14 15:35:49 +0100496
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100497 ICpuKernel::configure(win);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000498}
499
Pablo Tellof6c572c2018-02-14 12:47:30 +0000500template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100501void CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
Pablo Tellod6ca4782018-01-23 09:36:04 +0000502{
Pablo Tellod6ca4782018-01-23 09:36:04 +0000503 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100504 ARM_COMPUTE_ERROR_ON(tensors.empty());
Pablo Tellod6ca4782018-01-23 09:36:04 +0000505
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100506 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);
Pablo Tellobda6e4b2018-08-22 11:40:33 +0100510
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100511 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
Pablo Tellod6ca4782018-01-23 09:36:04 +0000520 // 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();
Pablo Tello8f43d742019-03-27 09:28:32 +0000523 _transform->run(fst, lst, info.thread_id);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000524}
525
Pablo Tellof6c572c2018-02-14 12:47:30 +0000526template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100527Status CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output,
528 const WinogradInfo &winograd_info)
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100529{
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +0100530 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_output_trans(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info));
morgolockc6d9a8b2019-12-23 10:45:59 +0000531 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_output_trans(input->clone().get(), output->clone().get(), winograd_info).first);
Vidhya Sudhan Loganathan3ca97862018-04-23 08:20:04 +0100532
533 return Status{};
534}
535
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100536template class CpuWinogradConv2dTransformOutputKernel<float, 2, 2, 3, 3>;
537template class CpuWinogradConv2dTransformOutputKernel<float, 4, 4, 3, 3>;
538template class CpuWinogradConv2dTransformOutputKernel<float, 2, 2, 5, 5>;
539template class CpuWinogradConv2dTransformOutputKernel<float, 1, 6, 1, 3>;
540template class CpuWinogradConv2dTransformOutputKernel<float, 6, 1, 3, 1>;
Pablo Tello52140b42018-01-30 14:48:11 +0000541
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100542template class CpuWinogradConv2dTransformOutputKernel<float, 1, 4, 1, 5>;
543template class CpuWinogradConv2dTransformOutputKernel<float, 4, 1, 5, 1>;
544template class CpuWinogradConv2dTransformOutputKernel<float, 1, 2, 1, 7>;
545template class CpuWinogradConv2dTransformOutputKernel<float, 2, 1, 7, 1>;
Pablo Tello000d33a2018-09-03 16:59:20 +0100546
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100547#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100548template class CpuWinogradConv2dTransformOutputKernel<__fp16, 4, 4, 3, 3>;
Georgios Pinitas5ce897f2020-04-29 11:44:10 +0100549#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100550} // namespace cpu
Pablo Tello89519332017-11-17 11:52:36 +0000551} // namespace arm_compute