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 | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 42 | namespace |
| 43 | { |
| 44 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 45 | const ActivationLayerInfo &act_info) |
| 46 | { |
| 47 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
| 48 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(act_info.enabled() && ((input->data_type() != DataType::QASYMM8) || ((act_info.activation() != ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) |
| 49 | && (act_info.activation() != ActivationLayerInfo::ActivationFunction::BOUNDED_RELU) |
| 50 | && (act_info.activation() != ActivationLayerInfo::ActivationFunction::RELU))), |
| 51 | "For QASYMM8 only relu, lower bounded relu and lower-upper bounded relu are supported"); |
| 52 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 53 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(0) != 3 || weights->dimension(1) != 3); |
| 54 | ARM_COMPUTE_RETURN_ERROR_ON((input->dimension(2) * depth_multiplier) != output->dimension(2)); |
| 55 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.stride().first < 1 || conv_info.stride().first > 3); |
| 56 | |
| 57 | const bool is_qasymm = is_data_type_quantized_asymmetric(input->data_type()); |
| 58 | |
| 59 | if(biases != nullptr) |
| 60 | { |
| 61 | if(is_qasymm) |
| 62 | { |
| 63 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
| 68 | } |
| 69 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(2)); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 71 | } |
| 72 | |
| 73 | if(output->total_size() != 0) |
| 74 | { |
| 75 | const TensorShape output_shape = compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 77 | } |
| 78 | |
| 79 | return Status{}; |
| 80 | } |
| 81 | |
| 82 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 83 | GPUTarget gpu_target, std::string &kernel_name) |
| 84 | { |
| 85 | // Output auto inizialitation if not yet initialized |
| 86 | const TensorShape output_shape = compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier); |
| 87 | auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape)); |
| 88 | |
| 89 | const unsigned int conv_stride_x = conv_info.stride().first; |
| 90 | const unsigned int conv_stride_y = conv_info.stride().second; |
| 91 | const bool is_qasymm = is_data_type_quantized_asymmetric(input->data_type()); |
| 92 | const bool is_bifrost = get_arch_from_target(gpu_target) == GPUTarget::BIFROST; |
| 93 | |
| 94 | // Configure kernel window |
| 95 | unsigned int num_elems_read_per_iteration_x = 0; |
| 96 | unsigned int num_elems_read_per_iteration_y = 0; |
| 97 | unsigned int num_elems_written_per_iteration_x = 0; |
| 98 | unsigned int num_elems_written_per_iteration_y = 0; |
| 99 | |
| 100 | if(input->data_type() == DataType::F16) |
| 101 | { |
| 102 | kernel_name = "depthwise_convolution_3x3_f16"; |
| 103 | num_elems_written_per_iteration_x = 8 / data_size_from_type(input->data_type()); |
| 104 | num_elems_written_per_iteration_y = 1; |
| 105 | num_elems_read_per_iteration_y = 3; |
| 106 | switch(conv_stride_x) |
| 107 | { |
| 108 | case 1: |
| 109 | num_elems_read_per_iteration_x = 8; |
| 110 | break; |
| 111 | case 2: |
| 112 | num_elems_read_per_iteration_x = 9; |
| 113 | break; |
| 114 | case 3: |
| 115 | num_elems_read_per_iteration_x = 16; |
| 116 | break; |
| 117 | default: |
| 118 | num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * conv_stride_x; |
| 119 | break; |
| 120 | } |
| 121 | if(is_bifrost) |
| 122 | { |
| 123 | if(conv_stride_x == 1 && conv_stride_y == 1) |
| 124 | { |
| 125 | kernel_name = "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16"; |
| 126 | num_elems_read_per_iteration_x = 8; |
| 127 | num_elems_written_per_iteration_x = 4; |
| 128 | num_elems_read_per_iteration_y = 6; |
| 129 | num_elems_written_per_iteration_y = 4; |
| 130 | } |
| 131 | else if(conv_stride_x == 2 && conv_stride_y == 2) |
| 132 | { |
| 133 | kernel_name = "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16"; |
| 134 | num_elems_read_per_iteration_x = 10; |
| 135 | num_elems_written_per_iteration_x = 4; |
| 136 | num_elems_read_per_iteration_y = 5; |
| 137 | num_elems_written_per_iteration_y = 2; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | else if(input->data_type() == DataType::F32 && is_bifrost) |
| 142 | { |
| 143 | if(conv_stride_x == 1 && conv_stride_y == 1) |
| 144 | { |
| 145 | kernel_name = "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32"; |
| 146 | num_elems_read_per_iteration_x = 4; |
| 147 | num_elems_read_per_iteration_y = 6; |
| 148 | num_elems_written_per_iteration_x = 2; |
| 149 | num_elems_written_per_iteration_y = 4; |
| 150 | } |
| 151 | else if(conv_stride_x == 2 && conv_stride_y == 2) |
| 152 | { |
| 153 | kernel_name = "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32"; |
| 154 | num_elems_read_per_iteration_x = 6; |
| 155 | num_elems_read_per_iteration_y = 5; |
| 156 | num_elems_written_per_iteration_x = 2; |
| 157 | num_elems_written_per_iteration_y = 2; |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | kernel_name = "depthwise_convolution_3x3"; |
| 162 | num_elems_written_per_iteration_x = 8 / data_size_from_type(input->data_type()); |
| 163 | num_elems_written_per_iteration_y = 1; |
| 164 | num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * conv_stride_x; |
| 165 | num_elems_read_per_iteration_y = 3; |
| 166 | } |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | kernel_name = is_qasymm ? "depthwise_convolution_3x3_quantized_nchw" : "depthwise_convolution_3x3"; |
| 171 | num_elems_written_per_iteration_x = 8 / data_size_from_type(input->data_type()); |
| 172 | num_elems_written_per_iteration_y = (is_qasymm && conv_stride_y < 3) ? (2 / conv_stride_y) : 1; |
| 173 | num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * conv_stride_x; |
| 174 | num_elems_read_per_iteration_y = num_elems_written_per_iteration_y + 2; |
| 175 | } |
| 176 | |
| 177 | // Create window and update padding |
| 178 | Window win = calculate_max_window(*output, Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y)); |
| 179 | |
| 180 | AccessWindowRectangle input_access(input, -conv_info.pad_left(), -conv_info.pad_top(), |
| 181 | num_elems_read_per_iteration_x, num_elems_read_per_iteration_y, |
| 182 | conv_stride_x, conv_stride_y); |
| 183 | AccessWindowStatic weights_access(weights, 0, 0, 3, 3); |
| 184 | AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y); |
| 185 | |
| 186 | bool window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 187 | |
| 188 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 189 | |
| 190 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 191 | return std::make_pair(err, win); |
| 192 | } |
| 193 | } // namespace |
| 194 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 195 | CLDepthwiseConvolutionLayer3x3NCHWKernel::CLDepthwiseConvolutionLayer3x3NCHWKernel() |
| 196 | : _conv_stride_x(0), _conv_pad_top(0) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 197 | { |
| 198 | } |
| 199 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 200 | BorderSize CLDepthwiseConvolutionLayer3x3NCHWKernel::border_size() const |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 201 | { |
| 202 | return _border_size; |
| 203 | } |
| 204 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 205 | 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] | 206 | unsigned int depth_multiplier, |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 207 | ActivationLayerInfo act_info) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 208 | { |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 209 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 210 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 211 | bool is_qasymm = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 212 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 213 | _input = input; |
| 214 | _output = output; |
| 215 | _weights = weights; |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 216 | _biases = biases; |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 217 | _conv_stride_x = conv_info.stride().first; |
| 218 | _conv_stride_y = conv_info.stride().second; |
Jaroslaw Rzepecki | 16cdf89 | 2017-10-27 13:15:03 +0100 | [diff] [blame] | 219 | _conv_pad_left = conv_info.pad_left(); |
| 220 | _conv_pad_top = conv_info.pad_top(); |
| 221 | _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] | 222 | |
| 223 | // Set build options |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 224 | CLBuildOptions build_opts; |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 225 | build_opts.add_option("-DDEPTH_MULTIPLIER=" + support::cpp11::to_string(depth_multiplier)); |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 226 | build_opts.add_option("-DCONV_STRIDE_X=" + support::cpp11::to_string(_conv_stride_x)); |
| 227 | build_opts.add_option_if(_biases != nullptr, "-DHAS_BIAS"); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 228 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 229 | if(is_qasymm) |
| 230 | { |
| 231 | float multiplier = _input->info()->quantization_info().scale * _weights->info()->quantization_info().scale / _output->info()->quantization_info().scale; |
| 232 | int output_multiplier = 0; |
| 233 | int output_shift = 0; |
| 234 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
| 235 | |
| 236 | build_opts.add_option("-DCONV_STRIDE_Y=" + support::cpp11::to_string(_conv_stride_y)); |
| 237 | build_opts.add_option("-DINPUT_OFFSET=" + support::cpp11::to_string(-_input->info()->quantization_info().offset)); |
| 238 | build_opts.add_option("-DWEIGHTS_OFFSET=" + support::cpp11::to_string(-_weights->info()->quantization_info().offset)); |
| 239 | build_opts.add_option("-DOUTPUT_OFFSET=" + support::cpp11::to_string(_output->info()->quantization_info().offset)); |
| 240 | build_opts.add_option("-DK_OFFSET=" + support::cpp11::to_string(9 * input->info()->quantization_info().offset * weights->info()->quantization_info().offset)); |
| 241 | build_opts.add_option("-DOUTPUT_MULTIPLIER=" + support::cpp11::to_string(output_multiplier)); |
| 242 | build_opts.add_option("-DOUTPUT_SHIFT=" + support::cpp11::to_string(output_shift)); |
Giorgio Arena | 99ac60b | 2018-02-16 15:17:23 +0000 | [diff] [blame] | 243 | |
| 244 | if(act_info.enabled()) |
| 245 | { |
| 246 | const int a_val = input->info()->quantization_info().quantize(act_info.a(), RoundingPolicy::TO_NEAREST_UP); |
| 247 | const int b_val = input->info()->quantization_info().quantize(act_info.b(), RoundingPolicy::TO_NEAREST_UP); |
| 248 | const int o1 = input->info()->quantization_info().offset; |
| 249 | |
| 250 | build_opts.add_option("-DFUSED_ACTIVATION=" + lower_string(string_from_activation_func(act_info.activation()))); |
| 251 | build_opts.add_option("-DA_VAL=" + support::cpp11::to_string(a_val)); |
| 252 | build_opts.add_option("-DB_VAL=" + support::cpp11::to_string(b_val)); |
| 253 | build_opts.add_option("-DCONST_0=" + support::cpp11::to_string(o1)); |
| 254 | |
| 255 | if(output != nullptr) |
| 256 | { |
| 257 | const float s1 = input->info()->quantization_info().scale; |
| 258 | const float s2 = output->info()->quantization_info().scale; |
| 259 | const int o2 = output->info()->quantization_info().offset; |
| 260 | |
| 261 | if(o1 != o2 || s1 != s2) |
| 262 | { |
| 263 | build_opts.add_option("-DS1_VAL=" + float_to_string_with_full_precision(s1)); |
| 264 | build_opts.add_option("-DS2_VAL=" + float_to_string_with_full_precision(s2)); |
| 265 | build_opts.add_option("-DO1_VAL=" + support::cpp11::to_string(o1)); |
| 266 | build_opts.add_option("-DO2_VAL=" + support::cpp11::to_string(o2)); |
| 267 | } |
| 268 | } |
| 269 | } |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 272 | // Configure kernel window |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 273 | std::string kernel_name; |
| 274 | const GPUTarget gpu_target = get_target(); |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 275 | |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 276 | auto win_config = validate_and_configure_window(input->info(), weights->info(), output->info(), conv_info, depth_multiplier, gpu_target, kernel_name); |
| 277 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 278 | ICLKernel::configure(win_config.second); |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 279 | |
| 280 | _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] | 281 | |
Gian Marco | 85e6f51 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 282 | // Set config_id for enabling LWS tuning |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 283 | _config_id = kernel_name; |
| 284 | _config_id += "_"; |
Gian Marco | 85e6f51 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 285 | _config_id += lower_string(string_from_data_type(input->info()->data_type())); |
| 286 | _config_id += "_"; |
| 287 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 288 | _config_id += "_"; |
| 289 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 290 | _config_id += "_"; |
| 291 | _config_id += support::cpp11::to_string(input->info()->dimension(2)); |
| 292 | _config_id += "_"; |
| 293 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 294 | _config_id += "_"; |
| 295 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 298 | Status CLDepthwiseConvolutionLayer3x3NCHWKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 299 | unsigned int depth_multiplier, |
| 300 | ActivationLayerInfo act_info, GPUTarget gpu_target) |
| 301 | { |
| 302 | std::string kernel_name; |
| 303 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info, depth_multiplier, act_info)); |
| 304 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, depth_multiplier, gpu_target, kernel_name).first); |
| 305 | |
| 306 | return Status{}; |
| 307 | } |
| 308 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 309 | void CLDepthwiseConvolutionLayer3x3NCHWKernel::run(const Window &window, cl::CommandQueue &queue) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 310 | { |
| 311 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 312 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 313 | |
Georgios Pinitas | b6f182d3 | 2017-11-29 10:17:56 +0000 | [diff] [blame] | 314 | // Create input window and adjust |
| 315 | Window win_in = window; |
| 316 | win_in.adjust(Window::DimX, -_conv_pad_left, true); |
| 317 | win_in.adjust(Window::DimY, -_conv_pad_top, true); |
| 318 | win_in.set_dimension_step(Window::DimX, window.x().step() * _conv_stride_x); |
| 319 | win_in.set_dimension_step(Window::DimY, window.y().step() * _conv_stride_y); |
| 320 | |
| 321 | Window slice_in = win_in.first_slice_window_3D(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 322 | Window slice_out = window.first_slice_window_3D(); |
| 323 | Window slice_weights = window.first_slice_window_3D(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 324 | slice_weights.set_dimension_step(Window::DimX, 0); |
| 325 | slice_weights.set_dimension_step(Window::DimY, 0); |
| 326 | |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 327 | // Set biases |
| 328 | if(_biases != nullptr) |
| 329 | { |
| 330 | unsigned int idx = 3 * num_arguments_per_3D_tensor(); |
| 331 | Window slice_biases; |
| 332 | slice_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
| 333 | add_1D_tensor_argument(idx, _biases, slice_biases); |
| 334 | } |
| 335 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 336 | do |
| 337 | { |
| 338 | unsigned int idx = 0; |
| 339 | add_3D_tensor_argument(idx, _input, slice_in); |
| 340 | add_3D_tensor_argument(idx, _output, slice_out); |
| 341 | add_3D_tensor_argument(idx, _weights, slice_weights); |
| 342 | |
Anthony Barbier | a2ea753 | 2017-11-28 10:33:22 +0000 | [diff] [blame] | 343 | enqueue(queue, *this, slice_out, _lws_hint); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 344 | } |
Georgios Pinitas | b6f182d3 | 2017-11-29 10:17:56 +0000 | [diff] [blame] | 345 | 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] | 346 | } |