blob: 56ac0c72504f923bcf227dc1e1446d11e177c6a6 [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
Anthony Barbier328891c2018-02-21 14:00:44 +0000127 unsigned int conv_stride_x = std::get<0>(conv_info.stride());
128 unsigned int conv_stride_y = std::get<1>(conv_info.stride());
129 unsigned int conv_pad_left = conv_info.pad_left();
130 unsigned int conv_pad_top = conv_info.pad_top();
Giorgio Arena59486342017-12-01 10:42:47 +0000131
132 unsigned int num_elems_read_per_iteration_x = 0;
133 unsigned int num_elems_read_per_iteration_y = 0;
134 unsigned int num_elems_written_per_iteration_x = 0;
135 unsigned int num_elems_written_per_iteration_y = 0;
136
Michalis Spyroua9676112018-02-22 18:07:43 +0000137 if(gpu_target_is_in(target, GPUTarget::G71, GPUTarget::G72) && (kernel_size <= 5) && (conv_stride_x == 1) && (conv_stride_y == 1) && (data_type == DataType::F32))
Giorgio Arena59486342017-12-01 10:42:47 +0000138 {
139 // Configure kernel window
Giorgio Arena59486342017-12-01 10:42:47 +0000140
141 switch(kernel_size)
142 {
143 case 1:
144 {
145 num_elems_read_per_iteration_x = 4;
146 num_elems_read_per_iteration_y = 4;
147 num_elems_written_per_iteration_x = 4;
148 num_elems_written_per_iteration_y = 4;
149 break;
150 }
151 case 3:
152 {
153 num_elems_read_per_iteration_x = 6;
154 num_elems_read_per_iteration_y = 5;
155 num_elems_written_per_iteration_x = 4;
156 num_elems_written_per_iteration_y = 3;
157 break;
158 }
159 case 5:
160 {
161 num_elems_read_per_iteration_x = 8;
162 num_elems_read_per_iteration_y = 6;
163 num_elems_written_per_iteration_x = 4;
164 num_elems_written_per_iteration_y = 2;
165 break;
166 }
167 default:
168 {
169 ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost");
170 }
171 }
172 }
173 else
174 {
Giorgio Arena59486342017-12-01 10:42:47 +0000175 num_elems_read_per_iteration_y = kernel_size;
176 num_elems_written_per_iteration_x = 8;
177 num_elems_written_per_iteration_y = 1;
Anthony Barbiercc9fed52017-12-13 10:46:00 +0000178 switch(kernel_size)
179 {
180 case 1:
181 switch(conv_stride_x)
182 {
183 case 1:
184 num_elems_read_per_iteration_x = 8;
185 break;
186 case 2:
187 num_elems_read_per_iteration_x = 16;
188 break;
189 case 3:
190 switch(input->element_size())
191 {
192 case 1:
193 num_elems_read_per_iteration_x = 28;
194 break;
195 case 2:
196 num_elems_read_per_iteration_x = 24;
197 break;
198 case 4:
199 num_elems_read_per_iteration_x = 22;
200 break;
201 default:
202 ARM_COMPUTE_ERROR("Invalid data size");
203 }
204 break;
205 default:
206 ARM_COMPUTE_ERROR("Invalid convolution stride X");
207 }
208 break;
209 case 3:
210 switch(conv_stride_x)
211 {
212 case 1:
213 num_elems_read_per_iteration_x = 10;
214 break;
215 case 2:
216 num_elems_read_per_iteration_x = 17;
217 break;
218 default:
219 ARM_COMPUTE_ERROR("Invalid convolution stride X");
220 }
221 break;
222 case 5:
223 switch(conv_stride_x)
224 {
225 case 1:
226 num_elems_read_per_iteration_x = 12;
227 break;
228 case 2:
229 num_elems_read_per_iteration_x = 20;
230 break;
231 default:
232 ARM_COMPUTE_ERROR("Invalid convolution stride X");
233 }
234 break;
235 default:
236 ARM_COMPUTE_ERROR("Invalid direct convolution size");
237 }
Giorgio Arena59486342017-12-01 10:42:47 +0000238 }
239
Giorgio Arena59486342017-12-01 10:42:47 +0000240 // Create window and update padding
Anthony Barbiercc9fed52017-12-13 10:46:00 +0000241 bool window_changed = false;
242 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 +0000243
Georgios Pinitas1a03d762018-02-21 14:47:09 +0000244 AccessWindowRectangle input_access(input, -conv_pad_left, -conv_pad_top,
245 num_elems_read_per_iteration_x, num_elems_read_per_iteration_y,
246 conv_stride_x, conv_stride_y);
Giorgio Arena59486342017-12-01 10:42:47 +0000247 AccessWindowStatic weights_access(weights, 0, 0, kernel_size, kernel_size);
248 AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y);
249
250 window_changed = update_window_and_padding(win, input_access, weights_access, output_access);
251
252 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
253
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000254 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
Giorgio Arena59486342017-12-01 10:42:47 +0000255 return std::make_pair(err, win);
256}
257} // namespace
258
259CLDirectConvolutionLayerKernel::CLDirectConvolutionLayerKernel()
260 : _input(nullptr), _biases(nullptr), _weights(nullptr), _output(nullptr), _border_size(0), _conv_stride_x(0), _conv_stride_y(0)
261{
262}
263
264BorderSize CLDirectConvolutionLayerKernel::border_size() const
265{
266 return _border_size;
267}
268
269void CLDirectConvolutionLayerKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info)
270{
271 ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output);
272
273 const unsigned int kernel_size = weights->info()->dimension(0);
274 const DataType data_type = input->info()->data_type();
275
276 // Get convolved dimensions
277 TensorShape output_shape = get_output_shape(input->info()->tensor_shape(), weights->info()->tensor_shape(), conv_info);
278
279 // Output auto inizialitation if not yet initialized
280 // FIXME: input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet).
281 auto_init_if_empty(*output->info(),
282 output_shape,
283 1,
284 input->info()->data_type(),
285 input->info()->fixed_point_position(),
286 input->info()->quantization_info());
287
288 // Perform validation step
289 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
290 weights->info(),
291 (biases != nullptr) ? biases->info() : nullptr,
292 output->info(),
293 conv_info));
294
295 _conv_stride_x = std::get<0>(conv_info.stride());
296 _conv_stride_y = std::get<1>(conv_info.stride());
Georgios Pinitas15997872018-02-19 13:58:22 +0000297 _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 +0000298
299 _input = input;
300 _weights = weights;
301 _output = output;
302 _biases = biases;
303
Michalis Spyroua9676112018-02-22 18:07:43 +0000304 const GPUTarget gpu_target = get_target();
Giorgio Arena59486342017-12-01 10:42:47 +0000305
306 std::stringstream kernel_name;
307 kernel_name << "direct_convolution" << kernel_size << "x" << kernel_size;
308
309 CLBuildOptions build_options;
310 build_options.add_option_if(_biases != nullptr, std::string("-DHAS_BIAS"));
311
Michalis Spyroua9676112018-02-22 18:07:43 +0000312 if(gpu_target_is_in(gpu_target, GPUTarget::G71, GPUTarget::G72) && (kernel_size <= 5) && (_conv_stride_x == 1) && (_conv_stride_y == 1) && (data_type == DataType::F32))
Giorgio Arena59486342017-12-01 10:42:47 +0000313 {
314 build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2))));
315
316 kernel_name << "_f32_bifrost";
317 _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_options.options()));
318
319 // Through extensive experimentation with over 30 representative tensor
320 // shapes, we found a small number of local work size configurations
321 // that result in nearly optimal execution times. Selecting the right
322 // lws for a given shape, however, required a complex decision tree,
323 // until we constructed a simple feature as described below.
324 //
325 // We started from the number of multiply-accumulate operations for a
326 // convolution layer, which is equal to the product of the input
327 // dimensions 0..2 and the weights dimensions 0..2. Unfortunately,
328 // this resulted in ties between distinct shapes that required distinct
329 // lws configurations. Replacing the width of the input with the kernel
330 // size, however, resulted in nearly optimal predictions. We use underscores
331 // in variable names to indicate when they are intentionally misleading.
332 const size_t product_of_weights_dimensions = weights->info()->dimension(0) * weights->info()->dimension(1) * weights->info()->dimension(2);
333 const size_t product_of_input_dimensions_ = input->info()->dimension(0) * weights->info()->dimension(1) * input->info()->dimension(2);
334 const float mega_ops_ = 1e-6 * product_of_weights_dimensions * product_of_input_dimensions_;
335
336 switch(kernel_size)
337 {
338 case 1:
339 {
340 if(mega_ops_ < 1.f)
341 {
342 _lws_hint = cl::NDRange(1, 1, 8);
343 }
344 else if(mega_ops_ < 7.f)
345 {
346 _lws_hint = cl::NDRange(1, 1, 4);
347 }
348 else
349 {
350 _lws_hint = cl::NDRange(1, 1, 2);
351 }
352 break;
353 }
354 case 3:
355 {
356 if(mega_ops_ < 1.f)
357 {
358 _lws_hint = cl::NDRange(1, 1, 8);
359 }
360 else if(mega_ops_ < 13.f)
361 {
362 _lws_hint = cl::NDRange(2, 1, 4);
363 }
364 else if(mega_ops_ < 50.f)
365 {
366 _lws_hint = cl::NDRange(3, 1, 4);
367 }
368 else
369 {
370 _lws_hint = cl::NDRange(2, 1, 6);
371 }
372 break;
373 }
374 case 5:
375 {
376 if(mega_ops_ < 2.f || mega_ops_ > 80.f)
377 {
378 _lws_hint = cl::NDRange(2, 1, 4);
379 }
380 else
381 {
382 _lws_hint = cl::NDRange(2, 1, 8);
383 }
384 break;
385 }
386 default:
387 {
388 ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost");
389 }
390 }
391 }
392 else
393 {
394 bool is_quantized_fixed_point = is_data_type_fixed_point(data_type);
395 bool is_quantized_asymm = is_data_type_quantized_asymmetric(data_type);
396 DataType promoted_type = (is_quantized_fixed_point) ? get_promoted_data_type(data_type) : data_type;
397
398 build_options.add_option_if(is_quantized_asymm, std::string("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size)));
399 build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)));
400 build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type)));
401 build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2))));
402 build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x)));
403 build_options.add_option_if(is_quantized_fixed_point,
404 std::string("-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position())));
405 build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(promoted_type)));
406
407 // Create kernel
408 _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(is_quantized_asymm ? "direct_convolution_1x1_3x3_5x5_quantized" : kernel_name.str(),
409 build_options.options()));
410 }
411
412 // Configure kernel window
413 auto win_config = validate_and_configure_window(input->info(), weights->info(), output->info(), conv_info, gpu_target);
414 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
415 ICLKernel::configure(win_config.second);
416
417 // Set static kernel arguments
418 if(is_data_type_quantized_asymmetric(data_type))
419 {
420 int output_multiplier = 0;
421 int output_shift = 0;
422
423 float multiplier = _input->info()->quantization_info().scale * _weights->info()->quantization_info().scale / _output->info()->quantization_info().scale;
424 ARM_COMPUTE_THROW_ON_ERROR(quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift));
425
426 unsigned int idx = 3 * num_arguments_per_3D_tensor() + ((_biases != nullptr) ? num_arguments_per_1D_tensor() : 0) + 1;
427 _kernel.setArg(idx++, -_input->info()->quantization_info().offset);
428 _kernel.setArg(idx++, -_weights->info()->quantization_info().offset);
429 _kernel.setArg(idx++, _output->info()->quantization_info().offset);
430 _kernel.setArg(idx++, output_multiplier);
431 _kernel.setArg(idx++, output_shift);
432 }
433
434 // Set config_id for enabling LWS tuning
435 _config_id = "direct_convolution_";
436 _config_id += lower_string(string_from_data_type(data_type));
437 _config_id += "_";
438 _config_id += support::cpp11::to_string(kernel_size);
439 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000440 _config_id += support::cpp11::to_string(border_size().left);
Giorgio Arena59486342017-12-01 10:42:47 +0000441 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000442 _config_id += support::cpp11::to_string(border_size().top);
Giorgio Arena59486342017-12-01 10:42:47 +0000443 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000444 _config_id += support::cpp11::to_string(border_size().right);
Giorgio Arena59486342017-12-01 10:42:47 +0000445 _config_id += "_";
Georgios Pinitas15997872018-02-19 13:58:22 +0000446 _config_id += support::cpp11::to_string(border_size().bottom);
Giorgio Arena59486342017-12-01 10:42:47 +0000447 _config_id += "_";
448 _config_id += support::cpp11::to_string(_conv_stride_x);
449 _config_id += "_";
450 _config_id += support::cpp11::to_string(_conv_stride_y);
451 _config_id += "_";
452 _config_id += support::cpp11::to_string(output->info()->dimension(0));
453 _config_id += "_";
454 _config_id += support::cpp11::to_string(output->info()->dimension(1));
455}
456
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000457Status CLDirectConvolutionLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
458 const GPUTarget target)
Giorgio Arena59486342017-12-01 10:42:47 +0000459{
460 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info));
461 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, target).first);
462
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000463 return Status{};
Giorgio Arena59486342017-12-01 10:42:47 +0000464}
465
SiCong Lic51b72f2017-07-28 14:46:20 +0100466void CLDirectConvolutionLayerKernel::run(const Window &window, cl::CommandQueue &queue)
steniu0127b386c2017-07-18 17:37:43 +0100467{
468 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
469 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
470
471 // Get initial windows
472 Window slice = window.first_slice_window_3D();
473 Window win_in = window;
474
Jaroslaw Rzepecki2ecbada2017-11-29 13:51:34 +0000475 win_in.adjust(Window::DimX, -_border_size.left, true);
476 win_in.adjust(Window::DimY, -_border_size.top, true);
steniu0127b386c2017-07-18 17:37:43 +0100477 win_in.set_dimension_step(Window::DimX, window.x().step() * _conv_stride_x);
478 win_in.set_dimension_step(Window::DimY, window.y().step() * _conv_stride_y);
479
480 Window slice_in = win_in.first_slice_window_3D();
481
482 unsigned int idx1 = 2 * num_arguments_per_3D_tensor();
483 add_3D_tensor_argument(idx1, _weights, slice);
484
485 if(_biases != nullptr)
486 {
487 Window slice_biases;
SiCong Li86b53332017-08-23 11:02:43 +0100488 slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape());
steniu0127b386c2017-07-18 17:37:43 +0100489 add_1D_tensor_argument(idx1, _biases, slice_biases);
490 }
491
Gian Marco Iodice5cb4d6a2017-08-08 10:53:00 +0100492 _kernel.setArg(idx1++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3]));
493
steniu0127b386c2017-07-18 17:37:43 +0100494 do
495 {
496 unsigned int idx = 0;
497 add_3D_tensor_argument(idx, _input, slice_in);
498 add_3D_tensor_argument(idx, _output, slice);
499
500 enqueue(queue, *this, slice, _lws_hint);
501 }
502 while(window.slide_window_slice_3D(slice) && win_in.slide_window_slice_3D(slice_in));
503}