Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 1 | /* |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018 ARM Limited. |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +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 | */ |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/CL/kernels/CLDepthwiseConvolutionLayer3x3NCHWKernel.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 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/ICLKernel.h" |
| 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/TensorInfo.h" |
| 34 | #include "arm_compute/core/Types.h" |
| 35 | #include "arm_compute/core/Utils.h" |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 36 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 37 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 38 | |
| 39 | using namespace arm_compute; |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 40 | using namespace arm_compute::misc::shape_calculator; |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 41 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 42 | CLDepthwiseConvolutionLayer3x3NCHWKernel::CLDepthwiseConvolutionLayer3x3NCHWKernel() |
| 43 | : _conv_stride_x(0), _conv_pad_top(0) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 47 | BorderSize CLDepthwiseConvolutionLayer3x3NCHWKernel::border_size() const |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 48 | { |
| 49 | return _border_size; |
| 50 | } |
| 51 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 52 | void CLDepthwiseConvolutionLayer3x3NCHWKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame^] | 53 | unsigned int depth_multiplier, |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 54 | ActivationLayerInfo act_info) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 55 | { |
Michele Di Giorgio | 933fe86 | 2018-02-19 15:42:12 +0000 | [diff] [blame] | 56 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 57 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 58 | ARM_COMPUTE_ERROR_ON(weights->info()->dimension(0) != 3 || weights->info()->dimension(1) != 3); |
| 59 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 60 | bool is_qasymm = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 61 | |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 62 | if(biases != nullptr) |
| 63 | { |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 64 | if(is_qasymm) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 65 | { |
| 66 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 71 | } |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 72 | ARM_COMPUTE_ERROR_ON(biases->info()->dimension(0) != weights->info()->dimension(2)); |
| 73 | ARM_COMPUTE_ERROR_ON(biases->info()->num_dimensions() > 1); |
| 74 | } |
| 75 | |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 76 | // Get convolved dimensions |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame^] | 77 | const TensorShape output_shape = compute_depthwise_convolution_shape(*input->info(), *weights->info(), conv_info, depth_multiplier); |
Georgios Pinitas | c26ecf8 | 2017-09-22 13:44:05 +0100 | [diff] [blame] | 78 | |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 79 | // Output auto inizialitation if not yet initialized |
| 80 | auto_init_if_empty(*output->info(), |
| 81 | output_shape, |
| 82 | 1, |
| 83 | input->info()->data_type(), |
| 84 | input->info()->fixed_point_position(), |
| 85 | input->info()->quantization_info()); |
| 86 | |
| 87 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame^] | 88 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(2) != weights->info()->dimension(2)); |
Georgios Pinitas | c26ecf8 | 2017-09-22 13:44:05 +0100 | [diff] [blame] | 89 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 90 | _input = input; |
| 91 | _output = output; |
| 92 | _weights = weights; |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 93 | _biases = biases; |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 94 | _conv_stride_x = conv_info.stride().first; |
| 95 | _conv_stride_y = conv_info.stride().second; |
Jaroslaw Rzepecki | 16cdf89 | 2017-10-27 13:15:03 +0100 | [diff] [blame] | 96 | _conv_pad_left = conv_info.pad_left(); |
| 97 | _conv_pad_top = conv_info.pad_top(); |
| 98 | _border_size = BorderSize(_conv_pad_top, conv_info.pad_right(), conv_info.pad_bottom(), _conv_pad_left); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 99 | |
| 100 | // Set build options |
Georgios Pinitas | c26ecf8 | 2017-09-22 13:44:05 +0100 | [diff] [blame] | 101 | ARM_COMPUTE_ERROR_ON(_conv_stride_x < 1 || _conv_stride_x > 3); |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 102 | CLBuildOptions build_opts; |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame^] | 103 | build_opts.add_option("-DDEPTH_MULTIPLIER=" + support::cpp11::to_string(depth_multiplier)); |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 104 | build_opts.add_option("-DCONV_STRIDE_X=" + support::cpp11::to_string(_conv_stride_x)); |
| 105 | build_opts.add_option_if(_biases != nullptr, "-DHAS_BIAS"); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 106 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 107 | if(is_qasymm) |
| 108 | { |
| 109 | float multiplier = _input->info()->quantization_info().scale * _weights->info()->quantization_info().scale / _output->info()->quantization_info().scale; |
| 110 | int output_multiplier = 0; |
| 111 | int output_shift = 0; |
| 112 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
| 113 | |
| 114 | build_opts.add_option("-DCONV_STRIDE_Y=" + support::cpp11::to_string(_conv_stride_y)); |
| 115 | build_opts.add_option("-DINPUT_OFFSET=" + support::cpp11::to_string(-_input->info()->quantization_info().offset)); |
| 116 | build_opts.add_option("-DWEIGHTS_OFFSET=" + support::cpp11::to_string(-_weights->info()->quantization_info().offset)); |
| 117 | build_opts.add_option("-DOUTPUT_OFFSET=" + support::cpp11::to_string(_output->info()->quantization_info().offset)); |
| 118 | build_opts.add_option("-DK_OFFSET=" + support::cpp11::to_string(9 * input->info()->quantization_info().offset * weights->info()->quantization_info().offset)); |
| 119 | build_opts.add_option("-DOUTPUT_MULTIPLIER=" + support::cpp11::to_string(output_multiplier)); |
| 120 | build_opts.add_option("-DOUTPUT_SHIFT=" + support::cpp11::to_string(output_shift)); |
Giorgio Arena | 99ac60b | 2018-02-16 15:17:23 +0000 | [diff] [blame] | 121 | |
| 122 | if(act_info.enabled()) |
| 123 | { |
| 124 | const int a_val = input->info()->quantization_info().quantize(act_info.a(), RoundingPolicy::TO_NEAREST_UP); |
| 125 | const int b_val = input->info()->quantization_info().quantize(act_info.b(), RoundingPolicy::TO_NEAREST_UP); |
| 126 | const int o1 = input->info()->quantization_info().offset; |
| 127 | |
| 128 | build_opts.add_option("-DFUSED_ACTIVATION=" + lower_string(string_from_activation_func(act_info.activation()))); |
| 129 | build_opts.add_option("-DA_VAL=" + support::cpp11::to_string(a_val)); |
| 130 | build_opts.add_option("-DB_VAL=" + support::cpp11::to_string(b_val)); |
| 131 | build_opts.add_option("-DCONST_0=" + support::cpp11::to_string(o1)); |
| 132 | |
| 133 | if(output != nullptr) |
| 134 | { |
| 135 | const float s1 = input->info()->quantization_info().scale; |
| 136 | const float s2 = output->info()->quantization_info().scale; |
| 137 | const int o2 = output->info()->quantization_info().offset; |
| 138 | |
| 139 | if(o1 != o2 || s1 != s2) |
| 140 | { |
| 141 | build_opts.add_option("-DS1_VAL=" + float_to_string_with_full_precision(s1)); |
| 142 | build_opts.add_option("-DS2_VAL=" + float_to_string_with_full_precision(s2)); |
| 143 | build_opts.add_option("-DO1_VAL=" + support::cpp11::to_string(o1)); |
| 144 | build_opts.add_option("-DO2_VAL=" + support::cpp11::to_string(o2)); |
| 145 | } |
| 146 | } |
| 147 | } |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 150 | const GPUTarget gpu_target = get_target(); |
Sam Laynton | 56e8e86 | 2018-04-05 13:26:08 +0100 | [diff] [blame] | 151 | const bool is_bifrost = gpu_target_is_in(gpu_target, GPUTarget::G71, GPUTarget::G72, GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT, GPUTarget::TNOX); |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 152 | |
| 153 | // Configure kernel window |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 154 | unsigned int num_elems_read_per_iteration_x = 0; |
| 155 | unsigned int num_elems_read_per_iteration_y = 0; |
| 156 | unsigned int num_elems_written_per_iteration_x = 0; |
| 157 | unsigned int num_elems_written_per_iteration_y = 0; |
| 158 | |
Anthony Barbier | a2ea753 | 2017-11-28 10:33:22 +0000 | [diff] [blame] | 159 | // Create kernel |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 160 | std::string kernel_name; |
| 161 | |
Michele Di Giorgio | 933fe86 | 2018-02-19 15:42:12 +0000 | [diff] [blame] | 162 | if(input->info()->data_type() == DataType::F16) |
| 163 | { |
| 164 | kernel_name = "depthwise_convolution_3x3_f16"; |
| 165 | num_elems_written_per_iteration_x = 8 / data_size_from_type(input->info()->data_type()); |
| 166 | num_elems_written_per_iteration_y = 1; |
Michele Di Giorgio | 933fe86 | 2018-02-19 15:42:12 +0000 | [diff] [blame] | 167 | num_elems_read_per_iteration_y = 3; |
Georgios Pinitas | 1a03d76 | 2018-02-21 14:47:09 +0000 | [diff] [blame] | 168 | switch(_conv_stride_x) |
| 169 | { |
| 170 | case 1: |
| 171 | num_elems_read_per_iteration_x = 8; |
| 172 | break; |
| 173 | case 2: |
| 174 | num_elems_read_per_iteration_x = 9; |
| 175 | break; |
| 176 | case 3: |
| 177 | num_elems_read_per_iteration_x = 16; |
| 178 | break; |
| 179 | default: |
| 180 | num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * _conv_stride_x; |
| 181 | break; |
| 182 | } |
Michele Di Giorgio | 3ebef32 | 2018-02-21 10:02:58 +0000 | [diff] [blame] | 183 | if(is_bifrost) |
| 184 | { |
| 185 | if(_conv_stride_x == 1 && _conv_stride_y == 1) |
| 186 | { |
| 187 | kernel_name = "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16"; |
| 188 | num_elems_read_per_iteration_x = 8; |
| 189 | num_elems_written_per_iteration_x = 4; |
| 190 | num_elems_read_per_iteration_y = 6; |
| 191 | num_elems_written_per_iteration_y = 4; |
| 192 | } |
| 193 | else if(_conv_stride_x == 2 && _conv_stride_y == 2) |
| 194 | { |
| 195 | kernel_name = "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16"; |
| 196 | num_elems_read_per_iteration_x = 10; |
| 197 | num_elems_written_per_iteration_x = 4; |
| 198 | num_elems_read_per_iteration_y = 5; |
| 199 | num_elems_written_per_iteration_y = 2; |
| 200 | } |
| 201 | } |
Michele Di Giorgio | 933fe86 | 2018-02-19 15:42:12 +0000 | [diff] [blame] | 202 | } |
Michele Di Giorgio | 3ebef32 | 2018-02-21 10:02:58 +0000 | [diff] [blame] | 203 | else if(input->info()->data_type() == DataType::F32 && is_bifrost) |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 204 | { |
| 205 | if(_conv_stride_x == 1 && _conv_stride_y == 1) |
| 206 | { |
Michele Di Giorgio | 3ebef32 | 2018-02-21 10:02:58 +0000 | [diff] [blame] | 207 | kernel_name = "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32"; |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 208 | num_elems_read_per_iteration_x = 4; |
| 209 | num_elems_read_per_iteration_y = 6; |
| 210 | num_elems_written_per_iteration_x = 2; |
| 211 | num_elems_written_per_iteration_y = 4; |
| 212 | } |
| 213 | else if(_conv_stride_x == 2 && _conv_stride_y == 2) |
| 214 | { |
Michele Di Giorgio | 3ebef32 | 2018-02-21 10:02:58 +0000 | [diff] [blame] | 215 | kernel_name = "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32"; |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 216 | num_elems_read_per_iteration_x = 6; |
| 217 | num_elems_read_per_iteration_y = 5; |
| 218 | num_elems_written_per_iteration_x = 2; |
| 219 | num_elems_written_per_iteration_y = 2; |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | kernel_name = "depthwise_convolution_3x3"; |
| 224 | num_elems_written_per_iteration_x = 8 / data_size_from_type(input->info()->data_type()); |
| 225 | num_elems_written_per_iteration_y = 1; |
| 226 | num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * _conv_stride_x; |
| 227 | num_elems_read_per_iteration_y = 3; |
| 228 | } |
| 229 | } |
| 230 | else |
| 231 | { |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 232 | kernel_name = is_qasymm ? "depthwise_convolution_3x3_quantized_nchw" : "depthwise_convolution_3x3"; |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 233 | num_elems_written_per_iteration_x = 8 / data_size_from_type(input->info()->data_type()); |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 234 | num_elems_written_per_iteration_y = (is_qasymm && _conv_stride_y < 3) ? (2 / _conv_stride_y) : 1; |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 235 | num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * _conv_stride_x; |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 236 | num_elems_read_per_iteration_y = num_elems_written_per_iteration_y + 2; |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 239 | // Create window and update padding |
| 240 | Window win = calculate_max_window(*output->info(), Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y)); |
| 241 | |
Georgios Pinitas | 1a03d76 | 2018-02-21 14:47:09 +0000 | [diff] [blame] | 242 | AccessWindowRectangle input_access(input->info(), -_conv_pad_left, -_conv_pad_top, |
| 243 | num_elems_read_per_iteration_x, num_elems_read_per_iteration_y, |
| 244 | _conv_stride_x, _conv_stride_y); |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 245 | AccessWindowStatic weights_access(weights->info(), 0, 0, 3, 3); |
| 246 | AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 247 | |
| 248 | update_window_and_padding(win, input_access, weights_access, output_access); |
| 249 | |
| 250 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape())); |
| 251 | |
| 252 | ICLKernel::configure(win); |
| 253 | |
| 254 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 255 | |
Gian Marco | 85e6f51 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 256 | // Set config_id for enabling LWS tuning |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 257 | _config_id = kernel_name; |
| 258 | _config_id += "_"; |
Gian Marco | 85e6f51 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 259 | _config_id += lower_string(string_from_data_type(input->info()->data_type())); |
| 260 | _config_id += "_"; |
| 261 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 262 | _config_id += "_"; |
| 263 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 264 | _config_id += "_"; |
| 265 | _config_id += support::cpp11::to_string(input->info()->dimension(2)); |
| 266 | _config_id += "_"; |
| 267 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 268 | _config_id += "_"; |
| 269 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 272 | void CLDepthwiseConvolutionLayer3x3NCHWKernel::run(const Window &window, cl::CommandQueue &queue) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 273 | { |
| 274 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 275 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 276 | |
Georgios Pinitas | b6f182d3 | 2017-11-29 10:17:56 +0000 | [diff] [blame] | 277 | // Create input window and adjust |
| 278 | Window win_in = window; |
| 279 | win_in.adjust(Window::DimX, -_conv_pad_left, true); |
| 280 | win_in.adjust(Window::DimY, -_conv_pad_top, true); |
| 281 | win_in.set_dimension_step(Window::DimX, window.x().step() * _conv_stride_x); |
| 282 | win_in.set_dimension_step(Window::DimY, window.y().step() * _conv_stride_y); |
| 283 | |
| 284 | Window slice_in = win_in.first_slice_window_3D(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 285 | Window slice_out = window.first_slice_window_3D(); |
| 286 | Window slice_weights = window.first_slice_window_3D(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 287 | slice_weights.set_dimension_step(Window::DimX, 0); |
| 288 | slice_weights.set_dimension_step(Window::DimY, 0); |
| 289 | |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 290 | // Set biases |
| 291 | if(_biases != nullptr) |
| 292 | { |
| 293 | unsigned int idx = 3 * num_arguments_per_3D_tensor(); |
| 294 | Window slice_biases; |
| 295 | slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
| 296 | add_1D_tensor_argument(idx, _biases, slice_biases); |
| 297 | } |
| 298 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 299 | do |
| 300 | { |
| 301 | unsigned int idx = 0; |
| 302 | add_3D_tensor_argument(idx, _input, slice_in); |
| 303 | add_3D_tensor_argument(idx, _output, slice_out); |
| 304 | add_3D_tensor_argument(idx, _weights, slice_weights); |
| 305 | |
Anthony Barbier | a2ea753 | 2017-11-28 10:33:22 +0000 | [diff] [blame] | 306 | enqueue(queue, *this, slice_out, _lws_hint); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 307 | } |
Georgios Pinitas | b6f182d3 | 2017-11-29 10:17:56 +0000 | [diff] [blame] | 308 | while(window.slide_window_slice_3D(slice_out) && win_in.slide_window_slice_3D(slice_in)); |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 309 | } |