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