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