steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 "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 Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 35 | #include "arm_compute/core/Utils.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 36 | #include "arm_compute/core/Validate.h" |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 37 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 38 | #include "support/ToolchainSupport.h" |
| 39 | |
| 40 | using namespace arm_compute; |
| 41 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 42 | CLDirectConvolutionLayerKernel::CLDirectConvolutionLayerKernel() |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 43 | : _input(nullptr), _biases(nullptr), _weights(nullptr), _output(nullptr), _border_size(0), _conv_pad_x(0), _conv_pad_y(0), _conv_stride_x(0), _conv_stride_y(0) |
| 44 | { |
| 45 | } |
| 46 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 47 | BorderSize CLDirectConvolutionLayerKernel::border_size() const |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 48 | { |
| 49 | return _border_size; |
| 50 | } |
| 51 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 52 | void CLDirectConvolutionLayerKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 53 | { |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 54 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 55 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 56 | ARM_COMPUTE_ERROR_ON_MSG(weights->info()->dimension(0) != weights->info()->dimension(1), |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 57 | "Weights should have same width as length"); |
| 58 | ARM_COMPUTE_ERROR_ON_MSG(weights->info()->dimension(0) != 1 && weights->info()->dimension(0) != 3 && weights->info()->dimension(0) != 5, |
| 59 | "Kernel sizes other than 1x1, 3x3 or 5x5 are not supported"); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 60 | ARM_COMPUTE_ERROR_ON(weights->info()->dimension(2) != input->info()->dimension(2)); |
| 61 | ARM_COMPUTE_ERROR_ON(weights->info()->dimension(0) != weights->info()->dimension(1)); |
| 62 | ARM_COMPUTE_ERROR_ON(weights->info()->num_dimensions() > 4); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 63 | ARM_COMPUTE_ERROR_ON_MSG((weights->info()->dimension(0) == 1) && std::get<0>(conv_info.stride()) > 3, "Strides larger than 3 not supported for 1x1 convolution."); |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 64 | ARM_COMPUTE_ERROR_ON_MSG((weights->info()->dimension(0) == 3 || weights->info()->dimension(0) == 5) && std::get<0>(conv_info.stride()) > 2, "Strides larger than 2 not supported for 3x3 convolution."); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 65 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 66 | if(biases != nullptr) |
| 67 | { |
| 68 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 69 | ARM_COMPUTE_ERROR_ON(biases->info()->dimension(0) != weights->info()->dimension(3)); |
| 70 | ARM_COMPUTE_ERROR_ON(biases->info()->num_dimensions() > 1); |
| 71 | } |
| 72 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 73 | const unsigned int kernel_size = weights->info()->dimension(0); |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 74 | const DataType data_type = input->info()->data_type(); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 75 | |
| 76 | // Get convolved dimensions |
| 77 | unsigned int output_width = 0; |
| 78 | unsigned int output_height = 0; |
| 79 | std::tie(output_width, output_height) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), kernel_size, kernel_size, conv_info); |
| 80 | |
| 81 | TensorShape output_shape = input->info()->tensor_shape(); |
| 82 | output_shape.set(0, output_width); |
| 83 | output_shape.set(1, output_height); |
| 84 | output_shape.set(2, weights->info()->dimension(3)); |
| 85 | |
| 86 | // Output auto inizialitation if not yet initialized |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame^] | 87 | auto_init_if_empty(*output->info(), |
| 88 | output_shape, |
| 89 | 1, |
| 90 | input->info()->data_type(), |
| 91 | input->info()->fixed_point_position(), |
| 92 | input->info()->quantization_info()); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 93 | |
| 94 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); |
| 95 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 96 | ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); |
| 97 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 98 | _conv_stride_x = std::get<0>(conv_info.stride()); |
| 99 | _conv_stride_y = std::get<1>(conv_info.stride()); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 100 | _conv_pad_x = std::min(std::get<0>(conv_info.pad()), kernel_size / 2); |
| 101 | _conv_pad_y = std::min(std::get<1>(conv_info.pad()), kernel_size / 2); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 102 | |
| 103 | _input = input; |
| 104 | _weights = weights; |
| 105 | _output = output; |
| 106 | _biases = biases; |
| 107 | _border_size = BorderSize(_conv_pad_y, _conv_pad_x); |
| 108 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 109 | const GPUTarget gpu_target = get_arch_from_target(get_target()); |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 110 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 111 | std::stringstream kernel_name; |
| 112 | kernel_name << "direct_convolution" << kernel_size << "x" << kernel_size; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 113 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 114 | CLBuildOptions build_options; |
| 115 | build_options.add_option_if(_biases != nullptr, std::string("-DHAS_BIAS")); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 116 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 117 | if((gpu_target == GPUTarget::BIFROST) && (kernel_size <= 5) && (_conv_stride_x == 1) && (_conv_stride_y == 1) && (data_type == DataType::F32)) |
| 118 | { |
| 119 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2)))); |
| 120 | |
| 121 | kernel_name << "_f32_bifrost"; |
| 122 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_options.options())); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 123 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 124 | // Configure kernel window |
| 125 | Window win = calculate_max_window(*output->info()); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 126 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 127 | unsigned int num_elems_read_per_iteration_x = 0; |
| 128 | unsigned int num_elems_read_per_iteration_y = 0; |
| 129 | unsigned int num_elems_written_per_iteration_x = 0; |
| 130 | unsigned int num_elems_written_per_iteration_y = 0; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 131 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 132 | switch(kernel_size) |
| 133 | { |
Gian Marco Iodice | 1c8409d | 2017-09-06 17:24:25 +0100 | [diff] [blame] | 134 | case 1: |
| 135 | { |
| 136 | num_elems_read_per_iteration_x = 4; |
| 137 | num_elems_read_per_iteration_y = 4; |
| 138 | num_elems_written_per_iteration_x = 4; |
| 139 | num_elems_written_per_iteration_y = 4; |
| 140 | break; |
| 141 | } |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 142 | case 3: |
| 143 | { |
| 144 | num_elems_read_per_iteration_x = 6; |
| 145 | num_elems_read_per_iteration_y = 5; |
| 146 | num_elems_written_per_iteration_x = 4; |
| 147 | num_elems_written_per_iteration_y = 3; |
| 148 | break; |
| 149 | } |
| 150 | case 5: |
| 151 | { |
| 152 | num_elems_read_per_iteration_x = 8; |
| 153 | num_elems_read_per_iteration_y = 6; |
| 154 | num_elems_written_per_iteration_x = 4; |
| 155 | num_elems_written_per_iteration_y = 2; |
| 156 | break; |
| 157 | } |
| 158 | default: |
| 159 | { |
| 160 | ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost"); |
| 161 | } |
| 162 | } |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 163 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 164 | // Calculate right and bottom border |
| 165 | const int input_width = input->info()->dimension(0) - kernel_size / 2 + _conv_pad_x; |
| 166 | const int input_height = input->info()->dimension(1) - kernel_size / 2 + _conv_pad_y; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 167 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 168 | // Create window and update padding |
| 169 | win = calculate_max_window(*output->info(), Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y)); |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 170 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 171 | AccessWindowStatic input_access(input->info(), -_conv_pad_x, -_conv_pad_y, input_width + num_elems_read_per_iteration_x, input_height + num_elems_read_per_iteration_y); |
| 172 | AccessWindowStatic weights_access(weights->info(), 0, 0, kernel_size, kernel_size); |
| 173 | AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 174 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 175 | update_window_and_padding(win, input_access, weights_access, output_access); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 176 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 177 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape())); |
| 178 | |
| 179 | ICLKernel::configure(win); |
| 180 | } |
| 181 | else |
| 182 | { |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 183 | bool is_quantized_fixed_point = is_data_type_fixed_point(data_type); |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame^] | 184 | bool is_quantized_asymm = is_data_type_quantized_asymmetric(data_type); |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 185 | DataType promoted_type = (is_quantized_fixed_point) ? get_promoted_data_type(data_type) : data_type; |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 186 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 187 | build_options.add_option_if(is_quantized_asymm, std::string("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size))); |
| 188 | build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type))); |
| 189 | build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type))); |
| 190 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2)))); |
| 191 | build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x))); |
| 192 | build_options.add_option_if(is_quantized_fixed_point, |
| 193 | std::string("-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position()))); |
| 194 | build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(promoted_type))); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 195 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 196 | // Create kernel |
| 197 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(is_quantized_asymm ? "direct_convolution_1x1_3x3_5x5_quantized" : kernel_name.str(), |
| 198 | build_options.options())); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 199 | |
| 200 | // Configure kernel window |
| 201 | |
| 202 | bool is_stride2 = ((kernel_size != 1) && (_conv_stride_x == 2)); |
| 203 | |
| 204 | const unsigned int num_elems_read_per_iteration_x = 8 + 2 * (kernel_size / 2) + (is_stride2 ? 6 + kernel_size / 2 : 0); |
| 205 | const unsigned int num_elems_read_per_iteration_y = kernel_size; |
| 206 | const unsigned int num_elems_written_per_iteration_x = 8; |
| 207 | const unsigned int num_elems_written_per_iteration_y = 1; |
| 208 | |
| 209 | // Calculate right and bottom border |
| 210 | const int input_width = input->info()->dimension(0) - kernel_size / 2 + _conv_pad_x; |
| 211 | const int input_height = input->info()->dimension(1) - kernel_size / 2 + _conv_pad_y; |
| 212 | |
| 213 | // Create window and update padding |
| 214 | Window win = calculate_max_window(*output->info(), Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y)); |
| 215 | |
| 216 | AccessWindowStatic input_access(input->info(), -_conv_pad_x, -_conv_pad_y, input_width + num_elems_read_per_iteration_x, input_height + num_elems_read_per_iteration_y); |
| 217 | AccessWindowStatic weights_access(weights->info(), 0, 0, kernel_size, kernel_size); |
| 218 | AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 219 | |
| 220 | update_window_and_padding(win, input_access, weights_access, output_access); |
| 221 | |
| 222 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape())); |
| 223 | |
| 224 | ICLKernel::configure(win); |
| 225 | } |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 226 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 227 | // Set static kernel arguments |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame^] | 228 | if(is_data_type_quantized_asymmetric(data_type)) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 229 | { |
| 230 | int output_multiplier = 0; |
| 231 | int output_shift = 0; |
| 232 | |
| 233 | float multiplier = _input->info()->quantization_info().scale * _weights->info()->quantization_info().scale / _output->info()->quantization_info().scale; |
| 234 | ARM_COMPUTE_THROW_ON_ERROR(quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift)); |
| 235 | |
| 236 | unsigned int idx = 3 * num_arguments_per_3D_tensor() + ((_biases != nullptr) ? num_arguments_per_1D_tensor() : 0) + 1; |
| 237 | _kernel.setArg(idx++, -_input->info()->quantization_info().offset); |
| 238 | _kernel.setArg(idx++, -_weights->info()->quantization_info().offset); |
| 239 | _kernel.setArg(idx++, _output->info()->quantization_info().offset); |
| 240 | _kernel.setArg(idx++, output_multiplier); |
| 241 | _kernel.setArg(idx++, output_shift); |
| 242 | } |
| 243 | |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 244 | // Set config_id for enabling LWS tuning |
| 245 | _config_id = "direct_convolution_"; |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 246 | _config_id += lower_string(string_from_data_type(data_type)); |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 247 | _config_id += "_"; |
| 248 | _config_id += support::cpp11::to_string(kernel_size); |
| 249 | _config_id += "_"; |
| 250 | _config_id += support::cpp11::to_string(_conv_pad_x); |
| 251 | _config_id += "_"; |
| 252 | _config_id += support::cpp11::to_string(_conv_pad_y); |
| 253 | _config_id += "_"; |
| 254 | _config_id += support::cpp11::to_string(_conv_stride_x); |
| 255 | _config_id += "_"; |
| 256 | _config_id += support::cpp11::to_string(_conv_stride_y); |
| 257 | _config_id += "_"; |
| 258 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 259 | _config_id += "_"; |
| 260 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 261 | } |
| 262 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 263 | void CLDirectConvolutionLayerKernel::run(const Window &window, cl::CommandQueue &queue) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 264 | { |
| 265 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 266 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 267 | |
| 268 | // Get initial windows |
| 269 | Window slice = window.first_slice_window_3D(); |
| 270 | Window win_in = window; |
| 271 | |
| 272 | win_in.adjust(Window::DimX, -_conv_pad_x, true); |
| 273 | win_in.adjust(Window::DimY, -_conv_pad_y, true); |
| 274 | win_in.set_dimension_step(Window::DimX, window.x().step() * _conv_stride_x); |
| 275 | win_in.set_dimension_step(Window::DimY, window.y().step() * _conv_stride_y); |
| 276 | |
| 277 | Window slice_in = win_in.first_slice_window_3D(); |
| 278 | |
| 279 | unsigned int idx1 = 2 * num_arguments_per_3D_tensor(); |
| 280 | add_3D_tensor_argument(idx1, _weights, slice); |
| 281 | |
| 282 | if(_biases != nullptr) |
| 283 | { |
| 284 | Window slice_biases; |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 285 | slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 286 | add_1D_tensor_argument(idx1, _biases, slice_biases); |
| 287 | } |
| 288 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 289 | _kernel.setArg(idx1++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3])); |
| 290 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 291 | do |
| 292 | { |
| 293 | unsigned int idx = 0; |
| 294 | add_3D_tensor_argument(idx, _input, slice_in); |
| 295 | add_3D_tensor_argument(idx, _output, slice); |
| 296 | |
| 297 | enqueue(queue, *this, slice, _lws_hint); |
| 298 | } |
| 299 | while(window.slide_window_slice_3D(slice) && win_in.slide_window_slice_3D(slice_in)); |
| 300 | } |