blob: 89c80c55ef36c6b0b08fb55b322ca1932073ede4 [file] [log] [blame]
Gian Marco Iodiced2fab732018-03-02 11:18:12 +00001/*
Gian Marco Iodice905a3c12023-04-14 12:20:58 +01002 * Copyright (c) 2018-2023 Arm Limited.
Gian Marco Iodiced2fab732018-03-02 11:18:12 +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/gpu/cl/kernels/ClWinogradOutputTransformKernel.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000025
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000026#include "arm_compute/core/CL/CLHelpers.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000027#include "arm_compute/core/CL/CLKernelLibrary.h"
28#include "arm_compute/core/CL/ICLTensor.h"
29#include "arm_compute/core/Helpers.h"
30#include "arm_compute/core/IAccessWindow.h"
31#include "arm_compute/core/TensorInfo.h"
32#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010033#include "arm_compute/core/utils/ActivationFunctionUtils.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000034#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Matthew Bentham314d3e22023-06-23 10:53:52 +000035#include "arm_compute/core/utils/StringUtils.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010036#include "arm_compute/core/Validate.h"
37#include "arm_compute/core/Window.h"
38
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010039#include "src/core/AccessWindowStatic.h"
40#include "src/core/CL/CLValidate.h"
41#include "src/core/helpers/AutoConfiguration.h"
42#include "src/core/helpers/WindowHelpers.h"
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010043#include "support/Cast.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000044#include "support/StringSupport.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000045
46#include <cmath>
47
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000048using namespace arm_compute::misc::shape_calculator;
49
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010050namespace arm_compute
51{
52namespace opencl
53{
54namespace kernels
55{
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000056namespace
57{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010058Status validate_arguments(const ITensorInfo *input,
59 const ITensorInfo *bias,
60 const ITensorInfo *output,
61 const WinogradInfo &winograd_info,
62 const ActivationLayerInfo &act_info)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000063{
Michele Di Giorgiodf2c7212019-10-11 14:01:35 +010064 ARM_COMPUTE_UNUSED(act_info);
Vidhya Sudhan Loganathan71ecf392018-08-31 16:10:16 +010065 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16);
66 ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input);
Gian Marco Iodice247f52c2018-03-22 11:24:56 +000067
Georgios Pinitasc084f0d2018-06-11 17:43:31 +010068 ARM_COMPUTE_RETURN_ERROR_ON(output->data_layout() != winograd_info.output_data_layout);
69
Gian Marco Iodice247f52c2018-03-22 11:24:56 +000070 const PadStrideInfo conv_info = winograd_info.convolution_info;
71 const Size2D output_tile_size = winograd_info.output_tile_size;
72 const Size2D kernel_size = winograd_info.kernel_size;
73 const Size2D input_dimensions = winograd_info.input_dimensions;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010074 const unsigned int num_channels = (winograd_info.kernel_size.width + winograd_info.output_tile_size.width - 1) *
75 (winograd_info.kernel_size.height + winograd_info.output_tile_size.height - 1);
Gian Marco Iodice247f52c2018-03-22 11:24:56 +000076
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010077 ARM_COMPUTE_RETURN_ERROR_ON_MSG(
78 !cl_winograd_convolution_layer_supported(output_tile_size, kernel_size, winograd_info.output_data_layout),
79 "Winograd output transform not supported");
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +010080 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->dimension(2) != num_channels, "Wrong number of channels");
Gian Marco Iodice247f52c2018-03-22 11:24:56 +000081
82 // Compute number of elements to process in the X and Y direction
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +010083 // Compute the number of output tiles along the x and y direction of size "output_tile_size"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010084 const Size2D num_tiles =
85 compute_winograd_convolution_tiles(input_dimensions, kernel_size, output_tile_size, conv_info);
Gian Marco Iodice247f52c2018-03-22 11:24:56 +000086
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +010087 ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != static_cast<unsigned int>((num_tiles.area())));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000088
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010089 if (bias != nullptr)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000090 {
91 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias);
92 ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0));
93 }
94
95 // Checks performed when output is configured
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010096 if (output->total_size() != 0)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000097 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010098 const TensorInfo tensor_info_output =
99 input->clone()->set_tensor_shape(compute_winograd_output_transform_shape(*input, winograd_info));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000100
101 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
102 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
103 }
104
105 return Status{};
106}
107
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100108std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input,
109 ITensorInfo *bias,
110 ITensorInfo *output,
111 const Size2D &output_tile_size)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000112{
113 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Gian Marco Iodice5f910412020-10-20 09:14:45 +0100114 ARM_COMPUTE_UNUSED(bias);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000115
Gian Marco Iodice905a3c12023-04-14 12:20:58 +0100116 unsigned int num_elems_processed_per_iteration = 1;
117
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100118 if (input->data_layout() == DataLayout::NHWC)
Gian Marco Iodice905a3c12023-04-14 12:20:58 +0100119 {
120 // In the case of FP16 computation, we can perform more
121 // output feature maps in a single work-item.
122 // From experiments, num_elems_processed_per_iteration = 2 looks good for fp16 to
123 // improve the performance. However, in order to make the implementation simpler,
124 // we set num_elems_processed_per_iteration = 2 only when the OFMs are multiple of 2.
125 const DataType dt = input->data_type();
126 const size_t dim0 = input->dimension(0);
127 const bool cond = dt == DataType::F16 && ((dim0 % 2) == 0);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100128 if (cond)
Gian Marco Iodice905a3c12023-04-14 12:20:58 +0100129 {
130 num_elems_processed_per_iteration = 2;
131 }
132 }
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000133
134 Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
135 bool window_changed = false;
136
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100137 if (output->data_layout() == DataLayout::NCHW)
Georgios Pinitasc084f0d2018-06-11 17:43:31 +0100138 {
Gian Marco Iodice5f910412020-10-20 09:14:45 +0100139 const int output_static_window_end_x = ceil_to_multiple(output->dimension(0), output_tile_size.width);
140 const int output_static_window_end_y = ceil_to_multiple(output->dimension(1), output_tile_size.height);
Georgios Pinitasc084f0d2018-06-11 17:43:31 +0100141
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100142 AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration,
143 num_elems_processed_per_iteration);
Gian Marco Iodice5f910412020-10-20 09:14:45 +0100144 AccessWindowStatic output_access(output, 0, 0, output_static_window_end_x, output_static_window_end_y);
145 window_changed = update_window_and_padding(win, input_access, output_access);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000146 }
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000147
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100148 Status err =
149 (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000150 return std::make_pair(err, win);
151}
152} // namespace
153
Giorgio Arena4a95bba2021-06-28 11:00:27 +0100154ClWinogradOutputTransformKernel::ClWinogradOutputTransformKernel()
155{
156 _type = CLKernelType::WINOGRAD;
157}
158
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100159void ClWinogradOutputTransformKernel::configure(const ClCompileContext &compile_context,
160 ITensorInfo *src,
161 ITensorInfo *bias,
162 ITensorInfo *dst,
163 const WinogradInfo &winograd_info,
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100164 const ActivationLayerInfo &act_info)
165{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100166 ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000167
168 // Output tensor auto initialization if not yet initialized
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100169 auto_init_if_empty(*dst,
170 src->clone()->set_tensor_shape(compute_winograd_output_transform_shape(*src, winograd_info)));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000171
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100172 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, bias, dst, winograd_info, act_info));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000173
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000174 // Configure kernel window
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100175 auto win_config = validate_and_configure_window(src, bias, dst, winograd_info.output_tile_size);
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000176 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100177 IClKernel::configure_internal(win_config.second);
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000178
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100179 auto padding_info = get_padding_info({src, bias, dst});
Gian Marco Iodice5f910412020-10-20 09:14:45 +0100180
Georgios Pinitas7191aaa2019-04-03 17:01:26 +0100181 _is_nhwc = winograd_info.output_data_layout == DataLayout::NHWC;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000182
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000183 // Compute num_tiles_x
184 const Size2D input_dimensions = winograd_info.input_dimensions;
185 const Size2D kernel_size = winograd_info.kernel_size;
186 const Size2D output_tile_size = winograd_info.output_tile_size;
187 const PadStrideInfo conv_info = winograd_info.convolution_info;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100188 const int idx_width = get_data_layout_dimension_index(winograd_info.output_data_layout, DataLayoutDimension::WIDTH);
189 const int idx_height =
190 get_data_layout_dimension_index(winograd_info.output_data_layout, DataLayoutDimension::HEIGHT);
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100191
192 // Compute the number of output tiles along the x and y direction of size "output_tile_size"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100193 const Size2D num_tiles =
194 compute_winograd_convolution_tiles(input_dimensions, kernel_size, output_tile_size, conv_info);
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100195 const size_t total_batches = dst->tensor_shape().total_size_upper(3);
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000196
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000197 // Set build options
198 CLBuildOptions build_opts;
Usama Arif6a98a6e2019-05-10 17:07:27 +0100199 build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_info.activation())));
Manuel Bottini0d0028c2018-10-02 16:41:52 +0100200 build_opts.add_option_if(act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(act_info.a()));
201 build_opts.add_option_if(act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(act_info.b()));
202
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100203 if ((output_tile_size.x() == 2) || (output_tile_size.x() == 1 && output_tile_size.y() == 2))
Manuel Bottini0d0028c2018-10-02 16:41:52 +0100204 {
205 build_opts.add_option("-DVEC_SIZE=2");
206 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100207 else if ((output_tile_size.x() == 4) || (output_tile_size.x() == 1 && output_tile_size.y() == 4))
Manuel Bottini0d0028c2018-10-02 16:41:52 +0100208 {
209 build_opts.add_option("-DVEC_SIZE=4");
210 }
211
Gian Marco Iodiced8804fd2022-06-28 16:55:19 +0100212 _num_tiles_x = num_tiles.width;
213
Gunes Bayircc034192022-08-10 15:58:51 +0100214 // Conditions of -cl-fast-relaxed-math causing accuracy issues can be traced from COMPMID-5324
215 const GPUTarget gpu_target = get_target();
216 const auto act_function = act_info.activation();
217 const auto src_data_type = src->data_type();
218
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100219 if ((gpu_target != GPUTarget::G71 && (gpu_target & GPUTarget::GPU_ARCH_MASK) == GPUTarget::BIFROST) &&
220 (act_function == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU ||
221 act_function == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) &&
222 (src_data_type == DataType::F32 || src_data_type == DataType::F16))
Gunes Bayircc034192022-08-10 15:58:51 +0100223 {
224 // -cl-fast-relaxed-math also sets -cl-finite-math-only and -cl-unsafe-math-optimizations
225 // to disable -cl-finite-math-only, we only include -cl-unsafe-math-optimizations
226 build_opts.add_option("-cl-unsafe-math-optimizations");
227 }
228 else
229 {
230 build_opts.add_option("-cl-fast-relaxed-math");
231 }
232
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100233 if (_is_nhwc)
ramelg01bb6877a2022-02-08 09:38:17 +0000234 {
235 build_opts.add_option_if(bias != nullptr, std::string("-DHAS_BIAS"));
ramelg01bb6877a2022-02-08 09:38:17 +0000236 build_opts.add_option("-DN0=" + support::cpp11::to_string(win_config.second.x().step()));
237 build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width));
238 build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height));
Gunes Bayircc034192022-08-10 15:58:51 +0100239 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src_data_type));
Gian Marco Iodice905a3c12023-04-14 12:20:58 +0100240 build_opts.add_option_if(total_batches > 1, "-DIS_BATCHED");
ramelg01bb6877a2022-02-08 09:38:17 +0000241 build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_HORIZONTAL");
242 build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_VERTICAL");
Gian Marco Iodice0c687042022-06-14 15:13:16 +0100243 build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(_num_tiles_x));
ramelg01bb6877a2022-02-08 09:38:17 +0000244 }
245 else
246 {
247 build_opts.add_option_if(bias != nullptr, std::string("-DHAS_BIAS"));
ramelg01bb6877a2022-02-08 09:38:17 +0000248 build_opts.add_option("-DN0=" + support::cpp11::to_string(win_config.second.x().step()));
249 build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(num_tiles.width));
250 build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width));
251 build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height));
Gunes Bayircc034192022-08-10 15:58:51 +0100252 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src_data_type));
ramelg01bb6877a2022-02-08 09:38:17 +0000253 build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(src->dimension(1)));
254 build_opts.add_option("-DDST_WIDTH=" + support::cpp11::to_string(dst->dimension(idx_width)));
255 build_opts.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(dst->dimension(idx_height)));
256 build_opts.add_option_if(total_batches > 1, "-DSRC_DEPTH=" + support::cpp11::to_string(src->dimension(2)));
257 build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_HORIZONTAL");
258 build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_VERTICAL");
259 }
260
261 // Storing tensor dimensions to be sent later as kernel arguments
Gunes Bayircc034192022-08-10 15:58:51 +0100262 _src_height = src->dimension(1);
263 _dst_width = dst->dimension(idx_width);
264 _dst_height = dst->dimension(idx_height);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000265
266 // Create kernel
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100267 std::string kernel_name = "winograd_output_transform_" + output_tile_size.to_string() + "_" +
268 kernel_size.to_string() + "_" +
269 lower_string(string_from_data_layout(winograd_info.output_data_layout));
ramelg01bb6877a2022-02-08 09:38:17 +0000270
271 // A macro guard to compile ONLY the kernel of interest
272 build_opts.add_option("-D" + upper_string(kernel_name));
273 _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000274
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000275 // Set config_id for enabling LWS tuning
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000276 _config_id = kernel_name;
277 _config_id += "_";
Gunes Bayircc034192022-08-10 15:58:51 +0100278 _config_id += lower_string(string_from_data_type(src_data_type));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000279 _config_id += "_";
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100280 _config_id += support::cpp11::to_string(src->dimension(0));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000281 _config_id += "_";
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100282 _config_id += support::cpp11::to_string(src->dimension(1));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000283 _config_id += "_";
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100284 _config_id += support::cpp11::to_string(dst->dimension(0));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000285 _config_id += "_";
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100286 _config_id += support::cpp11::to_string(dst->dimension(1));
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100287 _config_id += "_";
288 _config_id += lower_string(string_from_data_layout(winograd_info.output_data_layout));
Gian Marco Iodice5f910412020-10-20 09:14:45 +0100289
290 ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info) && _is_nhwc);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000291}
292
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100293Status ClWinogradOutputTransformKernel::validate(const ITensorInfo *src,
294 const ITensorInfo *bias,
295 const ITensorInfo *dst,
296 const WinogradInfo &winograd_info,
297 const ActivationLayerInfo &act_info)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000298{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100299 ARM_COMPUTE_RETURN_ON_ERROR(
300 validate_arguments(src, (bias != nullptr ? bias->clone().get() : nullptr), dst, winograd_info, act_info));
301 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(),
302 (bias != nullptr ? bias->clone().get() : nullptr),
303 dst->clone().get(), winograd_info.output_tile_size)
304 .first);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000305 return Status{};
306}
307
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100308void ClWinogradOutputTransformKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000309{
310 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100311 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IClKernel::window(), window);
312
313 auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0));
314 auto bias = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1));
315 auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000316
Georgios Pinitasc55beee2018-10-23 15:23:23 +0100317 // Collapse window
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100318 Window window_collapsed = window.collapse_if_possible(IClKernel::window(), Window::DimZ);
Georgios Pinitasc55beee2018-10-23 15:23:23 +0100319
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000320 // Get initial windows
Georgios Pinitasc55beee2018-10-23 15:23:23 +0100321 Window slice = window_collapsed.first_slice_window_4D();
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000322 slice.set(Window::DimZ, Window::Dimension(0, 1, 1));
323
324 // Setup output slice
325 Window slice_out(slice);
326 slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
327 slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
328
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100329 if (bias != nullptr)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000330 {
Georgios Pinitasc55beee2018-10-23 15:23:23 +0100331 unsigned int idx1 = 2 * num_arguments_per_4D_tensor();
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000332 Window slice_biases;
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100333 slice_biases.use_tensor_dimensions(bias->info()->tensor_shape());
334 add_1D_tensor_argument(idx1, bias, slice_biases);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000335 }
336
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100337 if (_is_nhwc)
Georgios Pinitasc084f0d2018-06-11 17:43:31 +0100338 {
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100339 unsigned int idx2 = 2 * num_arguments_per_4D_tensor() + ((bias != nullptr) ? num_arguments_per_1D_tensor() : 0);
ramelg01bb6877a2022-02-08 09:38:17 +0000340 _kernel.setArg(idx2++, static_cast<int>(dst->info()->total_size() - dst->info()->strides_in_bytes().y()));
341 _kernel.setArg<cl_int>(idx2++, _src_height);
342 _kernel.setArg<cl_int>(idx2++, _dst_width);
343 _kernel.setArg<cl_int>(idx2++, _dst_height);
Georgios Pinitasc084f0d2018-06-11 17:43:31 +0100344 }
345
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000346 do
347 {
348 unsigned int idx = 0;
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100349 add_4D_tensor_argument(idx, src, slice);
350 add_4D_tensor_argument(idx, dst, slice_out);
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100351 enqueue(queue, *this, slice, lws_hint());
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100352 } while (window.slide_window_slice_3D(slice) && window.slide_window_slice_3D(slice_out));
Gian Marco Iodicee52a3002018-04-11 15:59:10 +0100353}
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100354} // namespace kernels
355} // namespace opencl
Michele Di Giorgiodf2c7212019-10-11 14:01:35 +0100356} // namespace arm_compute