steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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 | */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 24 | #include "src/core/CL/kernels/CLDirectConvolutionLayerKernel.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 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 | d95c3e8 | 2021-01-19 17:39:02 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/PixelValue.h" |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/Utils.h" |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 33 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 34 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 35 | #include "src/core/AccessWindowStatic.h" |
| 36 | #include "src/core/CL/CLValidate.h" |
| 37 | #include "src/core/helpers/AutoConfiguration.h" |
| 38 | #include "src/core/helpers/WindowHelpers.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"); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 57 | 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] | 58 | "Weights feature map dimension should match the respective input's one"); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->num_dimensions() > 4, "Weights can be at most 4 dimensional"); |
| 60 | 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] | 61 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(width_idx) == 3 || weights->dimension(width_idx) == 5 || weights->dimension(width_idx) == 9) |
| 62 | && std::get<0>(conv_info.stride()) > 2, |
| 63 | "Strides larger than 2 not supported for 3x3, 5x5, 9x9 convolution."); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 64 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 65 | if(data_layout == DataLayout::NCHW) |
| 66 | { |
| 67 | if(is_data_type_quantized(input->data_type())) |
| 68 | { |
| 69 | 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, |
Gian Marco Iodice | d95c3e8 | 2021-01-19 17:39:02 +0000 | [diff] [blame] | 70 | "Kernel sizes other than 1x1, 3x3, 5x5 or 9x9 are not supported with quantized data types"); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 71 | } |
| 72 | else |
| 73 | { |
| 74 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != 1 && weights->dimension(width_idx) != 3 && weights->dimension(width_idx) != 5, |
| 75 | "Kernel sizes other than 1x1, 3x3 or 5x5 are not supported with float data types"); |
| 76 | } |
| 77 | } |
| 78 | |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 79 | if(biases != nullptr) |
| 80 | { |
| 81 | if(is_data_type_quantized_asymmetric(input->data_type())) |
| 82 | { |
| 83 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 88 | } |
| 89 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->dimension(0) != weights->dimension(3), |
| 90 | "Biases size and number of input feature maps should match"); |
| 91 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->num_dimensions() > 1, |
| 92 | "Biases should be one dimensional"); |
| 93 | } |
| 94 | |
| 95 | // Checks performed when output is configured |
| 96 | if(output->total_size() != 0) |
| 97 | { |
| 98 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 99 | misc::shape_calculator::compute_deep_convolution_shape(*input, *weights, conv_info)); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 100 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Georgios Pinitas | aa95ddc | 2020-07-21 22:45:13 +0100 | [diff] [blame] | 103 | const auto data_type = input->data_type(); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 104 | if(is_data_type_quantized(data_type)) |
| 105 | { |
| 106 | const UniformQuantizationInfo iqinfo = input->quantization_info().uniform(); |
| 107 | const UniformQuantizationInfo wqinfo = weights->quantization_info().uniform(); |
| 108 | const UniformQuantizationInfo oqinfo = output->quantization_info().uniform(); |
| 109 | |
| 110 | float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale; |
| 111 | int output_multiplier = 0; |
| 112 | int output_shift = 0; |
| 113 | ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift)); |
| 114 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 115 | return Status{}; |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 118 | inline bool can_run_optimized_kernel_for_bifrost_nchw(GPUTarget gpu_target, unsigned int conv_stride_x, unsigned int conv_stride_y, unsigned int kernel_size, |
| 119 | DataType data_type, DataLayout data_layout) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 120 | { |
Georgios Pinitas | a34286e | 2018-09-04 12:18:50 +0100 | [diff] [blame] | 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 <= 5) |
| 126 | && (conv_stride_x == 1) && (conv_stride_y == 1) |
| 127 | && (data_type == DataType::F32) |
| 128 | && (data_layout == DataLayout::NCHW); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 129 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 130 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 131 | inline void setup_num_elems_nchw(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) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 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 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 140 | const bool run_optimized_bifrost = can_run_optimized_kernel_for_bifrost_nchw(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 | } |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 177 | else |
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 | } |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output, const PadStrideInfo &conv_info, const GPUTarget target) |
| 259 | { |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 260 | const DataLayout data_layout = input->data_layout(); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 261 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 262 | // Get output shape |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 263 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*input, *weights, conv_info); |
| 264 | |
| 265 | // Output auto inizialitation if not yet initialized |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 266 | auto_init_if_empty(*output, output_shape, |
| 267 | 1, |
| 268 | input->data_type(), |
| 269 | input->quantization_info()); |
| 270 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 271 | if(data_layout == DataLayout::NHWC) |
| 272 | { |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 273 | const unsigned int vec_size = std::min(static_cast<unsigned int>(output->tensor_shape()[0]), 4u); |
| 274 | |
| 275 | // Create window and update padding |
| 276 | Window win = calculate_max_window(*output, Steps(vec_size, 1U)); |
| 277 | output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); |
| 278 | Status err = Status{}; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 279 | return std::make_pair(err, win); |
| 280 | } |
| 281 | else if(data_layout == DataLayout::NCHW) |
| 282 | { |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 283 | const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 284 | const unsigned int kernel_size = weights->dimension(width_idx); |
| 285 | |
| 286 | unsigned int num_elems_read_per_iteration_x = 0; |
| 287 | unsigned int num_elems_read_per_iteration_y = 0; |
| 288 | unsigned int num_elems_written_per_iteration_x = 0; |
| 289 | unsigned int num_elems_written_per_iteration_y = 0; |
| 290 | |
| 291 | unsigned int conv_pad_left = conv_info.pad_left(); |
| 292 | unsigned int conv_pad_top = conv_info.pad_top(); |
| 293 | unsigned int conv_stride_x = std::get<0>(conv_info.stride()); |
| 294 | unsigned int conv_stride_y = std::get<1>(conv_info.stride()); |
| 295 | |
| 296 | setup_num_elems_nchw(num_elems_read_per_iteration_x, num_elems_read_per_iteration_y, |
| 297 | num_elems_written_per_iteration_x, num_elems_written_per_iteration_y, |
| 298 | kernel_size, conv_info, target, input); |
| 299 | |
| 300 | // Create window and update padding |
| 301 | bool window_changed = false; |
| 302 | Window win = calculate_max_window(*output, Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y)); |
| 303 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 304 | 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); |
| 305 | AccessWindowStatic weights_access(weights, 0, 0, kernel_size, kernel_size); |
| 306 | AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 307 | window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 308 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 309 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 310 | return std::make_pair(err, win); |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | ARM_COMPUTE_ERROR("Not supported"); |
| 315 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 316 | } |
| 317 | } // namespace |
| 318 | |
| 319 | CLDirectConvolutionLayerKernel::CLDirectConvolutionLayerKernel() |
Giorgio Arena | 9a09180 | 2021-02-17 16:04:05 +0000 | [diff] [blame] | 320 | : _input(nullptr), _biases(nullptr), _weights(nullptr), _output(nullptr), _data_layout(DataLayout::UNKNOWN), _border_size(0), _conv_stride_x(0), _conv_stride_y(0), _conv_info() |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 321 | { |
| 322 | } |
| 323 | |
| 324 | BorderSize CLDirectConvolutionLayerKernel::border_size() const |
| 325 | { |
| 326 | return _border_size; |
| 327 | } |
| 328 | |
| 329 | void CLDirectConvolutionLayerKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info) |
| 330 | { |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 331 | configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info); |
| 332 | } |
| 333 | |
Manuel Bottini | 256c0b9 | 2020-04-21 13:29:30 +0100 | [diff] [blame] | 334 | 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] | 335 | const PadStrideInfo &conv_info) |
| 336 | { |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 337 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 338 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 339 | // Perform validation |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 340 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), |
| 341 | weights->info(), |
| 342 | (biases != nullptr) ? biases->info() : nullptr, |
| 343 | output->info(), |
| 344 | conv_info)); |
| 345 | |
| 346 | _conv_stride_x = std::get<0>(conv_info.stride()); |
| 347 | _conv_stride_y = std::get<1>(conv_info.stride()); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 348 | _data_layout = input->info()->data_layout(); |
| 349 | _input = input; |
| 350 | _weights = weights; |
| 351 | _output = output; |
| 352 | _biases = biases; |
Giorgio Arena | 9a09180 | 2021-02-17 16:04:05 +0000 | [diff] [blame] | 353 | _conv_info = conv_info; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 354 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 355 | const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 356 | const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 357 | const unsigned int channel_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL); |
| 358 | const unsigned int kernel_size = weights->info()->dimension(width_idx); |
| 359 | const DataType data_type = input->info()->data_type(); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 360 | |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 361 | const GPUTarget gpu_target = get_target(); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 362 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 363 | // Configure kernel window |
| 364 | auto win_config = validate_and_configure_window(input->info(), weights->info(), output->info(), conv_info, gpu_target); |
| 365 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 366 | ICLKernel::configure_internal(win_config.second); |
| 367 | |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 368 | std::stringstream kernel_name; |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 369 | CLBuildOptions build_options; |
| 370 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 371 | if(_data_layout == DataLayout::NHWC) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 372 | { |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 373 | _border_size = BorderSize(); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 374 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 375 | kernel_name << "direct_convolution_nhwc"; |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 376 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 377 | const unsigned int n0 = win_config.second.x().step(); |
| 378 | const unsigned int m0 = win_config.second.y().step(); |
Gian Marco Iodice | 0841ca0 | 2021-02-01 14:37:02 +0000 | [diff] [blame] | 379 | const unsigned int k0 = adjust_vec_size(16u, _input->info()->dimension(channel_idx)); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 380 | const unsigned int partial_store_n0 = _output->info()->dimension(channel_idx) % n0; |
Gian Marco Iodice | d95c3e8 | 2021-01-19 17:39:02 +0000 | [diff] [blame] | 381 | const unsigned int partial_store_m0 = (_output->info()->dimension(width_idx) * _output->info()->dimension(height_idx)) % m0; |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 382 | const unsigned int pad_left = conv_info.pad_left(); |
| 383 | const unsigned int pad_top = conv_info.pad_top(); |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 384 | |
Giorgio Arena | 9a09180 | 2021-02-17 16:04:05 +0000 | [diff] [blame] | 385 | if(_biases != nullptr) |
Teresa Charlin | 8d8a1c5 | 2021-02-03 17:01:23 +0000 | [diff] [blame] | 386 | { |
| 387 | build_options.add_option(std::string("-DHAS_BIAS")); |
| 388 | build_options.add_option(std::string("-DBIA_DATA_TYPE=" + get_cl_type_from_data_type(_biases->info()->data_type()))); |
| 389 | } |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 390 | build_options.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(_input->info()->dimension(width_idx))); |
| 391 | build_options.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(_input->info()->dimension(height_idx))); |
| 392 | build_options.add_option("-DSRC_CHANNELS=" + support::cpp11::to_string(_input->info()->dimension(channel_idx))); |
| 393 | build_options.add_option("-DSRC_DATA_TYPE=" + get_cl_type_from_data_type(_input->info()->data_type())); |
| 394 | build_options.add_option("-DDST_WIDTH=" + support::cpp11::to_string(_output->info()->dimension(width_idx))); |
| 395 | build_options.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(_output->info()->dimension(height_idx))); |
| 396 | build_options.add_option("-DDST_CHANNELS=" + support::cpp11::to_string(_output->info()->dimension(channel_idx))); |
| 397 | build_options.add_option("-DDST_DATA_TYPE=" + get_cl_type_from_data_type(_output->info()->data_type())); |
| 398 | build_options.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(_weights->info()->dimension(width_idx))); |
| 399 | build_options.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(_weights->info()->dimension(height_idx))); |
| 400 | build_options.add_option("-DWEI_DATA_TYPE=" + get_cl_type_from_data_type(_weights->info()->data_type())); |
| 401 | build_options.add_option("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x)); |
| 402 | build_options.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(_conv_stride_y)); |
| 403 | build_options.add_option("-DPAD_LEFT=" + support::cpp11::to_string(pad_left)); |
| 404 | build_options.add_option("-DPAD_TOP=" + support::cpp11::to_string(pad_top)); |
| 405 | build_options.add_option("-DN0=" + support::cpp11::to_string(n0)); |
| 406 | build_options.add_option("-DM0=" + support::cpp11::to_string(m0)); |
| 407 | build_options.add_option("-DK0=" + support::cpp11::to_string(k0)); |
| 408 | build_options.add_option("-DPARTIAL_STORE_N0=" + support::cpp11::to_string(partial_store_n0)); |
| 409 | build_options.add_option("-DPARTIAL_STORE_M0=" + support::cpp11::to_string(partial_store_m0)); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 410 | |
| 411 | if(is_data_type_quantized(data_type)) |
| 412 | { |
| 413 | const UniformQuantizationInfo iqinfo = _input->info()->quantization_info().uniform(); |
| 414 | const UniformQuantizationInfo wqinfo = _weights->info()->quantization_info().uniform(); |
| 415 | const UniformQuantizationInfo oqinfo = _output->info()->quantization_info().uniform(); |
| 416 | |
Gian Marco Iodice | d95c3e8 | 2021-01-19 17:39:02 +0000 | [diff] [blame] | 417 | PixelValue zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info()); |
| 418 | int zero_value_s32; |
| 419 | zero_value.get(zero_value_s32); |
| 420 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 421 | float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale; |
| 422 | int output_multiplier = 0; |
| 423 | int output_shift = 0; |
| 424 | quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); |
Gian Marco Iodice | d95c3e8 | 2021-01-19 17:39:02 +0000 | [diff] [blame] | 425 | build_options.add_option("-DIS_QUANTIZED"); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 426 | build_options.add_option("-DDST_MULTIPLIER=" + support::cpp11::to_string(output_multiplier)); |
| 427 | build_options.add_option("-DDST_SHIFT=" + support::cpp11::to_string(output_shift)); |
| 428 | build_options.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(-iqinfo.offset)); |
| 429 | build_options.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(-wqinfo.offset)); |
| 430 | build_options.add_option("-DDST_OFFSET=" + support::cpp11::to_string(oqinfo.offset)); |
Gian Marco Iodice | d95c3e8 | 2021-01-19 17:39:02 +0000 | [diff] [blame] | 431 | build_options.add_option("-DZERO_VALUE=" + support::cpp11::to_string(zero_value_s32)); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 432 | build_options.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(DataType::S32)); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 433 | } |
| 434 | else |
| 435 | { |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 436 | build_options.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
| 437 | build_options.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(0)); |
| 438 | build_options.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(0)); |
| 439 | build_options.add_option("-DDST_OFFSET=" + support::cpp11::to_string(0)); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | else |
| 443 | { |
Giorgio Arena | 9a09180 | 2021-02-17 16:04:05 +0000 | [diff] [blame] | 444 | _border_size = BorderSize(_input->info()->padding()); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 445 | |
| 446 | kernel_name << "direct_convolution" << kernel_size << "x" << kernel_size; |
| 447 | |
| 448 | build_options.add_option_if(_biases != nullptr, std::string("-DHAS_BIAS")); |
| 449 | |
| 450 | const bool run_optimized_for_bifrost = can_run_optimized_kernel_for_bifrost_nchw(gpu_target, _conv_stride_x, _conv_stride_y, kernel_size, data_type, _data_layout); |
| 451 | |
| 452 | if(run_optimized_for_bifrost) |
| 453 | { |
| 454 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(channel_idx)))); |
| 455 | |
| 456 | kernel_name << "_f32_bifrost"; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type))); |
| 461 | build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type))); |
| 462 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(channel_idx)))); |
| 463 | build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x))); |
| 464 | build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(data_type))); |
| 465 | |
| 466 | if(is_data_type_quantized(data_type)) |
| 467 | { |
| 468 | const UniformQuantizationInfo iqinfo = _input->info()->quantization_info().uniform(); |
| 469 | const UniformQuantizationInfo wqinfo = _weights->info()->quantization_info().uniform(); |
| 470 | const UniformQuantizationInfo oqinfo = _output->info()->quantization_info().uniform(); |
| 471 | |
| 472 | float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale; |
| 473 | int output_multiplier = 0; |
| 474 | int output_shift = 0; |
| 475 | quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); |
| 476 | build_options.add_option("-DOUTPUT_MULTIPLIER=" + support::cpp11::to_string(output_multiplier)); |
| 477 | build_options.add_option("-DOUTPUT_SHIFT=" + support::cpp11::to_string(output_shift)); |
| 478 | build_options.add_option("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size)); |
| 479 | build_options.add_option("-DINPUT_OFFSET=" + support::cpp11::to_string(-iqinfo.offset)); |
| 480 | build_options.add_option("-DWEIGHTS_OFFSET=" + support::cpp11::to_string(-wqinfo.offset)); |
| 481 | build_options.add_option("-DOUTPUT_OFFSET=" + support::cpp11::to_string(oqinfo.offset)); |
| 482 | |
| 483 | kernel_name.str("direct_convolution_quantized"); |
| 484 | } |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 485 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 488 | _kernel = create_kernel(compile_context, kernel_name.str(), build_options.options()); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 489 | |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 490 | // Set config_id for enabling LWS tuning |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 491 | _config_id = kernel_name.str(); |
| 492 | _config_id += "_"; |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 493 | _config_id += lower_string(string_from_data_type(data_type)); |
| 494 | _config_id += "_"; |
| 495 | _config_id += support::cpp11::to_string(kernel_size); |
| 496 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 497 | _config_id += support::cpp11::to_string(border_size().left); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 498 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 499 | _config_id += support::cpp11::to_string(border_size().top); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 500 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 501 | _config_id += support::cpp11::to_string(border_size().right); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 502 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 503 | _config_id += support::cpp11::to_string(border_size().bottom); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 504 | _config_id += "_"; |
| 505 | _config_id += support::cpp11::to_string(_conv_stride_x); |
| 506 | _config_id += "_"; |
| 507 | _config_id += support::cpp11::to_string(_conv_stride_y); |
| 508 | _config_id += "_"; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 509 | _config_id += support::cpp11::to_string(output->info()->dimension(width_idx)); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 510 | _config_id += "_"; |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 511 | _config_id += support::cpp11::to_string(output->info()->dimension(height_idx)); |
| 512 | _config_id += "_"; |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 513 | _config_id += lower_string(string_from_data_layout(_data_layout)); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 516 | Status CLDirectConvolutionLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 517 | const GPUTarget target) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 518 | { |
| 519 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info)); |
| 520 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, target).first); |
| 521 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 522 | return Status{}; |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 523 | } |
| 524 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 525 | void CLDirectConvolutionLayerKernel::run(const Window &window, cl::CommandQueue &queue) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 526 | { |
| 527 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 528 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 529 | |
| 530 | // Get initial windows |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 531 | Window slice = window.first_slice_window_3D(); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 532 | |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 533 | if(_data_layout == DataLayout::NHWC) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 534 | { |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 535 | slice.set(Window::DimY, Window::Dimension(0, _output->info()->dimension(1) * _output->info()->dimension(2), 1)); |
| 536 | slice.set(Window::DimZ, Window::Dimension(0, _output->info()->dimension(3), 1)); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 537 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 538 | unsigned int idx = 0; |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 539 | add_3D_tensor_argument(idx, _input, slice); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 540 | add_3D_tensor_argument(idx, _output, slice); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 541 | add_3D_tensor_argument(idx, _weights, slice); |
| 542 | if(_biases != nullptr) |
| 543 | { |
| 544 | add_1D_tensor_argument(idx, _biases, slice); |
| 545 | } |
| 546 | _kernel.setArg(idx++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3])); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 547 | enqueue(queue, *this, slice, lws_hint()); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 548 | } |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 549 | else |
| 550 | { |
| 551 | Window win_in = window; |
| 552 | |
Giorgio Arena | 9a09180 | 2021-02-17 16:04:05 +0000 | [diff] [blame] | 553 | win_in.adjust(Window::DimX, -_conv_info.pad_left(), true); |
| 554 | win_in.adjust(Window::DimY, -_conv_info.pad_top(), true); |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 555 | |
| 556 | const int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 557 | const int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 558 | |
| 559 | win_in.set_dimension_step(width_idx, window[width_idx].step() * _conv_stride_x); |
| 560 | win_in.set_dimension_step(height_idx, window[height_idx].step() * _conv_stride_y); |
| 561 | |
| 562 | Window slice_in = win_in.first_slice_window_3D(); |
| 563 | unsigned int idx1 = 2 * num_arguments_per_3D_tensor(); |
| 564 | add_3D_tensor_argument(idx1, _weights, slice); |
| 565 | |
| 566 | if(_biases != nullptr) |
| 567 | { |
| 568 | Window slice_biases; |
| 569 | slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
| 570 | add_1D_tensor_argument(idx1, _biases, slice_biases); |
| 571 | } |
| 572 | |
| 573 | _kernel.setArg(idx1++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3])); |
| 574 | |
| 575 | do |
| 576 | { |
| 577 | unsigned int idx = 0; |
| 578 | add_3D_tensor_argument(idx, _input, slice_in); |
| 579 | add_3D_tensor_argument(idx, _output, slice); |
| 580 | enqueue(queue, *this, slice, lws_hint()); |
| 581 | } |
| 582 | while(window.slide_window_slice_3D(slice) && win_in.slide_window_slice_3D(slice_in)); |
| 583 | } |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 584 | } |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 585 | } // namespace arm_compute |