1 /*
2 * Copyright (c) 2017-2020 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 */
24 #include "src/core/CL/kernels/CLIm2ColKernel.h"
25
26 #include "arm_compute/core/CL/CLHelpers.h"
27 #include "arm_compute/core/CL/CLKernelLibrary.h"
28 #include "arm_compute/core/CL/ICLTensor.h"
29 #include "arm_compute/core/CL/OpenCL.h"
30 #include "arm_compute/core/Helpers.h"
31 #include "arm_compute/core/TensorInfo.h"
32 #include "arm_compute/core/Validate.h"
33 #include "arm_compute/core/utils/misc/ShapeCalculator.h"
34 #include "src/core/AccessWindowStatic.h"
35 #include "src/core/CL/CLValidate.h"
36 #include "src/core/helpers/AutoConfiguration.h"
37 #include "src/core/helpers/WindowHelpers.h"
38 #include "support/StringSupport.h"
39
40 #include <cmath>
41 #include <tuple>
42 #include <utility>
43
44 namespace arm_compute
45 {
46 using namespace misc::shape_calculator;
47
48 namespace
49 {
50 struct Im2ColConfiguration
51 {
52 std::string kernel_name{};
53 std::set<std::string> build_options{};
54 unsigned int num_elems_processed_per_iteration{};
55 bool is_padding_required_nchw{};
56 };
57
validate_arguments(const ITensorInfo * input,const ITensorInfo * output,const Size2D & kernel_dims,const PadStrideInfo & conv_info,bool has_bias,const Size2D & dilation,unsigned int num_groups)58 Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
59 unsigned int num_groups)
60 {
61 const unsigned int channel_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL);
62
63 ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input);
64 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::F16, DataType::F32);
65 ARM_COMPUTE_RETURN_ERROR_ON(is_data_type_quantized(input->data_type()) && has_bias);
66 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
67 ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1));
68 ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() == DataLayout::UNKNOWN);
69 ARM_COMPUTE_RETURN_ERROR_ON(num_groups == 0);
70 ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() == DataLayout::NHWC && num_groups > 1);
71 ARM_COMPUTE_RETURN_ERROR_ON((input->dimension(channel_idx) % num_groups) != 0);
72
73 // Since there's no implicit padding added, check the total input spatial dimensions (with conv paddings) are big enough for the kernel dimensions
74 const unsigned int width_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH);
75 const unsigned int height_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT);
76 const unsigned total_width = input->dimension(width_idx) + conv_info.pad_left() + conv_info.pad_right();
77 const unsigned total_height = input->dimension(height_idx) + conv_info.pad_top() + conv_info.pad_bottom();
78 ARM_COMPUTE_RETURN_ERROR_ON((total_width < kernel_dims.width) || (total_height < kernel_dims.height));
79
80 if(output->total_size() > 0)
81 {
82 const TensorInfo tensor_info_output = output->clone()->set_tensor_shape(compute_im2col_conv_shape(input, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups));
83 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
84 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
85 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output);
86 }
87
88 return Status{};
89 }
90
validate_and_configure_window(ITensorInfo * input,ITensorInfo * output,const Size2D & kernel_dims,const PadStrideInfo & conv_info,bool has_bias,const Size2D & dilation,unsigned int num_elems_processed_per_iteration,bool is_padding_required_nchw,unsigned int num_groups)91 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
92 unsigned int num_elems_processed_per_iteration, bool is_padding_required_nchw, unsigned int num_groups)
93 {
94 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
95
96 // Output tensor auto initialization if not yet initialized
97 TensorShape expected_output_shape = compute_im2col_conv_shape(input, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups);
98
99 auto_init_if_empty(*output, input->clone()->set_tensor_shape(expected_output_shape));
100
101 const DataLayout data_layout = input->data_layout();
102 const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
103 const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
104 const unsigned int input_width = input->dimension(width_idx);
105 const unsigned int input_height = input->dimension(height_idx);
106
107 // Configure the execute window based on the selected optimal OpenCL kernel
108 bool window_changed = false;
109 Window win;
110
111 if(data_layout == DataLayout::NHWC)
112 {
113 win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
114
115 const int xin_start = 0;
116 const int xin_end = input->dimension(0);
117 const int yin_start = 0;
118 const int yin_end = input->dimension(1);
119
120 const int xout_start = 0;
121 const int xout_end = output->dimension(0);
122 const int yout_start = 0;
123 const int yout_end = output->dimension(1);
124
125 AccessWindowStatic input_access(input, xin_start, yin_start, xin_end, yin_end);
126 AccessWindowStatic output_access(output, xout_start, yout_start, xout_end, yout_end);
127 window_changed = window_changed || update_window_and_padding(win, input_access, output_access);
128 }
129 else
130 {
131 if(is_padding_required_nchw)
132 {
133 const BorderSize border(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left());
134 win = calculate_max_window(*input,
135 Steps(num_elems_processed_per_iteration * conv_info.stride().first, conv_info.stride().second));
136 AccessWindowStatic input_access(input,
137 -border.left,
138 -border.top,
139 ceil_to_multiple(input_width + border.right, kernel_dims.width * num_elems_processed_per_iteration),
140 input_height + border.bottom);
141 window_changed = window_changed || update_window_and_padding(win, input_access);
142 }
143 else
144 {
145 // For the generic case, CLIm2ColKernel doesn't need padding (we do not read out-of-bounds elements) so
146 // update_window_and_padding() can be skipped
147 win = calculate_max_window(*input, Steps());
148 }
149 }
150 output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape()));
151 // set the Z dimension's step same size as the whole dimension so that one can't split across the Z dimension
152 win.set_dimension_step(Window::DimZ, win[Window::DimZ].end() - win[Window::DimZ].start());
153
154 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
155 return std::make_pair(err, win);
156 }
157
configure_opencl_kernel(const ITensorInfo * input,const Size2D & kernel_dims,const PadStrideInfo & conv_info,bool has_bias,const Size2D & dilation,unsigned int num_groups)158 Im2ColConfiguration configure_opencl_kernel(const ITensorInfo *input, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, unsigned int num_groups)
159 {
160 const DataLayout data_layout = input->data_layout();
161 const DataType data_type = input->data_type();
162 const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
163 const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
164 const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
165 const unsigned int input_width = input->dimension(width_idx);
166 const unsigned int input_height = input->dimension(height_idx);
167 const unsigned int input_channel = input->dimension(channel_idx);
168
169 const std::pair<unsigned int, unsigned int> convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation);
170
171 // Im2Col configuration
172 std::string kernel_name = "im2col_generic_";
173 CLBuildOptions build_opts;
174 unsigned int num_elems_processed_per_iteration = 1;
175 bool is_padding_required_nchw = false;
176 const UniformQuantizationInfo qinfo = input->quantization_info().uniform();
177
178 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
179 build_opts.add_option("-DELEMENT_SIZE=" + support::cpp11::to_string(input->element_size()));
180 build_opts.add_option("-DKERNEL_WIDTH=" + support::cpp11::to_string(kernel_dims.width));
181 build_opts.add_option("-DKERNEL_HEIGHT=" + support::cpp11::to_string(kernel_dims.height));
182 build_opts.add_option("-DCONVOLVED_WIDTH=" + support::cpp11::to_string(convolved_dims.first));
183 build_opts.add_option("-DCONVOLVED_HEIGHT=" + support::cpp11::to_string(convolved_dims.second));
184 build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.stride().first));
185 build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.stride().second));
186 build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left()));
187 build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top()));
188 build_opts.add_option("-DPAD_RIGHT=" + support::cpp11::to_string(conv_info.pad_right()));
189 build_opts.add_option("-DPAD_BOTTOM=" + support::cpp11::to_string(conv_info.pad_bottom()));
190 build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input_width));
191 build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(input_height));
192 build_opts.add_option("-DSRC_DEPTH=" + support::cpp11::to_string(input_channel));
193 build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(dilation.x()));
194 build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(dilation.y()));
195 build_opts.add_option_if(num_groups > 1, "-DNUM_GROUPS=" + support::cpp11::to_string(num_groups));
196 build_opts.add_option_if_else(is_data_type_quantized(data_type), "-DPAD_VALUE=" + support::cpp11::to_string(qinfo.offset), "-DPAD_VALUE=0");
197 build_opts.add_option_if(has_bias, "-DHAS_BIAS");
198
199 if(data_layout == DataLayout::NHWC)
200 {
201 num_elems_processed_per_iteration = std::min(2U, input_channel);
202 is_padding_required_nchw = false;
203
204 // Only the 3x3 and 9x9 cases are optimized for NHWC
205 if(kernel_dims == Size2D(3U, 3U))
206 {
207 kernel_name = "im2col3x3_";
208 }
209 else if(kernel_dims == Size2D(9U, 9U))
210 {
211 kernel_name = "im2col9x9_";
212 }
213
214 // Get boundary vector (the first/last vector with potentially a partial vector size) size
215 // If input_channel is a multiple of num_elems_processed_per_iteration, the boundary vec size is the (full) vector size
216 // otherwise, the boundary vec size is the (partial) remainder vector size
217 const unsigned int vec_size = num_elems_processed_per_iteration;
218 const unsigned int partial_vec_size = input_channel % vec_size;
219 const unsigned int boundary_vec_size = vec_size - ((vec_size - partial_vec_size) % vec_size);
220 build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vec_size));
221 build_opts.add_option("-DBOUNDARY_VECTOR_SIZE=" + support::cpp11::to_string(boundary_vec_size));
222 }
223 else
224 {
225 if(dilation == Size2D(1U, 1U))
226 {
227 const bool squared_im2col = kernel_dims.width == kernel_dims.height;
228 if(squared_im2col)
229 {
230 // Check if we can run an optimized im2col for NCHW
231 switch(kernel_dims.width)
232 {
233 case 1:
234 // Optimized im2col1x1 if stride_x = 1 and conv_info.has_padding() = false
235 if(conv_info.stride().first == 1 && !conv_info.has_padding())
236 {
237 kernel_name = "im2col1x1_stridex1_";
238 num_elems_processed_per_iteration = 4;
239 is_padding_required_nchw = true;
240 }
241 break;
242 case 3:
243 kernel_name = "im2col3x3_";
244 num_elems_processed_per_iteration = 1;
245 is_padding_required_nchw = true;
246 break;
247 case 5:
248 kernel_name = "im2col5x5_";
249 num_elems_processed_per_iteration = 1;
250 is_padding_required_nchw = true;
251 break;
252 case 11:
253 // Optimized im2col11x11 if pad_x = pad_y = 0
254 if(!conv_info.has_padding())
255 {
256 kernel_name = "im2col11x11_padx0_pady0_";
257 num_elems_processed_per_iteration = 1;
258 is_padding_required_nchw = true;
259 }
260 break;
261 default:
262 kernel_name = "im2col_generic_";
263 num_elems_processed_per_iteration = 1;
264 is_padding_required_nchw = false;
265 break;
266 }
267 }
268 else if(kernel_dims.width > 1 && !conv_info.has_padding())
269 {
270 kernel_name = "im2col_generic_padx0_pady0_";
271 num_elems_processed_per_iteration = 1;
272 is_padding_required_nchw = false;
273
274 // Optimized im2col is performed using one or more vector operations with the specified vector size
275 // and a remainder. For example, for 5x5 convolutions, im2col is performed using vectors of size 4
276 // and scalars; for 7x7 convolutions, using vectors of size 4 and vectors of size 3.
277 // Using the vector size of 4 is always safe since OpenCL supports vectors of size 2 and 3.
278 // Using the vector size of 8, however, may be faster.
279 // For 2x2 convolutions, use vectors of size 2. (For 3x3 convolutions, im2col_kernel3x3_padx0_pady0
280 // is used instead.)
281 const size_t vector_size = std::min(static_cast<size_t>(4), kernel_dims.width);
282 const size_t width_mod_vector_size = kernel_dims.width % vector_size;
283 build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vector_size));
284 build_opts.add_option("-DWIDTH_MOD_VECTOR_SIZE=" + support::cpp11::to_string(width_mod_vector_size));
285 }
286 }
287 }
288
289 // Append the data layout to the kernel_name
290 kernel_name += lower_string(string_from_data_layout(data_layout));
291
292 Im2ColConfiguration im2col_config;
293 im2col_config.kernel_name = kernel_name;
294 im2col_config.build_options = build_opts.options();
295 im2col_config.num_elems_processed_per_iteration = num_elems_processed_per_iteration;
296 im2col_config.is_padding_required_nchw = is_padding_required_nchw;
297
298 return im2col_config;
299 }
300 } // namespace
301
CLIm2ColKernel()302 CLIm2ColKernel::CLIm2ColKernel()
303 : _input(nullptr), _output(nullptr), _data_layout(DataLayout::UNKNOWN), _convolved_dims(), _num_elems_processed_per_iteration(1), _kernel_dims(), _conv_info(), _num_groups()
304 {
305 }
306
configure(const ICLTensor * input,ICLTensor * output,const Size2D & kernel_dims,const PadStrideInfo & conv_info,bool has_bias,const Size2D & dilation,unsigned int num_groups)307 void CLIm2ColKernel::configure(const ICLTensor *input, ICLTensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
308 unsigned int num_groups)
309 {
310 configure(CLKernelLibrary::get().get_compile_context(), input, output, kernel_dims, conv_info, has_bias, dilation, num_groups);
311 }
312
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output,const Size2D & kernel_dims,const PadStrideInfo & conv_info,bool has_bias,const Size2D & dilation,unsigned int num_groups)313 void CLIm2ColKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias,
314 const Size2D &dilation,
315 unsigned int num_groups)
316 {
317 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
318 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation, num_groups));
319
320 auto padding_info = get_padding_info({ input, output });
321 _data_layout = input->info()->data_layout();
322
323 const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
324 const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
325 const unsigned int input_width = input->info()->dimension(width_idx);
326 const unsigned int input_height = input->info()->dimension(height_idx);
327
328 // Select and configure the optimal OpenCL kernel to run.
329 // This function returns the OpenCL kernel's name, the arguments to pass at compile time, the number of elements processed per iteration
330 // and the padding requirement flag
331 Im2ColConfiguration im2col_config = configure_opencl_kernel(input->info(), kernel_dims, conv_info, has_bias, dilation, num_groups);
332
333 // Create kernel
334 _kernel = create_kernel(compile_context, im2col_config.kernel_name, im2col_config.build_options);
335
336 _input = input;
337 _output = output;
338 _convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation);
339 _num_elems_processed_per_iteration = im2col_config.num_elems_processed_per_iteration;
340 _kernel_dims = kernel_dims; // Only needed by the Tuner
341 _conv_info = conv_info; // Only needed by the Tuner
342 _num_groups = num_groups;
343
344 // Configure kernel window
345 auto win_config = validate_and_configure_window(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration,
346 im2col_config.is_padding_required_nchw, num_groups);
347 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
348 ICLKernel::configure_internal(win_config.second);
349
350 // Set config_id for enabling LWS tuning
351 _config_id = im2col_config.kernel_name;
352 _config_id += "_";
353 _config_id += lower_string(string_from_data_type(input->info()->data_type()));
354 _config_id += "_";
355 _config_id += support::cpp11::to_string(num_groups);
356 _config_id += "_";
357 _config_id += support::cpp11::to_string(output->info()->dimension(0));
358 _config_id += "_";
359 _config_id += support::cpp11::to_string(output->info()->dimension(1));
360 _config_id += "_";
361 _config_id += lower_string(string_from_data_layout(_data_layout));
362
363 ARM_COMPUTE_ERROR_ON(input->info()->data_layout() == DataLayout::NHWC && has_padding_changed(padding_info));
364 }
365
validate(const ITensorInfo * input,const ITensorInfo * output,const Size2D & kernel_dims,const PadStrideInfo & conv_info,bool has_bias,const Size2D & dilation,unsigned int num_groups)366 Status CLIm2ColKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
367 unsigned int num_groups)
368 {
369 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, kernel_dims, conv_info, has_bias, dilation, num_groups));
370 Im2ColConfiguration im2col_config = configure_opencl_kernel(input, kernel_dims, conv_info, has_bias, dilation, num_groups);
371 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration,
372 im2col_config.is_padding_required_nchw, num_groups)
373 .first);
374 return Status{};
375 }
376
run(const Window & window,cl::CommandQueue & queue)377 void CLIm2ColKernel::run(const Window &window, cl::CommandQueue &queue)
378 {
379 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
380 ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(ICLKernel::window(), window);
381
382 // Get initial windows
383 // Collapse in order to have (SRC_DEPTH * BATCH_SIZE) on the 3rd dimension
384 Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ);
385 window_collapsed.set_dimension_step(Window::DimZ, 1);
386
387 Window window_output;
388 window_output.use_tensor_dimensions(_output->info()->tensor_shape());
389
390 const Window first_slice_3d = window_collapsed.first_slice_window_3D();
391
392 Window slice = first_slice_3d;
393 Window slice_in = first_slice_3d;
394 Window slice_out = window_output.first_slice_window_2D();
395
396 if(_data_layout == DataLayout::NHWC)
397 {
398 const Window tmp_win = window.collapse_if_possible(ICLKernel::window(), 3);
399 const int num_batches = tmp_win[3].end();
400
401 slice.set(1, Window::Dimension(0, static_cast<int>(_output->info()->tensor_shape()[1]), 1));
402 slice.set(2, Window::Dimension(0, static_cast<int>(num_batches), 1));
403 }
404 else
405 {
406 slice.set(0, Window::Dimension(0, static_cast<int>(ceil_to_multiple(_convolved_dims.first, _num_elems_processed_per_iteration)), _num_elems_processed_per_iteration));
407 slice.set(1, Window::Dimension(0, static_cast<int>(_convolved_dims.second), 1));
408 // Note: In case of NCHW the 3rd dimension is already set collapsing the input window
409 }
410
411 // Setup input slice
412 // The dimensions of the input are increased within the OpenCL kernel
413 slice_in.set(Window::DimX, Window::Dimension(0, 0, 0));
414 slice_in.set(Window::DimY, Window::Dimension(0, 0, 0));
415 slice_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
416
417 // Setup output slice
418 // The dimensions of the output are increased within the OpenCL kernel
419 slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
420 slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
421
422 unsigned int idx = num_arguments_per_3D_tensor() + (_num_groups == 1 ? num_arguments_per_2D_tensor() : num_arguments_per_3D_tensor());
423 _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(_input->info()->strides_in_bytes()[3]));
424 _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(_output->info()->strides_in_bytes()[((_num_groups == 1) ? 2 : 3)]));
425 do
426 {
427 unsigned int idx = 0;
428 add_3D_tensor_argument(idx, _input, slice_in);
429 if(_num_groups == 1)
430 {
431 add_2D_tensor_argument(idx, _output, slice_out);
432 }
433 else
434 {
435 add_3D_tensor_argument(idx, _output, slice_out);
436 }
437 enqueue(queue, *this, slice, lws_hint());
438 }
439 while(window_collapsed.slide_window_slice_3D(slice) && window_output.slide_window_slice_2D(slice_out) && window_collapsed.slide_window_slice_3D(slice_in));
440 }
441 } // namespace arm_compute
442