blob: ac3c9ac4a6f3db7a404213426c55f9a3b8f0dfc3 [file] [log] [blame]
steniu0127b386c2017-07-18 17:37:43 +01001/*
Georgios Pinitas15997872018-02-19 13:58:22 +00002 * Copyright (c) 2017-2018 ARM Limited.
steniu0127b386c2017-07-18 17:37:43 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/CL/kernels/CLDirectConvolutionLayerKernel.h"
25
26#include "arm_compute/core/AccessWindowStatic.h"
27#include "arm_compute/core/CL/CLHelpers.h"
28#include "arm_compute/core/CL/CLKernelLibrary.h"
29#include "arm_compute/core/CL/ICLTensor.h"
30#include "arm_compute/core/Error.h"
31#include "arm_compute/core/Helpers.h"
32#include "arm_compute/core/IAccessWindow.h"
33#include "arm_compute/core/ITensor.h"
34#include "arm_compute/core/Types.h"
Gian Marco Iodice5cb4d6a2017-08-08 10:53:00 +010035#include "arm_compute/core/Utils.h"
steniu0127b386c2017-07-18 17:37:43 +010036#include "arm_compute/core/Validate.h"
Chunosovd621bca2017-11-03 17:33:15 +070037#include "arm_compute/core/utils/quantization/AsymmHelpers.h"
steniu0127b386c2017-07-18 17:37:43 +010038#include "support/ToolchainSupport.h"
39
40using namespace arm_compute;
41
Georgios Pinitas30902ed2017-11-14 15:32:57 +000042namespace
43{
44/** Calculates expected output shape dimension
45 *
46 * @param[in] Input shape
47 *
48 * @return Expected output shape
49 */
50TensorShape get_output_shape(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info)
51{
52 unsigned int output_width = 0;
53 unsigned int output_height = 0;
54 std::tie(output_width, output_height) = scaled_dimensions(input_shape.x(), input_shape.y(), weights_shape.x(), weights_shape.y(), conv_info);
55
56 TensorShape output_shape = input_shape;
57 output_shape.set(0, output_width);
58 output_shape.set(1, output_height);
59 output_shape.set(2, weights_shape[3]);
60
61 return output_shape;
62}
Georgios Pinitas30902ed2017-11-14 15:32:57 +000063
Georgios Pinitas631c41a2017-12-06 11:53:03 +000064Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info)
Georgios Pinitas30902ed2017-11-14 15:32:57 +000065{
66 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F16, DataType::F32);
67 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
68 ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) != weights->dimension(1),
69 "Weights should have same width as length");
70 ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) != 1 && weights->dimension(0) != 3 && weights->dimension(0) != 5,
71 "Kernel sizes other than 1x1, 3x3 or 5x5 are not supported");
72 ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(2) != input->dimension(2),
73 "Weights feature map dimension should match the respective input's one");
74 ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) != weights->dimension(1),
75 "Only rectangular weights are supported!");
76 ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->num_dimensions() > 4,
77 "Weights can be at most 4 dimensional");
78 ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(0) == 1) && std::get<0>(conv_info.stride()) > 3,
79 "Strides larger than 3 not supported for 1x1 convolution.");
80 ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(0) == 3 || weights->dimension(0) == 5) && std::get<0>(conv_info.stride()) > 2,
81 "Strides larger than 2 not supported for 3x3 convolution.");
82
83 if(biases != nullptr)
84 {
85 if(is_data_type_quantized_asymmetric(input->data_type()))
86 {
87 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32);
88 }
89 else
90 {
91 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases);
92 }
93 ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->dimension(0) != weights->dimension(3),
94 "Biases size and number of input feature maps should match");
95 ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->num_dimensions() > 1,
96 "Biases should be one dimensional");
97 }
98
99 // Checks performed when output is configured
100 if(output->total_size() != 0)
101 {
102 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(),
103 get_output_shape(input->tensor_shape(), weights->tensor_shape(), conv_info));
104 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
105 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT(input, output);
106 }
107
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000108 return Status{};
Georgios Pinitas30902ed2017-11-14 15:32:57 +0000109}
110
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000111std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output, const PadStrideInfo &conv_info, const GPUTarget target)
Giorgio Arena59486342017-12-01 10:42:47 +0000112{
113 const unsigned int kernel_size = weights->dimension(0);
114 const DataType data_type = input->data_type();
115
116 // Get convolved dimensions
117 TensorShape output_shape = get_output_shape(input->tensor_shape(), weights->tensor_shape(), conv_info);
118
119 // Output auto inizialitation if not yet initialized
120 // FIXME: input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet).
121 auto_init_if_empty(*output, output_shape,
122 1,
123 input->data_type(),
124 input->fixed_point_position(),
125 input->quantization_info());
126
127 unsigned int conv_stride_x = std::get<0>(conv_info.stride());
128 unsigned int conv_stride_y = std::get<1>(conv_info.stride());
Georgios Pinitas15997872018-02-19 13:58:22 +0000129 unsigned int conv_pad_left = conv_info.pad_left();
130 unsigned int conv_pad_top = conv_info.pad_top();
131 unsigned int conv_pad_right = conv_info.pad_right();
132 unsigned int conv_pad_bottom = conv_info.pad_bottom();
Giorgio Arena59486342017-12-01 10:42:47 +0000133
134 unsigned int num_elems_read_per_iteration_x = 0;
135 unsigned int num_elems_read_per_iteration_y = 0;
136 unsigned int num_elems_written_per_iteration_x = 0;
137 unsigned int num_elems_written_per_iteration_y = 0;
138
Giorgio Arena59486342017-12-01 10:42:47 +0000139 if((target == GPUTarget::BIFROST) && (kernel_size <= 5) && (conv_stride_x == 1) && (conv_stride_y == 1) && (data_type == DataType::F32))
140 {
141 // Configure kernel window
Giorgio Arena59486342017-12-01 10:42:47 +0000142
143 switch(kernel_size)
144 {
145 case 1:
146 {
147 num_elems_read_per_iteration_x = 4;
148 num_elems_read_per_iteration_y = 4;
149 num_elems_written_per_iteration_x = 4;
150 num_elems_written_per_iteration_y = 4;
151 break;
152 }
153 case 3:
154 {
155 num_elems_read_per_iteration_x = 6;
156 num_elems_read_per_iteration_y = 5;
157 num_elems_written_per_iteration_x = 4;
158 num_elems_written_per_iteration_y = 3;
159 break;
160 }
161 case 5:
162 {
163 num_elems_read_per_iteration_x = 8;
164 num_elems_read_per_iteration_y = 6;
165 num_elems_written_per_iteration_x = 4;
166 num_elems_written_per_iteration_y = 2;
167 break;
168 }
169 default:
170 {
171 ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost");
172 }
173 }
174 }
175 else
176 {
Giorgio Arena59486342017-12-01 10:42:47 +0000177 num_elems_read_per_iteration_y = kernel_size;
178 num_elems_written_per_iteration_x = 8;
179 num_elems_written_per_iteration_y = 1;
Anthony Barbiercc9fed52017-12-13 10:46:00 +0000180 switch(kernel_size)
181 {
182 case 1:
183 switch(conv_stride_x)
184 {
185 case 1:
186 num_elems_read_per_iteration_x = 8;
187 break;
188 case 2:
189 num_elems_read_per_iteration_x = 16;
190 break;
191 case 3:
192 switch(input->element_size())
193 {
194 case 1:
195 num_elems_read_per_iteration_x = 28;
196 break;
197 case 2:
198 num_elems_read_per_iteration_x = 24;
199 break;
200 case 4:
201 num_elems_read_per_iteration_x = 22;
202 break;
203 default:
204 ARM_COMPUTE_ERROR("Invalid data size");
205 }
206 break;
207 default:
208 ARM_COMPUTE_ERROR("Invalid convolution stride X");
209 }
210 break;
211 case 3:
212 switch(conv_stride_x)
213 {
214 case 1:
215 num_elems_read_per_iteration_x = 10;
216 break;
217 case 2:
218 num_elems_read_per_iteration_x = 17;
219 break;
220 default:
221 ARM_COMPUTE_ERROR("Invalid convolution stride X");
222 }
223 break;
224 case 5:
225 switch(conv_stride_x)
226 {
227 case 1:
228 num_elems_read_per_iteration_x = 12;
229 break;
230 case 2:
231 num_elems_read_per_iteration_x = 20;
232 break;
233 default:
234 ARM_COMPUTE_ERROR("Invalid convolution stride X");
235 }
236 break;
237 default:
238 ARM_COMPUTE_ERROR("Invalid direct convolution size");
239 }
Giorgio Arena59486342017-12-01 10:42:47 +0000240 }
241
242 // Calculate right and bottom border
Michalis Spyrou4708e022017-12-08 13:35:16 +0000243 int input_width = input->dimension(0) + conv_pad_left + conv_pad_right;
244 int input_height = input->dimension(1) + conv_pad_top + conv_pad_bottom;
Giorgio Arena59486342017-12-01 10:42:47 +0000245
246 // Add padding only if necessary or it would always result in a window_changed
Anthony Barbiercc9fed52017-12-13 10:46:00 +0000247 input_width = ceil_to_multiple(input_width, num_elems_read_per_iteration_x);
248 input_height = ceil_to_multiple(input_height, num_elems_read_per_iteration_y);
Giorgio Arena59486342017-12-01 10:42:47 +0000249
250 // Create window and update padding
Anthony Barbiercc9fed52017-12-13 10:46:00 +0000251 bool window_changed = false;
252 Window win = calculate_max_window(*output, Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y));
Giorgio Arena59486342017-12-01 10:42:47 +0000253
254 AccessWindowStatic input_access(input, -conv_pad_left, -conv_pad_top, input_width, input_height);
255 AccessWindowStatic weights_access(weights, 0, 0, kernel_size, kernel_size);
256 AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y);
257
258 window_changed = update_window_and_padding(win, input_access, weights_access, output_access);
259
260 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
261
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000262 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
Giorgio Arena59486342017-12-01 10:42:47 +0000263 return std::make_pair(err, win);
264}
265} // namespace
266
267CLDirectConvolutionLayerKernel::CLDirectConvolutionLayerKernel()
268 : _input(nullptr), _biases(nullptr), _weights(nullptr), _output(nullptr), _border_size(0), _conv_stride_x(0), _conv_stride_y(0)
269{
270}
271
272BorderSize CLDirectConvolutionLayerKernel::border_size() const
273{
274 return _border_size;
275}
276
277void CLDirectConvolutionLayerKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info)
278{
279 ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output);
280
281 const unsigned int kernel_size = weights->info()->dimension(0);
282 const DataType data_type = input->info()->data_type();
283
284 // Get convolved dimensions
285 TensorShape output_shape = get_output_shape(input->info()->tensor_shape(), weights->info()->tensor_shape(), conv_info);
286
287 // Output auto inizialitation if not yet initialized
288 // FIXME: input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet).
289 auto_init_if_empty(*output->info(),
290 output_shape,
291 1,
292 input->info()->data_type(),
293 input->info()->fixed_point_position(),
294 input->info()->quantization_info());
295
296 // Perform validation step
297 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
298 weights->info(),
299 (biases != nullptr) ? biases->info() : nullptr,
300 output->info(),
301 conv_info));
302
303 _conv_stride_x = std::get<0>(conv_info.stride());
304 _conv_stride_y = std::get<1>(conv_info.stride());
Georgios Pinitas15997872018-02-19 13:58:22 +0000305 _border_size = BorderSize(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left());
Giorgio Arena59486342017-12-01 10:42:47 +0000306
307 _input = input;
308 _weights = weights;
309 _output = output;
310 _biases = biases;
311
Giorgio Arena59486342017-12-01 10:42:47 +0000312 const GPUTarget gpu_target = get_arch_from_target(get_target());
313
314 std::stringstream kernel_name;
315 kernel_name << "direct_convolution" << kernel_size << "x" << kernel_size;
316
317 CLBuildOptions build_options;
318 build_options.add_option_if(_biases != nullptr, std::string("-DHAS_BIAS"));
319
320 if((gpu_target == GPUTarget::BIFROST) && (kernel_size <= 5) && (_conv_stride_x == 1) && (_conv_stride_y == 1) && (data_type == DataType::F32))
321 {
322 build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2))));
323
324 kernel_name << "_f32_bifrost";
325 _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_options.options()));
326
327 // Through extensive experimentation with over 30 representative tensor
328 // shapes, we found a small number of local work size configurations
329 // that result in nearly optimal execution times. Selecting the right
330 // lws for a given shape, however, required a complex decision tree,
331 // until we constructed a simple feature as described below.
332 //
333 // We started from the number of multiply-accumulate operations for a
334 // convolution layer, which is equal to the product of the input
335 // dimensions 0..2 and the weights dimensions 0..2. Unfortunately,
336 // this resulted in ties between distinct shapes that required distinct
337 // lws configurations. Replacing the width of the input with the kernel
338 // size, however, resulted in nearly optimal predictions. We use underscores
339 // in variable names to indicate when they are intentionally misleading.
340 const size_t product_of_weights_dimensions = weights->info()->dimension(0) * weights->info()->dimension(1) * weights->info()->dimension(2);
341 const size_t product_of_input_dimensions_ = input->info()->dimension(0) * weights->info()->dimension(1) * input->info()->dimension(2);
342 const float mega_ops_ = 1e-6 * product_of_weights_dimensions * product_of_input_dimensions_;
343
344 switch(kernel_size)
345 {
346 case 1:
347 {
348 if(mega_ops_ < 1.f)
349 {
350 _lws_hint = cl::NDRange(1, 1, 8);
351 }
352 else if(mega_ops_ < 7.f)
353 {
354 _lws_hint = cl::NDRange(1, 1, 4);
355 }
356 else
357 {
358 _lws_hint = cl::NDRange(1, 1, 2);
359 }
360 break;
361 }
362 case 3:
363 {
364 if(mega_ops_ < 1.f)
365 {
366 _lws_hint = cl::NDRange(1, 1, 8);
367 }
368 else if(mega_ops_ < 13.f)
369 {
370 _lws_hint = cl::NDRange(2, 1, 4);
371 }
372 else if(mega_ops_ < 50.f)
373 {
374 _lws_hint = cl::NDRange(3, 1, 4);
375 }
376 else
377 {
378 _lws_hint = cl::NDRange(2, 1, 6);
379 }
380 break;
381 }
382 case 5:
383 {
384 if(mega_ops_ < 2.f || mega_ops_ > 80.f)
385 {
386 _lws_hint = cl::NDRange(2, 1, 4);
387 }
388 else
389 {
390 _lws_hint = cl::NDRange(2, 1, 8);
391 }
392 break;
393 }
394 default:
395 {
396 ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost");
397 }
398 }
399 }
400 else
401 {
402 bool is_quantized_fixed_point = is_data_type_fixed_point(data_type);
403 bool is_quantized_asymm = is_data_type_quantized_asymmetric(data_type);
404 DataType promoted_type = (is_quantized_fixed_point) ? get_promoted_data_type(data_type) : data_type;
405
406 build_options.add_option_if(is_quantized_asymm, std::string("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size)));
407 build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)));
408 build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type)));
409 build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2))));
410 build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x)));
411 build_options.add_option_if(is_quantized_fixed_point,
412 std::string("-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position())));
413 build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(promoted_type)));
414
415 // Create kernel
416 _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(is_quantized_asymm ? "direct_convolution_1x1_3x3_5x5_quantized" : kernel_name.str(),
417 build_options.options()));
418 }
419
420 // Configure kernel window
421 auto win_config = validate_and_configure_window(input->info(), weights->info(), output->info(), conv_info, gpu_target);
422 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
423 ICLKernel::configure(win_config.second);
424
425 // Set static kernel arguments
426 if(is_data_type_quantized_asymmetric(data_type))
427 {
428 int output_multiplier = 0;
429 int output_shift = 0;
430
431 float multiplier = _input->info()->quantization_info().scale * _weights->info()->quantization_info().scale / _output->info()->quantization_info().scale;
432 ARM_COMPUTE_THROW_ON_ERROR(quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift));
433
434 unsigned int idx = 3 * num_arguments_per_3D_tensor() + ((_biases != nullptr) ? num_arguments_per_1D_tensor() : 0) + 1;
435 _kernel.setArg(idx++, -_input->info()->quantization_info().offset);
436 _kernel.setArg(idx++, -_weights->info()->quantization_info().offset);
437 _kernel.setArg(idx++, _output->info()->quantization_info().offset);
438 _kernel.setArg(idx++, output_multiplier);
439 _kernel.setArg(idx++, output_shift);
440 }
441
442 // Set config_id for enabling LWS tuning
443 _config_id = "direct_convolution_";
444 _config_id += lower_string(string_from_data_type(data_type));
445 _config_id += "_";
446 _config_id += support::cpp11::to_string(kernel_size);
447 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000448 _config_id += support::cpp11::to_string(border_size().left);
Giorgio Arena59486342017-12-01 10:42:47 +0000449 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000450 _config_id += support::cpp11::to_string(border_size().top);
Giorgio Arena59486342017-12-01 10:42:47 +0000451 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000452 _config_id += support::cpp11::to_string(border_size().right);
Giorgio Arena59486342017-12-01 10:42:47 +0000453 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000454 _config_id += support::cpp11::to_string(border_size().bottom);
Giorgio Arena59486342017-12-01 10:42:47 +0000455 _config_id += "_";
456 _config_id += support::cpp11::to_string(_conv_stride_x);
457 _config_id += "_";
458 _config_id += support::cpp11::to_string(_conv_stride_y);
459 _config_id += "_";
460 _config_id += support::cpp11::to_string(output->info()->dimension(0));
461 _config_id += "_";
462 _config_id += support::cpp11::to_string(output->info()->dimension(1));
463}
464
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000465Status CLDirectConvolutionLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
466 const GPUTarget target)
Giorgio Arena59486342017-12-01 10:42:47 +0000467{
468 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info));
469 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, target).first);
470
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000471 return Status{};
Giorgio Arena59486342017-12-01 10:42:47 +0000472}
473
SiCong Lic51b72f2017-07-28 14:46:20 +0100474void CLDirectConvolutionLayerKernel::run(const Window &window, cl::CommandQueue &queue)
steniu0127b386c2017-07-18 17:37:43 +0100475{
476 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
477 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
478
479 // Get initial windows
480 Window slice = window.first_slice_window_3D();
481 Window win_in = window;
482
Jaroslaw Rzepecki2ecbada2017-11-29 13:51:34 +0000483 win_in.adjust(Window::DimX, -_border_size.left, true);
484 win_in.adjust(Window::DimY, -_border_size.top, true);
steniu0127b386c2017-07-18 17:37:43 +0100485 win_in.set_dimension_step(Window::DimX, window.x().step() * _conv_stride_x);
486 win_in.set_dimension_step(Window::DimY, window.y().step() * _conv_stride_y);
487
488 Window slice_in = win_in.first_slice_window_3D();
489
490 unsigned int idx1 = 2 * num_arguments_per_3D_tensor();
491 add_3D_tensor_argument(idx1, _weights, slice);
492
493 if(_biases != nullptr)
494 {
495 Window slice_biases;
SiCong Li86b53332017-08-23 11:02:43 +0100496 slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape());
steniu0127b386c2017-07-18 17:37:43 +0100497 add_1D_tensor_argument(idx1, _biases, slice_biases);
498 }
499
Gian Marco Iodice5cb4d6a2017-08-08 10:53:00 +0100500 _kernel.setArg(idx1++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3]));
501
steniu0127b386c2017-07-18 17:37:43 +0100502 do
503 {
504 unsigned int idx = 0;
505 add_3D_tensor_argument(idx, _input, slice_in);
506 add_3D_tensor_argument(idx, _output, slice);
507
508 enqueue(queue, *this, slice, _lws_hint);
509 }
510 while(window.slide_window_slice_3D(slice) && win_in.slide_window_slice_3D(slice_in));
511}