steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 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" |
Vidhya Sudhan Loganathan | f1f4906 | 2018-05-25 13:21:26 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/CL/CLValidate.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/CL/ICLTensor.h" |
| 31 | #include "arm_compute/core/Error.h" |
| 32 | #include "arm_compute/core/Helpers.h" |
| 33 | #include "arm_compute/core/IAccessWindow.h" |
| 34 | #include "arm_compute/core/ITensor.h" |
| 35 | #include "arm_compute/core/Types.h" |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 36 | #include "arm_compute/core/Utils.h" |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 37 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 38 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame^] | 39 | #include "support/StringSupport.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 40 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 41 | namespace arm_compute |
| 42 | { |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 43 | namespace |
| 44 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 45 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info) |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 46 | { |
Vidhya Sudhan Loganathan | f1f4906 | 2018-05-25 13:21:26 +0100 | [diff] [blame] | 47 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Sheri Zhang | 681f2d4 | 2020-02-20 11:23:08 +0000 | [diff] [blame] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8_SIGNED, DataType::QASYMM8, DataType::F16, DataType::F32); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 50 | |
| 51 | const DataLayout data_layout = input->data_layout(); |
| 52 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 53 | const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 54 | const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 55 | |
| 56 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != weights->dimension(height_idx), "Weights should have same width and height"); |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 57 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != 1 && weights->dimension(width_idx) != 3 && weights->dimension(width_idx) != 5 && weights->dimension(width_idx) != 9, |
| 58 | "Kernel sizes other than 1x1, 3x3, 5x5 or 9x9 are not supported"); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(channel_idx) != input->dimension(channel_idx), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 60 | "Weights feature map dimension should match the respective input's one"); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 61 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->num_dimensions() > 4, "Weights can be at most 4 dimensional"); |
| 62 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(width_idx) == 1) && std::get<0>(conv_info.stride()) > 3, "Strides larger than 3 not supported for 1x1 convolution."); |
| 63 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(width_idx) == 3 || weights->dimension(width_idx) == 5) && std::get<0>(conv_info.stride()) > 2, |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 64 | "Strides larger than 2 not supported for 3x3 convolution."); |
Sang-Hoon Park | ab5b1a2 | 2019-10-15 09:29:13 +0100 | [diff] [blame] | 65 | |
| 66 | const auto data_type = input->data_type(); |
| 67 | |
| 68 | if(weights->dimension(width_idx) == 9) |
| 69 | { |
| 70 | const auto supported_data_layout = is_data_type_quantized(data_type) ? DataLayout::NCHW : DataLayout::NHWC; |
| 71 | const auto error_message = std::string("Only " + string_from_data_layout(supported_data_layout) + " layout is supported for 9x9 convolution with " + string_from_data_type( |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 72 | data_type) |
| 73 | + " type"); |
Sang-Hoon Park | ab5b1a2 | 2019-10-15 09:29:13 +0100 | [diff] [blame] | 74 | |
| 75 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((supported_data_layout != data_layout), error_message.c_str()); |
| 76 | } |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 77 | |
| 78 | if(biases != nullptr) |
| 79 | { |
| 80 | if(is_data_type_quantized_asymmetric(input->data_type())) |
| 81 | { |
| 82 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 87 | } |
| 88 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->dimension(0) != weights->dimension(3), |
| 89 | "Biases size and number of input feature maps should match"); |
| 90 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->num_dimensions() > 1, |
| 91 | "Biases should be one dimensional"); |
| 92 | } |
| 93 | |
| 94 | // Checks performed when output is configured |
| 95 | if(output->total_size() != 0) |
| 96 | { |
| 97 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 98 | misc::shape_calculator::compute_deep_convolution_shape(*input, *weights, conv_info)); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 99 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 102 | if(is_data_type_quantized(data_type)) |
| 103 | { |
| 104 | const UniformQuantizationInfo iqinfo = input->quantization_info().uniform(); |
| 105 | const UniformQuantizationInfo wqinfo = weights->quantization_info().uniform(); |
| 106 | const UniformQuantizationInfo oqinfo = output->quantization_info().uniform(); |
| 107 | |
| 108 | float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale; |
| 109 | int output_multiplier = 0; |
| 110 | int output_shift = 0; |
| 111 | ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift)); |
| 112 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 113 | return Status{}; |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 116 | inline bool can_run_optimized_kernel_for_bifrost(GPUTarget gpu_target, unsigned int conv_stride_x, unsigned int conv_stride_y, unsigned int kernel_size, |
| 117 | DataType data_type, DataLayout data_layout) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 118 | { |
Georgios Pinitas | a34286e | 2018-09-04 12:18:50 +0100 | [diff] [blame] | 119 | return gpu_target_is_in(gpu_target, |
| 120 | GPUTarget::G71, GPUTarget::G72, GPUTarget::G76, |
| 121 | GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT, |
| 122 | GPUTarget::G52, GPUTarget::G52LIT) |
| 123 | && (kernel_size <= 5) |
| 124 | && (conv_stride_x == 1) && (conv_stride_y == 1) |
| 125 | && (data_type == DataType::F32) |
| 126 | && (data_layout == DataLayout::NCHW); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 127 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 128 | |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 129 | inline bool can_run_optimized_kernel_for_bifrost_nhwc(GPUTarget gpu_target, unsigned int conv_stride_x, unsigned int conv_stride_y, unsigned int kernel_size, |
| 130 | DataType data_type, DataLayout data_layout) |
| 131 | { |
| 132 | return gpu_target_is_in(gpu_target, |
| 133 | GPUTarget::G71, GPUTarget::G72, GPUTarget::G76, |
| 134 | GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT, |
| 135 | GPUTarget::G52, GPUTarget::G52LIT) |
| 136 | && (kernel_size == 9) |
| 137 | && (conv_stride_x == 1) && (conv_stride_y == 1) |
| 138 | && (data_type == DataType::F32) |
| 139 | && (data_layout == DataLayout::NHWC); |
| 140 | } |
| 141 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 142 | inline void setup_num_elems(unsigned int &num_elems_read_per_iteration_x, unsigned int &num_elems_read_per_iteration_y, |
| 143 | unsigned int &num_elems_written_per_iteration_x, unsigned int &num_elems_written_per_iteration_y, |
| 144 | unsigned int kernel_size, const PadStrideInfo &conv_info, const GPUTarget target, ITensorInfo *input) |
| 145 | { |
| 146 | const DataType data_type = input->data_type(); |
| 147 | const DataLayout data_layout = input->data_layout(); |
| 148 | unsigned int conv_stride_x = std::get<0>(conv_info.stride()); |
| 149 | unsigned int conv_stride_y = std::get<1>(conv_info.stride()); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 150 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 151 | const bool run_optimized_bifrost = can_run_optimized_kernel_for_bifrost(target, conv_stride_x, conv_stride_y, kernel_size, data_type, data_layout); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 152 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 153 | if(run_optimized_bifrost) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 154 | { |
| 155 | // Configure kernel window |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 156 | switch(kernel_size) |
| 157 | { |
| 158 | case 1: |
| 159 | { |
| 160 | num_elems_read_per_iteration_x = 4; |
| 161 | num_elems_read_per_iteration_y = 4; |
| 162 | num_elems_written_per_iteration_x = 4; |
| 163 | num_elems_written_per_iteration_y = 4; |
| 164 | break; |
| 165 | } |
| 166 | case 3: |
| 167 | { |
| 168 | num_elems_read_per_iteration_x = 6; |
| 169 | num_elems_read_per_iteration_y = 5; |
| 170 | num_elems_written_per_iteration_x = 4; |
| 171 | num_elems_written_per_iteration_y = 3; |
| 172 | break; |
| 173 | } |
| 174 | case 5: |
| 175 | { |
| 176 | num_elems_read_per_iteration_x = 8; |
| 177 | num_elems_read_per_iteration_y = 6; |
| 178 | num_elems_written_per_iteration_x = 4; |
| 179 | num_elems_written_per_iteration_y = 2; |
| 180 | break; |
| 181 | } |
| 182 | default: |
| 183 | { |
| 184 | ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost"); |
| 185 | } |
| 186 | } |
| 187 | } |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 188 | else if(data_layout == DataLayout::NCHW) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 189 | { |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 190 | num_elems_read_per_iteration_y = kernel_size; |
| 191 | num_elems_written_per_iteration_x = 8; |
| 192 | num_elems_written_per_iteration_y = 1; |
Anthony Barbier | cc9fed5 | 2017-12-13 10:46:00 +0000 | [diff] [blame] | 193 | switch(kernel_size) |
| 194 | { |
| 195 | case 1: |
| 196 | switch(conv_stride_x) |
| 197 | { |
| 198 | case 1: |
| 199 | num_elems_read_per_iteration_x = 8; |
| 200 | break; |
| 201 | case 2: |
| 202 | num_elems_read_per_iteration_x = 16; |
| 203 | break; |
| 204 | case 3: |
| 205 | switch(input->element_size()) |
| 206 | { |
| 207 | case 1: |
| 208 | num_elems_read_per_iteration_x = 28; |
| 209 | break; |
| 210 | case 2: |
| 211 | num_elems_read_per_iteration_x = 24; |
| 212 | break; |
| 213 | case 4: |
| 214 | num_elems_read_per_iteration_x = 22; |
| 215 | break; |
| 216 | default: |
| 217 | ARM_COMPUTE_ERROR("Invalid data size"); |
| 218 | } |
| 219 | break; |
| 220 | default: |
| 221 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 222 | } |
| 223 | break; |
| 224 | case 3: |
| 225 | switch(conv_stride_x) |
| 226 | { |
| 227 | case 1: |
| 228 | num_elems_read_per_iteration_x = 10; |
| 229 | break; |
| 230 | case 2: |
| 231 | num_elems_read_per_iteration_x = 17; |
| 232 | break; |
| 233 | default: |
| 234 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 235 | } |
| 236 | break; |
| 237 | case 5: |
| 238 | switch(conv_stride_x) |
| 239 | { |
| 240 | case 1: |
| 241 | num_elems_read_per_iteration_x = 12; |
| 242 | break; |
| 243 | case 2: |
| 244 | num_elems_read_per_iteration_x = 20; |
| 245 | break; |
| 246 | default: |
| 247 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 248 | } |
| 249 | break; |
Sang-Hoon Park | ab5b1a2 | 2019-10-15 09:29:13 +0100 | [diff] [blame] | 250 | case 9: |
| 251 | switch(conv_stride_x) |
| 252 | { |
| 253 | case 1: |
| 254 | num_elems_read_per_iteration_x = 16; |
| 255 | break; |
| 256 | case 2: |
| 257 | num_elems_read_per_iteration_x = 24; |
| 258 | break; |
| 259 | default: |
| 260 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 261 | } |
| 262 | break; |
Anthony Barbier | cc9fed5 | 2017-12-13 10:46:00 +0000 | [diff] [blame] | 263 | default: |
| 264 | ARM_COMPUTE_ERROR("Invalid direct convolution size"); |
| 265 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 266 | } |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 267 | else // data_layout == NHWC |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 268 | { |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 269 | const bool run_optimized_bifrost_nhwc = can_run_optimized_kernel_for_bifrost_nhwc(target, conv_stride_x, conv_stride_y, kernel_size, data_type, data_layout); |
| 270 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 271 | num_elems_written_per_iteration_x = 1; |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 272 | |
| 273 | if(run_optimized_bifrost_nhwc) |
| 274 | { |
| 275 | num_elems_read_per_iteration_x = 4; |
| 276 | } |
giuros01 | c878f1f | 2019-07-09 11:01:34 +0100 | [diff] [blame] | 277 | else |
| 278 | { |
| 279 | num_elems_read_per_iteration_x = 1; |
| 280 | } |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 281 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 282 | switch(kernel_size) |
| 283 | { |
| 284 | case 1: |
| 285 | switch(conv_stride_x) |
| 286 | { |
| 287 | case 1: |
| 288 | num_elems_read_per_iteration_y = 8; |
| 289 | num_elems_written_per_iteration_y = 8; |
| 290 | break; |
| 291 | case 2: |
| 292 | num_elems_read_per_iteration_y = 16; |
| 293 | num_elems_written_per_iteration_y = 8; |
| 294 | break; |
| 295 | default: |
| 296 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 297 | } |
| 298 | break; |
| 299 | case 3: |
| 300 | switch(conv_stride_x) |
| 301 | { |
| 302 | case 1: |
| 303 | num_elems_read_per_iteration_y = 10; |
| 304 | num_elems_written_per_iteration_y = 8; |
| 305 | break; |
| 306 | case 2: |
| 307 | num_elems_read_per_iteration_y = 17; |
| 308 | num_elems_written_per_iteration_y = 8; |
| 309 | break; |
| 310 | default: |
| 311 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 312 | } |
| 313 | break; |
| 314 | case 5: |
| 315 | switch(conv_stride_x) |
| 316 | { |
| 317 | case 1: |
| 318 | num_elems_read_per_iteration_y = 12; |
| 319 | num_elems_written_per_iteration_y = 8; |
| 320 | break; |
| 321 | case 2: |
| 322 | num_elems_read_per_iteration_y = 20; |
| 323 | num_elems_written_per_iteration_y = 8; |
| 324 | break; |
| 325 | default: |
| 326 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 327 | } |
| 328 | break; |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 329 | case 9: |
| 330 | switch(conv_stride_x) |
| 331 | { |
| 332 | case 1: |
| 333 | num_elems_read_per_iteration_y = 16; |
| 334 | num_elems_written_per_iteration_y = 8; |
| 335 | break; |
| 336 | case 2: |
| 337 | num_elems_read_per_iteration_y = 24; |
| 338 | num_elems_written_per_iteration_y = 8; |
| 339 | break; |
| 340 | default: |
| 341 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 342 | } |
| 343 | break; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 344 | default: |
| 345 | ARM_COMPUTE_ERROR("Not implemented."); |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output, const PadStrideInfo &conv_info, const GPUTarget target) |
| 352 | { |
| 353 | const DataLayout data_layout = input->data_layout(); |
| 354 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 355 | const unsigned int kernel_size = weights->dimension(width_idx); |
| 356 | |
| 357 | // Get convolved dimensions |
| 358 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*input, *weights, conv_info); |
| 359 | |
| 360 | // Output auto inizialitation if not yet initialized |
Georgios Pinitas | f52cd78 | 2019-03-25 14:06:14 +0000 | [diff] [blame] | 361 | // TODO(COMPMID-2078): input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet). |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 362 | auto_init_if_empty(*output, output_shape, |
| 363 | 1, |
| 364 | input->data_type(), |
| 365 | input->quantization_info()); |
| 366 | |
| 367 | unsigned int num_elems_read_per_iteration_x = 0; |
| 368 | unsigned int num_elems_read_per_iteration_y = 0; |
| 369 | unsigned int num_elems_written_per_iteration_x = 0; |
| 370 | unsigned int num_elems_written_per_iteration_y = 0; |
| 371 | |
| 372 | unsigned int conv_pad_left = conv_info.pad_left(); |
| 373 | unsigned int conv_pad_top = conv_info.pad_top(); |
| 374 | unsigned int conv_stride_x = std::get<0>(conv_info.stride()); |
| 375 | unsigned int conv_stride_y = std::get<1>(conv_info.stride()); |
| 376 | |
| 377 | setup_num_elems(num_elems_read_per_iteration_x, num_elems_read_per_iteration_y, |
| 378 | num_elems_written_per_iteration_x, num_elems_written_per_iteration_y, |
| 379 | kernel_size, conv_info, target, input); |
| 380 | |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 381 | // Create window and update padding |
Anthony Barbier | cc9fed5 | 2017-12-13 10:46:00 +0000 | [diff] [blame] | 382 | bool window_changed = false; |
| 383 | Window win = calculate_max_window(*output, Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y)); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 384 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 385 | if(data_layout == DataLayout::NHWC) |
| 386 | { |
| 387 | AccessWindowStatic input_access(input, 0, -conv_pad_left, |
giuros01 | c878f1f | 2019-07-09 11:01:34 +0100 | [diff] [blame] | 388 | ceil_to_multiple(input->dimension(0), num_elems_read_per_iteration_x), |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 389 | ceil_to_multiple(input->dimension(1) + conv_info.pad_right(), num_elems_read_per_iteration_y)); |
| 390 | AccessWindowStatic weights_access(weights, 0, 0, weights->dimension(0), weights->dimension(1)); |
| 391 | AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 392 | window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 393 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 394 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 395 | return std::make_pair(err, win); |
| 396 | } |
| 397 | else if(data_layout == DataLayout::NCHW) |
| 398 | { |
| 399 | AccessWindowRectangle input_access(input, -conv_pad_left, -conv_pad_top, num_elems_read_per_iteration_x, num_elems_read_per_iteration_y, conv_stride_x, conv_stride_y); |
| 400 | AccessWindowStatic weights_access(weights, 0, 0, kernel_size, kernel_size); |
| 401 | AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 402 | window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 403 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 404 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 405 | return std::make_pair(err, win); |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | ARM_COMPUTE_ERROR("Not supported"); |
| 410 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 411 | } |
| 412 | } // namespace |
| 413 | |
| 414 | CLDirectConvolutionLayerKernel::CLDirectConvolutionLayerKernel() |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 415 | : _input(nullptr), _biases(nullptr), _weights(nullptr), _output(nullptr), _data_layout(DataLayout::UNKNOWN), _border_size(0), _conv_stride_x(0), _conv_stride_y(0) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 416 | { |
| 417 | } |
| 418 | |
| 419 | BorderSize CLDirectConvolutionLayerKernel::border_size() const |
| 420 | { |
| 421 | return _border_size; |
| 422 | } |
| 423 | |
| 424 | void CLDirectConvolutionLayerKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info) |
| 425 | { |
| 426 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 427 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 428 | _data_layout = input->info()->data_layout(); |
| 429 | const int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 430 | const int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 431 | const int channel_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 432 | |
| 433 | const unsigned int kernel_size = weights->info()->dimension(width_idx); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 434 | const DataType data_type = input->info()->data_type(); |
| 435 | |
| 436 | // Get convolved dimensions |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 437 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*input->info(), *weights->info(), conv_info); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 438 | |
| 439 | // Output auto inizialitation if not yet initialized |
Georgios Pinitas | f52cd78 | 2019-03-25 14:06:14 +0000 | [diff] [blame] | 440 | // TODO(COMPMID-2078): input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet). |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 441 | auto_init_if_empty(*output->info(), |
| 442 | output_shape, |
| 443 | 1, |
| 444 | input->info()->data_type(), |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 445 | input->info()->quantization_info()); |
| 446 | |
| 447 | // Perform validation step |
| 448 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), |
| 449 | weights->info(), |
| 450 | (biases != nullptr) ? biases->info() : nullptr, |
| 451 | output->info(), |
| 452 | conv_info)); |
| 453 | |
| 454 | _conv_stride_x = std::get<0>(conv_info.stride()); |
| 455 | _conv_stride_y = std::get<1>(conv_info.stride()); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 456 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 457 | if(_data_layout == DataLayout::NHWC) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 458 | { |
| 459 | _border_size = BorderSize(conv_info.pad_left(), 0, conv_info.pad_right(), 0); |
| 460 | } |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 461 | else if(_data_layout == DataLayout::NCHW) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 462 | { |
| 463 | _border_size = BorderSize(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left()); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | ARM_COMPUTE_ERROR("Not supported"); |
| 468 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 469 | |
| 470 | _input = input; |
| 471 | _weights = weights; |
| 472 | _output = output; |
| 473 | _biases = biases; |
| 474 | |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 475 | const GPUTarget gpu_target = get_target(); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 476 | |
| 477 | std::stringstream kernel_name; |
| 478 | kernel_name << "direct_convolution" << kernel_size << "x" << kernel_size; |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 479 | if(_data_layout == DataLayout::NHWC) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 480 | { |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 481 | kernel_name << "_" << lower_string(string_from_data_layout(_data_layout)); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 482 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 483 | |
| 484 | CLBuildOptions build_options; |
| 485 | build_options.add_option_if(_biases != nullptr, std::string("-DHAS_BIAS")); |
| 486 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 487 | const bool run_optimized_for_bifrost = can_run_optimized_kernel_for_bifrost(gpu_target, _conv_stride_x, _conv_stride_y, kernel_size, data_type, _data_layout); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 488 | |
| 489 | if(run_optimized_for_bifrost) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 490 | { |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 491 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(channel_idx)))); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 492 | |
| 493 | kernel_name << "_f32_bifrost"; |
| 494 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_options.options())); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 495 | } |
| 496 | else |
| 497 | { |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 498 | build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type))); |
| 499 | build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type))); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 500 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(channel_idx)))); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 501 | build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x))); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 502 | if(_data_layout == DataLayout::NHWC) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 503 | { |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 504 | const bool run_optimized_for_bifrost_nhwc = can_run_optimized_kernel_for_bifrost_nhwc(gpu_target, _conv_stride_x, _conv_stride_y, kernel_size, data_type, _data_layout); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 505 | build_options.add_option(std::string("-DDATA_LAYOUT_NHWC=1")); |
| 506 | build_options.add_option(std::string("-DDST_HEIGHT=" + support::cpp11::to_string(_output->info()->dimension(height_idx)))); |
| 507 | build_options.add_option(std::string("-DDST_WIDTH=" + support::cpp11::to_string(_output->info()->dimension(width_idx)))); |
| 508 | build_options.add_option(std::string("-DSRC_HEIGHT=" + support::cpp11::to_string(_input->info()->dimension(height_idx)))); |
| 509 | build_options.add_option(std::string("-DSRC_WIDTH=" + support::cpp11::to_string(_input->info()->dimension(width_idx)))); |
| 510 | build_options.add_option(std::string("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left()))); |
| 511 | build_options.add_option(std::string("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top()))); |
Giorgio Arena | 3c4bf0c | 2020-03-02 09:49:29 +0000 | [diff] [blame] | 512 | build_options.add_option(std::string("-DPAD_BOTTOM=" + support::cpp11::to_string(conv_info.pad_bottom()))); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 513 | build_options.add_option(std::string("-DSTRIDE_Y=" + support::cpp11::to_string(_conv_stride_y))); |
Michalis Spyrou | 4509173 | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 514 | if(run_optimized_for_bifrost_nhwc) |
| 515 | { |
| 516 | const unsigned int num_elems_read_per_iteration_x = 4; |
| 517 | _border_size.right = num_elems_read_per_iteration_x; |
| 518 | build_options.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_read_per_iteration_x)); |
| 519 | } |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 520 | } |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 521 | build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(data_type))); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 522 | |
| 523 | if(is_data_type_quantized(data_type)) |
| 524 | { |
| 525 | const UniformQuantizationInfo iqinfo = _input->info()->quantization_info().uniform(); |
| 526 | const UniformQuantizationInfo wqinfo = _weights->info()->quantization_info().uniform(); |
| 527 | const UniformQuantizationInfo oqinfo = _output->info()->quantization_info().uniform(); |
| 528 | |
| 529 | float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale; |
| 530 | int output_multiplier = 0; |
| 531 | int output_shift = 0; |
| 532 | quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); |
| 533 | build_options.add_option("-DOUTPUT_MULTIPLIER=" + support::cpp11::to_string(output_multiplier)); |
| 534 | build_options.add_option("-DOUTPUT_SHIFT=" + support::cpp11::to_string(output_shift)); |
| 535 | build_options.add_option("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size)); |
| 536 | |
| 537 | // Create kernel |
| 538 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("direct_convolution_quantized", build_options.options())); |
| 539 | |
| 540 | // Set static kernel arguments |
| 541 | unsigned int idx = 3 * num_arguments_per_3D_tensor() + ((_biases != nullptr) ? num_arguments_per_1D_tensor() : 0) + 1; |
| 542 | _kernel.setArg(idx++, -iqinfo.offset); |
| 543 | _kernel.setArg(idx++, -wqinfo.offset); |
| 544 | _kernel.setArg(idx++, oqinfo.offset); |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | // Create kernel |
| 549 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_options.options())); |
| 550 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // Configure kernel window |
| 554 | auto win_config = validate_and_configure_window(input->info(), weights->info(), output->info(), conv_info, gpu_target); |
| 555 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 556 | ICLKernel::configure_internal(win_config.second); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 557 | |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 558 | // Set config_id for enabling LWS tuning |
| 559 | _config_id = "direct_convolution_"; |
| 560 | _config_id += lower_string(string_from_data_type(data_type)); |
| 561 | _config_id += "_"; |
| 562 | _config_id += support::cpp11::to_string(kernel_size); |
| 563 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 564 | _config_id += support::cpp11::to_string(border_size().left); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 565 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 566 | _config_id += support::cpp11::to_string(border_size().top); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 567 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 568 | _config_id += support::cpp11::to_string(border_size().right); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 569 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 570 | _config_id += support::cpp11::to_string(border_size().bottom); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 571 | _config_id += "_"; |
| 572 | _config_id += support::cpp11::to_string(_conv_stride_x); |
| 573 | _config_id += "_"; |
| 574 | _config_id += support::cpp11::to_string(_conv_stride_y); |
| 575 | _config_id += "_"; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 576 | _config_id += support::cpp11::to_string(output->info()->dimension(width_idx)); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 577 | _config_id += "_"; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 578 | _config_id += support::cpp11::to_string(output->info()->dimension(height_idx)); |
| 579 | _config_id += "_"; |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 580 | _config_id += lower_string(string_from_data_layout(_data_layout)); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 583 | Status CLDirectConvolutionLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 584 | const GPUTarget target) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 585 | { |
| 586 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info)); |
| 587 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, target).first); |
| 588 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 589 | return Status{}; |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 590 | } |
| 591 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 592 | void CLDirectConvolutionLayerKernel::run(const Window &window, cl::CommandQueue &queue) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 593 | { |
| 594 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 595 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 596 | |
| 597 | // Get initial windows |
| 598 | Window slice = window.first_slice_window_3D(); |
| 599 | Window win_in = window; |
| 600 | |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 601 | win_in.adjust(Window::DimX, -_border_size.left, true); |
| 602 | win_in.adjust(Window::DimY, -_border_size.top, true); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 603 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 604 | const int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 605 | const int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 606 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 607 | win_in.set_dimension_step(width_idx, window[width_idx].step() * _conv_stride_x); |
| 608 | win_in.set_dimension_step(height_idx, window[height_idx].step() * _conv_stride_y); |
| 609 | |
| 610 | Window slice_in = win_in.first_slice_window_3D(); |
| 611 | unsigned int idx1 = 2 * num_arguments_per_3D_tensor(); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 612 | add_3D_tensor_argument(idx1, _weights, slice); |
| 613 | |
| 614 | if(_biases != nullptr) |
| 615 | { |
| 616 | Window slice_biases; |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 617 | slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 618 | add_1D_tensor_argument(idx1, _biases, slice_biases); |
| 619 | } |
| 620 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 621 | _kernel.setArg(idx1++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3])); |
| 622 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 623 | do |
| 624 | { |
| 625 | unsigned int idx = 0; |
| 626 | add_3D_tensor_argument(idx, _input, slice_in); |
| 627 | add_3D_tensor_argument(idx, _output, slice); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 628 | enqueue(queue, *this, slice, lws_hint()); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 629 | } |
| 630 | while(window.slide_window_slice_3D(slice) && win_in.slide_window_slice_3D(slice_in)); |
| 631 | } |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 632 | } // namespace arm_compute |