steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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" |
| 29 | #include "arm_compute/core/CL/ICLTensor.h" |
| 30 | #include "arm_compute/core/Error.h" |
| 31 | #include "arm_compute/core/Helpers.h" |
| 32 | #include "arm_compute/core/IAccessWindow.h" |
| 33 | #include "arm_compute/core/ITensor.h" |
| 34 | #include "arm_compute/core/Types.h" |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 35 | #include "arm_compute/core/Utils.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 36 | #include "arm_compute/core/Validate.h" |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 37 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 38 | #include "support/ToolchainSupport.h" |
| 39 | |
| 40 | using namespace arm_compute; |
| 41 | |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 42 | namespace |
| 43 | { |
| 44 | /** Calculates expected output shape dimension |
| 45 | * |
| 46 | * @param[in] Input shape |
| 47 | * |
| 48 | * @return Expected output shape |
| 49 | */ |
| 50 | TensorShape get_output_shape(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info) |
| 51 | { |
| 52 | unsigned int output_width = 0; |
| 53 | unsigned int output_height = 0; |
| 54 | std::tie(output_width, output_height) = scaled_dimensions(input_shape.x(), input_shape.y(), weights_shape.x(), weights_shape.y(), conv_info); |
| 55 | |
| 56 | TensorShape output_shape = input_shape; |
| 57 | output_shape.set(0, output_width); |
| 58 | output_shape.set(1, output_height); |
| 59 | output_shape.set(2, weights_shape[3]); |
| 60 | |
| 61 | return output_shape; |
| 62 | } |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 63 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 64 | 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] | 65 | { |
| 66 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F16, DataType::F32); |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 68 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) != weights->dimension(1), |
| 69 | "Weights should have same width as length"); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) != 1 && weights->dimension(0) != 3 && weights->dimension(0) != 5, |
| 71 | "Kernel sizes other than 1x1, 3x3 or 5x5 are not supported"); |
| 72 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(2) != input->dimension(2), |
| 73 | "Weights feature map dimension should match the respective input's one"); |
| 74 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(0) != weights->dimension(1), |
| 75 | "Only rectangular weights are supported!"); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->num_dimensions() > 4, |
| 77 | "Weights can be at most 4 dimensional"); |
| 78 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(0) == 1) && std::get<0>(conv_info.stride()) > 3, |
| 79 | "Strides larger than 3 not supported for 1x1 convolution."); |
| 80 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(0) == 3 || weights->dimension(0) == 5) && std::get<0>(conv_info.stride()) > 2, |
| 81 | "Strides larger than 2 not supported for 3x3 convolution."); |
| 82 | |
| 83 | if(biases != nullptr) |
| 84 | { |
| 85 | if(is_data_type_quantized_asymmetric(input->data_type())) |
| 86 | { |
| 87 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 92 | } |
| 93 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->dimension(0) != weights->dimension(3), |
| 94 | "Biases size and number of input feature maps should match"); |
| 95 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->num_dimensions() > 1, |
| 96 | "Biases should be one dimensional"); |
| 97 | } |
| 98 | |
| 99 | // Checks performed when output is configured |
| 100 | if(output->total_size() != 0) |
| 101 | { |
| 102 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), |
| 103 | get_output_shape(input->tensor_shape(), weights->tensor_shape(), conv_info)); |
| 104 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 105 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); |
| 106 | } |
| 107 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 108 | return Status{}; |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 111 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output, const PadStrideInfo &conv_info, const GPUTarget target) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 112 | { |
| 113 | const unsigned int kernel_size = weights->dimension(0); |
| 114 | const DataType data_type = input->data_type(); |
| 115 | |
| 116 | // Get convolved dimensions |
| 117 | TensorShape output_shape = get_output_shape(input->tensor_shape(), weights->tensor_shape(), conv_info); |
| 118 | |
| 119 | // Output auto inizialitation if not yet initialized |
| 120 | // FIXME: input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet). |
| 121 | auto_init_if_empty(*output, output_shape, |
| 122 | 1, |
| 123 | input->data_type(), |
| 124 | input->fixed_point_position(), |
| 125 | input->quantization_info()); |
| 126 | |
Anthony Barbier | 328891c | 2018-02-21 14:00:44 +0000 | [diff] [blame] | 127 | unsigned int conv_stride_x = std::get<0>(conv_info.stride()); |
| 128 | unsigned int conv_stride_y = std::get<1>(conv_info.stride()); |
| 129 | unsigned int conv_pad_left = conv_info.pad_left(); |
| 130 | unsigned int conv_pad_top = conv_info.pad_top(); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 131 | |
| 132 | unsigned int num_elems_read_per_iteration_x = 0; |
| 133 | unsigned int num_elems_read_per_iteration_y = 0; |
| 134 | unsigned int num_elems_written_per_iteration_x = 0; |
| 135 | unsigned int num_elems_written_per_iteration_y = 0; |
| 136 | |
Sam Laynton | 56e8e86 | 2018-04-05 13:26:08 +0100 | [diff] [blame] | 137 | if(gpu_target_is_in(target, GPUTarget::G71, GPUTarget::G72, GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT, GPUTarget::TNOX) && (kernel_size <= 5) && (conv_stride_x == 1) && (conv_stride_y == 1) && (data_type == DataType::F32)) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 138 | { |
| 139 | // Configure kernel window |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 140 | |
| 141 | switch(kernel_size) |
| 142 | { |
| 143 | case 1: |
| 144 | { |
| 145 | num_elems_read_per_iteration_x = 4; |
| 146 | num_elems_read_per_iteration_y = 4; |
| 147 | num_elems_written_per_iteration_x = 4; |
| 148 | num_elems_written_per_iteration_y = 4; |
| 149 | break; |
| 150 | } |
| 151 | case 3: |
| 152 | { |
| 153 | num_elems_read_per_iteration_x = 6; |
| 154 | num_elems_read_per_iteration_y = 5; |
| 155 | num_elems_written_per_iteration_x = 4; |
| 156 | num_elems_written_per_iteration_y = 3; |
| 157 | break; |
| 158 | } |
| 159 | case 5: |
| 160 | { |
| 161 | num_elems_read_per_iteration_x = 8; |
| 162 | num_elems_read_per_iteration_y = 6; |
| 163 | num_elems_written_per_iteration_x = 4; |
| 164 | num_elems_written_per_iteration_y = 2; |
| 165 | break; |
| 166 | } |
| 167 | default: |
| 168 | { |
| 169 | ARM_COMPUTE_ERROR("Kernel size not optimized for Bifrost"); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | else |
| 174 | { |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 175 | num_elems_read_per_iteration_y = kernel_size; |
| 176 | num_elems_written_per_iteration_x = 8; |
| 177 | num_elems_written_per_iteration_y = 1; |
Anthony Barbier | cc9fed5 | 2017-12-13 10:46:00 +0000 | [diff] [blame] | 178 | switch(kernel_size) |
| 179 | { |
| 180 | case 1: |
| 181 | switch(conv_stride_x) |
| 182 | { |
| 183 | case 1: |
| 184 | num_elems_read_per_iteration_x = 8; |
| 185 | break; |
| 186 | case 2: |
| 187 | num_elems_read_per_iteration_x = 16; |
| 188 | break; |
| 189 | case 3: |
| 190 | switch(input->element_size()) |
| 191 | { |
| 192 | case 1: |
| 193 | num_elems_read_per_iteration_x = 28; |
| 194 | break; |
| 195 | case 2: |
| 196 | num_elems_read_per_iteration_x = 24; |
| 197 | break; |
| 198 | case 4: |
| 199 | num_elems_read_per_iteration_x = 22; |
| 200 | break; |
| 201 | default: |
| 202 | ARM_COMPUTE_ERROR("Invalid data size"); |
| 203 | } |
| 204 | break; |
| 205 | default: |
| 206 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 207 | } |
| 208 | break; |
| 209 | case 3: |
| 210 | switch(conv_stride_x) |
| 211 | { |
| 212 | case 1: |
| 213 | num_elems_read_per_iteration_x = 10; |
| 214 | break; |
| 215 | case 2: |
| 216 | num_elems_read_per_iteration_x = 17; |
| 217 | break; |
| 218 | default: |
| 219 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 220 | } |
| 221 | break; |
| 222 | case 5: |
| 223 | switch(conv_stride_x) |
| 224 | { |
| 225 | case 1: |
| 226 | num_elems_read_per_iteration_x = 12; |
| 227 | break; |
| 228 | case 2: |
| 229 | num_elems_read_per_iteration_x = 20; |
| 230 | break; |
| 231 | default: |
| 232 | ARM_COMPUTE_ERROR("Invalid convolution stride X"); |
| 233 | } |
| 234 | break; |
| 235 | default: |
| 236 | ARM_COMPUTE_ERROR("Invalid direct convolution size"); |
| 237 | } |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 240 | // Create window and update padding |
Anthony Barbier | cc9fed5 | 2017-12-13 10:46:00 +0000 | [diff] [blame] | 241 | bool window_changed = false; |
| 242 | 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] | 243 | |
Georgios Pinitas | 1a03d76 | 2018-02-21 14:47:09 +0000 | [diff] [blame] | 244 | AccessWindowRectangle input_access(input, -conv_pad_left, -conv_pad_top, |
| 245 | num_elems_read_per_iteration_x, num_elems_read_per_iteration_y, |
| 246 | conv_stride_x, conv_stride_y); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 247 | AccessWindowStatic weights_access(weights, 0, 0, kernel_size, kernel_size); |
| 248 | AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 249 | |
| 250 | window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 251 | |
| 252 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 253 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 254 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 255 | return std::make_pair(err, win); |
| 256 | } |
| 257 | } // namespace |
| 258 | |
| 259 | CLDirectConvolutionLayerKernel::CLDirectConvolutionLayerKernel() |
| 260 | : _input(nullptr), _biases(nullptr), _weights(nullptr), _output(nullptr), _border_size(0), _conv_stride_x(0), _conv_stride_y(0) |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | BorderSize CLDirectConvolutionLayerKernel::border_size() const |
| 265 | { |
| 266 | return _border_size; |
| 267 | } |
| 268 | |
| 269 | void CLDirectConvolutionLayerKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info) |
| 270 | { |
| 271 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 272 | |
| 273 | const unsigned int kernel_size = weights->info()->dimension(0); |
| 274 | const DataType data_type = input->info()->data_type(); |
| 275 | |
| 276 | // Get convolved dimensions |
| 277 | TensorShape output_shape = get_output_shape(input->info()->tensor_shape(), weights->info()->tensor_shape(), conv_info); |
| 278 | |
| 279 | // Output auto inizialitation if not yet initialized |
| 280 | // FIXME: input->clone()->set_tensor_shape(output_shape) doesn't work with subtensors for grouped direct convolutions (AlexNet). |
| 281 | auto_init_if_empty(*output->info(), |
| 282 | output_shape, |
| 283 | 1, |
| 284 | input->info()->data_type(), |
| 285 | input->info()->fixed_point_position(), |
| 286 | input->info()->quantization_info()); |
| 287 | |
| 288 | // Perform validation step |
| 289 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), |
| 290 | weights->info(), |
| 291 | (biases != nullptr) ? biases->info() : nullptr, |
| 292 | output->info(), |
| 293 | conv_info)); |
| 294 | |
| 295 | _conv_stride_x = std::get<0>(conv_info.stride()); |
| 296 | _conv_stride_y = std::get<1>(conv_info.stride()); |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 297 | _border_size = BorderSize(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left()); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 298 | |
| 299 | _input = input; |
| 300 | _weights = weights; |
| 301 | _output = output; |
| 302 | _biases = biases; |
| 303 | |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 304 | const GPUTarget gpu_target = get_target(); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 305 | |
| 306 | std::stringstream kernel_name; |
| 307 | kernel_name << "direct_convolution" << kernel_size << "x" << kernel_size; |
| 308 | |
| 309 | CLBuildOptions build_options; |
| 310 | build_options.add_option_if(_biases != nullptr, std::string("-DHAS_BIAS")); |
| 311 | |
Sam Laynton | 56e8e86 | 2018-04-05 13:26:08 +0100 | [diff] [blame] | 312 | if(gpu_target_is_in(gpu_target, GPUTarget::G71, GPUTarget::G72, GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT, GPUTarget::TNOX) && (kernel_size <= 5) && (_conv_stride_x == 1) && (_conv_stride_y == 1) && (data_type == DataType::F32)) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 313 | { |
| 314 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2)))); |
| 315 | |
| 316 | kernel_name << "_f32_bifrost"; |
| 317 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_options.options())); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 318 | } |
| 319 | else |
| 320 | { |
| 321 | bool is_quantized_fixed_point = is_data_type_fixed_point(data_type); |
| 322 | bool is_quantized_asymm = is_data_type_quantized_asymmetric(data_type); |
| 323 | DataType promoted_type = (is_quantized_fixed_point) ? get_promoted_data_type(data_type) : data_type; |
| 324 | |
| 325 | build_options.add_option_if(is_quantized_asymm, std::string("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size))); |
| 326 | build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type))); |
| 327 | build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type))); |
| 328 | build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(_weights->info()->dimension(2)))); |
| 329 | build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(_conv_stride_x))); |
| 330 | build_options.add_option_if(is_quantized_fixed_point, |
| 331 | std::string("-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position()))); |
| 332 | build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(promoted_type))); |
| 333 | |
| 334 | // Create kernel |
| 335 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(is_quantized_asymm ? "direct_convolution_1x1_3x3_5x5_quantized" : kernel_name.str(), |
| 336 | build_options.options())); |
| 337 | } |
| 338 | |
| 339 | // Configure kernel window |
| 340 | auto win_config = validate_and_configure_window(input->info(), weights->info(), output->info(), conv_info, gpu_target); |
| 341 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 342 | ICLKernel::configure(win_config.second); |
| 343 | |
| 344 | // Set static kernel arguments |
| 345 | if(is_data_type_quantized_asymmetric(data_type)) |
| 346 | { |
| 347 | int output_multiplier = 0; |
| 348 | int output_shift = 0; |
| 349 | |
| 350 | float multiplier = _input->info()->quantization_info().scale * _weights->info()->quantization_info().scale / _output->info()->quantization_info().scale; |
| 351 | ARM_COMPUTE_THROW_ON_ERROR(quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift)); |
| 352 | |
| 353 | unsigned int idx = 3 * num_arguments_per_3D_tensor() + ((_biases != nullptr) ? num_arguments_per_1D_tensor() : 0) + 1; |
| 354 | _kernel.setArg(idx++, -_input->info()->quantization_info().offset); |
| 355 | _kernel.setArg(idx++, -_weights->info()->quantization_info().offset); |
| 356 | _kernel.setArg(idx++, _output->info()->quantization_info().offset); |
| 357 | _kernel.setArg(idx++, output_multiplier); |
| 358 | _kernel.setArg(idx++, output_shift); |
| 359 | } |
| 360 | |
| 361 | // Set config_id for enabling LWS tuning |
| 362 | _config_id = "direct_convolution_"; |
| 363 | _config_id += lower_string(string_from_data_type(data_type)); |
| 364 | _config_id += "_"; |
| 365 | _config_id += support::cpp11::to_string(kernel_size); |
| 366 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 367 | _config_id += support::cpp11::to_string(border_size().left); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 368 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 369 | _config_id += support::cpp11::to_string(border_size().top); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 370 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 371 | _config_id += support::cpp11::to_string(border_size().right); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 372 | _config_id += "_"; |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 373 | _config_id += support::cpp11::to_string(border_size().bottom); |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 374 | _config_id += "_"; |
| 375 | _config_id += support::cpp11::to_string(_conv_stride_x); |
| 376 | _config_id += "_"; |
| 377 | _config_id += support::cpp11::to_string(_conv_stride_y); |
| 378 | _config_id += "_"; |
| 379 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 380 | _config_id += "_"; |
| 381 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
| 382 | } |
| 383 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 384 | Status CLDirectConvolutionLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 385 | const GPUTarget target) |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 386 | { |
| 387 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info)); |
| 388 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, target).first); |
| 389 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 390 | return Status{}; |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 391 | } |
| 392 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 393 | void CLDirectConvolutionLayerKernel::run(const Window &window, cl::CommandQueue &queue) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 394 | { |
| 395 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 396 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 397 | |
| 398 | // Get initial windows |
| 399 | Window slice = window.first_slice_window_3D(); |
| 400 | Window win_in = window; |
| 401 | |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 402 | win_in.adjust(Window::DimX, -_border_size.left, true); |
| 403 | win_in.adjust(Window::DimY, -_border_size.top, true); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 404 | win_in.set_dimension_step(Window::DimX, window.x().step() * _conv_stride_x); |
| 405 | win_in.set_dimension_step(Window::DimY, window.y().step() * _conv_stride_y); |
| 406 | |
| 407 | Window slice_in = win_in.first_slice_window_3D(); |
| 408 | |
| 409 | unsigned int idx1 = 2 * num_arguments_per_3D_tensor(); |
| 410 | add_3D_tensor_argument(idx1, _weights, slice); |
| 411 | |
| 412 | if(_biases != nullptr) |
| 413 | { |
| 414 | Window slice_biases; |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 415 | slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 416 | add_1D_tensor_argument(idx1, _biases, slice_biases); |
| 417 | } |
| 418 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 419 | _kernel.setArg(idx1++, static_cast<unsigned int>(_weights->info()->strides_in_bytes()[3])); |
| 420 | |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 421 | do |
| 422 | { |
| 423 | unsigned int idx = 0; |
| 424 | add_3D_tensor_argument(idx, _input, slice_in); |
| 425 | add_3D_tensor_argument(idx, _output, slice); |
| 426 | |
| 427 | enqueue(queue, *this, slice, _lws_hint); |
| 428 | } |
| 429 | while(window.slide_window_slice_3D(slice) && win_in.slide_window_slice_3D(slice_in)); |
| 430 | } |