Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 1 | /* |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 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 | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/runtime/CL/functions/CLDepthwiseConvolutionLayer.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/ICLTensor.h" |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/kernels/CLDepthwiseConvolutionLayer3x3NCHWKernel.h" |
| 28 | #include "arm_compute/core/CL/kernels/CLDepthwiseConvolutionLayer3x3NHWCKernel.h" |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Helpers.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/PixelValue.h" |
Georgios Pinitas | 9be0c5a | 2018-02-19 12:46:29 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Georgios Pinitas | de5a1cc | 2018-02-02 12:52:07 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/CL/CLScheduler.h" |
| 34 | #include "support/ToolchainSupport.h" |
| 35 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 36 | namespace arm_compute |
| 37 | { |
Georgios Pinitas | de5a1cc | 2018-02-02 12:52:07 +0000 | [diff] [blame] | 38 | using namespace arm_compute::misc; |
Georgios Pinitas | 9be0c5a | 2018-02-19 12:46:29 +0000 | [diff] [blame] | 39 | using namespace arm_compute::misc::shape_calculator; |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 40 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 41 | namespace |
| 42 | { |
| 43 | Status validate_arguments_3x3(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 44 | unsigned int depth_multiplier, ActivationLayerInfo act_info, GPUTarget gpu_target, const Size2D &dilation) |
| 45 | { |
| 46 | // This function should be removed and incorporated inside CLDepthwiseConvolutionLayerInternal3x3 once CLDepthwiseConvolutionLayer3x3 is properly removed |
| 47 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() == DataLayout::UNKNOWN); |
| 50 | |
| 51 | const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); |
| 52 | const bool is_nhwc = input->data_layout() == DataLayout::NHWC; |
| 53 | const bool needs_permute = is_nhwc && (depth_multiplier > 1); |
| 54 | const bool needs_weights_reshape = is_nhwc && (depth_multiplier == 1) && is_quantized; |
| 55 | const bool is_stride_1 = ((conv_info.stride().first == conv_info.stride().second) && (conv_info.stride().first == 1)); |
| 56 | const bool is_stride_1_dilation_1 = (is_stride_1 && dilation.x() == 1 && dilation.y() == 1); |
| 57 | const bool is_dot8_supported = dot8_supported(CLKernelLibrary::get().get_device()); |
| 58 | DepthwiseConvolutionReshapeInfo info; |
| 59 | info.c0 = 4; |
| 60 | info.transpose = is_stride_1_dilation_1 && is_dot8_supported; |
| 61 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 62 | TensorInfo output_multipliers_shifts_info(TensorInfo(TensorShape(1U), 1, DataType::S32)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 63 | if(is_quantized) |
| 64 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 65 | if(is_data_type_quantized_per_channel(weights->data_type())) |
| 66 | { |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QSYMM8_PER_CHANNEL); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 68 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 69 | const size_t idx_c = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::CHANNEL); |
| 70 | output_multipliers_shifts_info.set_tensor_shape(TensorShape(weights->dimension(idx_c))); |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 75 | } |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | if(needs_permute) |
| 79 | { |
| 80 | TensorShape permuted_input_shape = input->tensor_shape(); |
| 81 | TensorShape permuted_weights_shape = weights->tensor_shape(); |
| 82 | TensorShape permuted_output_shape = shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier, dilation); |
| 83 | |
| 84 | permute(permuted_input_shape, PermutationVector(1U, 2U, 0U)); |
| 85 | permute(permuted_weights_shape, PermutationVector(1U, 2U, 0U)); |
| 86 | permute(permuted_output_shape, PermutationVector(1U, 2U, 0U)); |
| 87 | |
| 88 | const TensorInfo permuted_input = input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_input_shape).set_data_layout(DataLayout::NCHW); |
| 89 | const TensorInfo permuted_weights = weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_weights_shape).set_data_layout(DataLayout::NCHW); |
| 90 | const TensorInfo permuted_output = output->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_output_shape).set_data_layout(DataLayout::NCHW); |
| 91 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 92 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthwiseConvolutionLayer3x3NCHWKernel::validate(&permuted_input, &permuted_weights, biases, &permuted_output, |
| 93 | conv_info, depth_multiplier, act_info, gpu_target, |
| 94 | dilation, &output_multipliers_shifts_info, &output_multipliers_shifts_info)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 95 | } |
| 96 | else if(is_nhwc) |
| 97 | { |
| 98 | if(needs_weights_reshape) |
| 99 | { |
| 100 | auto reshaped_weights_shape = arm_compute::misc::shape_calculator::compute_reshaped_depthwise_weights_shape(*weights, info); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 101 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthwiseConvolutionLayer3x3NHWCKernel::validate(input, &weights->clone()->set_tensor_shape(reshaped_weights_shape), biases, |
| 102 | output, conv_info, depth_multiplier, act_info, |
| 103 | dilation, &output_multipliers_shifts_info, &output_multipliers_shifts_info)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 104 | } |
| 105 | else |
| 106 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 107 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthwiseConvolutionLayer3x3NHWCKernel::validate(input, weights, biases, output, conv_info, depth_multiplier, act_info, |
| 108 | dilation, &output_multipliers_shifts_info, &output_multipliers_shifts_info)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | else |
| 112 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 113 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthwiseConvolutionLayer3x3NCHWKernel::validate(input, weights, biases, output, conv_info, depth_multiplier, act_info, gpu_target, |
| 114 | dilation, &output_multipliers_shifts_info, &output_multipliers_shifts_info)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 115 | } |
| 116 | return Status{}; |
| 117 | } |
| 118 | } // namespace |
| 119 | |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 120 | CLDepthwiseConvolutionLayer3x3::CLDepthwiseConvolutionLayer3x3(std::shared_ptr<IMemoryManager> memory_manager) |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 121 | : _func(std::move(memory_manager)) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 122 | { |
| 123 | } |
| 124 | |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 125 | void CLDepthwiseConvolutionLayer3x3::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 126 | ActivationLayerInfo act_info, const Size2D &dilation) |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 127 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 128 | _func.configure(input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation); |
| 129 | } |
| 130 | |
| 131 | Status CLDepthwiseConvolutionLayer3x3::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 132 | unsigned int depth_multiplier, ActivationLayerInfo act_info, GPUTarget gpu_target, const Size2D &dilation) |
| 133 | { |
| 134 | return validate_arguments_3x3(input, weights, biases, output, conv_info, depth_multiplier, act_info, gpu_target, dilation); |
| 135 | } |
| 136 | |
| 137 | void CLDepthwiseConvolutionLayer3x3::run() |
| 138 | { |
| 139 | _func.run(); |
| 140 | } |
| 141 | |
| 142 | void CLDepthwiseConvolutionLayer3x3::prepare() |
| 143 | { |
| 144 | _func.prepare(); |
| 145 | } |
| 146 | |
| 147 | CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerGeneric::CLDepthwiseConvolutionLayerGeneric(std::shared_ptr<IMemoryManager> memory_manager) |
| 148 | : _memory_group(std::move(memory_manager)), |
| 149 | _dwc_native_kernel(), |
| 150 | _permute_input_to_nhwc(), |
| 151 | _permute_weights_to_nhwc(), |
| 152 | _permute_output_to_nchw(), |
| 153 | _permuted_input(), |
| 154 | _permuted_weights(), |
| 155 | _permuted_output(), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 156 | _output_multipliers(), |
| 157 | _output_shifts(), |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 158 | _original_weights(), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 159 | _input(), |
| 160 | _output(), |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 161 | _needs_permute(false), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 162 | _is_prepared(false), |
| 163 | _is_quantized(false) |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 164 | { |
| 165 | } |
| 166 | |
| 167 | void CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerGeneric::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, |
| 168 | unsigned int depth_multiplier, const ActivationLayerInfo &act_info, const Size2D &dilation) |
| 169 | { |
| 170 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 171 | ARM_COMPUTE_ERROR_THROW_ON(CLDepthwiseConvolutionLayer::validate(input->info(), |
| 172 | weights->info(), |
| 173 | biases != nullptr ? biases->info() : nullptr, |
| 174 | output->info(), |
| 175 | conv_info, |
| 176 | depth_multiplier, |
| 177 | act_info, |
| 178 | dilation)); |
| 179 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 180 | _is_quantized = is_data_type_quantized(input->info()->data_type()); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 181 | _is_prepared = false; |
| 182 | _original_weights = weights; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 183 | _input = input; |
| 184 | _output = output; |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 185 | _needs_permute = input->info()->data_layout() == DataLayout::NCHW; |
| 186 | |
| 187 | ICLTensor *input_to_use = input; |
| 188 | const ICLTensor *weights_to_use = weights; |
| 189 | ICLTensor *output_to_use = output; |
| 190 | if(_needs_permute) |
| 191 | { |
| 192 | _memory_group.manage(&_permuted_input); |
| 193 | _memory_group.manage(&_permuted_output); |
| 194 | |
| 195 | // Configure the function to transform the input tensor from NCHW -> NHWC |
| 196 | _permute_input_to_nhwc.configure(input, &_permuted_input, PermutationVector(2U, 0U, 1U)); |
| 197 | _permuted_input.info()->set_data_layout(DataLayout::NHWC); |
| 198 | |
| 199 | // Configure the function to transform the weights tensor from IHW -> HWI |
| 200 | _permute_weights_to_nhwc.configure(weights, &_permuted_weights, PermutationVector(2U, 0U, 1U)); |
| 201 | _permuted_weights.info()->set_data_layout(DataLayout::NHWC); |
| 202 | |
| 203 | // Set output quantization info before dwc kernel configure |
| 204 | _permuted_output.info()->set_quantization_info(output->info()->quantization_info()); |
| 205 | |
| 206 | input_to_use = &_permuted_input; |
| 207 | weights_to_use = &_permuted_weights; |
| 208 | output_to_use = &_permuted_output; |
| 209 | } |
| 210 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 211 | CLTensor *output_multipliers_to_use = nullptr; |
| 212 | CLTensor *output_shifts_to_use = nullptr; |
| 213 | if(_is_quantized) |
| 214 | { |
| 215 | const size_t idx_c = get_data_layout_dimension_index(weights->info()->data_layout(), DataLayoutDimension::CHANNEL); |
| 216 | const size_t num_filters = (is_data_type_quantized_per_channel(weights->info()->data_type())) ? weights->info()->dimension(idx_c) : 1; |
| 217 | |
| 218 | _output_multipliers.allocator()->init(TensorInfo(TensorShape(num_filters), 1, DataType::S32)); |
| 219 | _output_shifts.allocator()->init(TensorInfo(TensorShape(num_filters), 1, DataType::S32)); |
| 220 | |
| 221 | output_multipliers_to_use = &_output_multipliers; |
| 222 | output_shifts_to_use = &_output_shifts; |
| 223 | } |
| 224 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 225 | DWCWeightsKernelInfo dwc_weights_info; |
| 226 | dwc_weights_info.n0 = (depth_multiplier == 1) ? 8 : 1; |
| 227 | DWCKernelInfo dwc_info; |
| 228 | dwc_info.activation_info = act_info; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 229 | _dwc_native_kernel.configure(input_to_use, weights_to_use, biases, output_to_use, |
| 230 | dwc_weights_info, dwc_info, conv_info, depth_multiplier, dilation, |
| 231 | output_multipliers_to_use, output_shifts_to_use); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 232 | |
| 233 | if(_needs_permute) |
| 234 | { |
| 235 | _permuted_input.allocator()->allocate(); |
| 236 | |
| 237 | // Configure the function to transform the convoluted output to NCHW format |
| 238 | _permuted_output.info()->set_data_layout(DataLayout::NCHW); |
| 239 | _permute_output_to_nchw.configure(&_permuted_output, output, PermutationVector(1U, 2U, 0U)); |
| 240 | _permuted_output.allocator()->allocate(); |
| 241 | } |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 242 | |
| 243 | if(_is_quantized) |
| 244 | { |
| 245 | _output_multipliers.allocator()->allocate(); |
| 246 | _output_shifts.allocator()->allocate(); |
| 247 | } |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | Status CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerGeneric::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, |
| 251 | const PadStrideInfo &conv_info, |
| 252 | unsigned int depth_multiplier, const ActivationLayerInfo &act_info, const Size2D &dilation) |
| 253 | { |
| 254 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output); |
| 255 | const size_t idx_w = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH); |
| 256 | const size_t idx_h = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT); |
| 257 | |
| 258 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_w) + (weights->dimension(idx_w) - 1) * (dilation.x() - 1) > input->dimension(idx_w) + conv_info.pad_left() + conv_info.pad_right()); |
| 259 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_h) + (weights->dimension(idx_h) - 1) * (dilation.y() - 1) > input->dimension(idx_h) + conv_info.pad_top() + conv_info.pad_bottom()); |
| 260 | |
| 261 | DWCWeightsKernelInfo dwc_weights_info; |
| 262 | dwc_weights_info.n0 = (depth_multiplier == 1) ? 8 : 1; |
| 263 | DWCKernelInfo dwc_info; |
| 264 | dwc_info.activation_info = act_info; |
| 265 | |
| 266 | const bool needs_permute = input->data_layout() == DataLayout::NCHW; |
| 267 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 268 | const bool is_quantized = is_data_type_quantized(input->data_type()); |
| 269 | |
| 270 | TensorInfo output_multipliers_shifts_info(TensorInfo(TensorShape(1U), 1, DataType::S32)); |
| 271 | if(is_quantized) |
| 272 | { |
| 273 | if(is_data_type_quantized_per_channel(weights->data_type())) |
| 274 | { |
| 275 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QSYMM8_PER_CHANNEL); |
| 276 | |
| 277 | const size_t idx_c = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::CHANNEL); |
| 278 | output_multipliers_shifts_info.set_tensor_shape(TensorShape(weights->dimension(idx_c))); |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 283 | } |
| 284 | } |
| 285 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 286 | if(needs_permute) |
| 287 | { |
| 288 | TensorShape permuted_input_shape = input->tensor_shape(); |
| 289 | TensorShape permuted_weights_shape = weights->tensor_shape(); |
| 290 | TensorShape permuted_output_shape = shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier, dilation); |
| 291 | |
| 292 | permute(permuted_input_shape, PermutationVector(2U, 0U, 1U)); |
| 293 | permute(permuted_weights_shape, PermutationVector(2U, 0U, 1U)); |
| 294 | permute(permuted_output_shape, PermutationVector(2U, 0U, 1U)); |
| 295 | |
| 296 | const TensorInfo permuted_input = input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_input_shape).set_data_layout(DataLayout::NHWC); |
| 297 | const TensorInfo permuted_weights = weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_weights_shape).set_data_layout(DataLayout::NHWC); |
| 298 | const TensorInfo permuted_output = output->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_output_shape).set_data_layout(DataLayout::NHWC); |
| 299 | |
| 300 | ARM_COMPUTE_RETURN_ON_ERROR(CLPermute::validate(input, &permuted_input, PermutationVector(2U, 0U, 1U))); |
| 301 | ARM_COMPUTE_RETURN_ON_ERROR(CLPermute::validate(weights, &permuted_weights, PermutationVector(2U, 0U, 1U))); |
| 302 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthwiseConvolutionLayerNativeKernel::validate(&permuted_input, &permuted_weights, biases, &permuted_output, dwc_weights_info, |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 303 | dwc_info, conv_info, depth_multiplier, dilation, |
| 304 | &output_multipliers_shifts_info, &output_multipliers_shifts_info)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 305 | ARM_COMPUTE_RETURN_ON_ERROR(CLPermute::validate(&permuted_output, output, PermutationVector(1U, 2U, 0U))); |
| 306 | } |
| 307 | else |
| 308 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 309 | ARM_COMPUTE_RETURN_ON_ERROR(CLDepthwiseConvolutionLayerNativeKernel::validate(input, weights, biases, output, dwc_weights_info, dwc_info, conv_info, depth_multiplier, |
| 310 | dilation, &output_multipliers_shifts_info, &output_multipliers_shifts_info)); |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 311 | } |
| 312 | return Status{}; |
| 313 | } |
| 314 | |
| 315 | void CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerGeneric::run() |
| 316 | { |
| 317 | prepare(); |
| 318 | |
| 319 | MemoryGroupResourceScope scope_mg(_memory_group); |
| 320 | |
| 321 | if(_needs_permute) |
| 322 | { |
| 323 | _permute_input_to_nhwc.run(); |
| 324 | } |
| 325 | CLScheduler::get().enqueue(_dwc_native_kernel); |
| 326 | if(_needs_permute) |
| 327 | { |
| 328 | _permute_output_to_nchw.run(); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerGeneric::prepare() |
| 333 | { |
| 334 | if(!_is_prepared) |
| 335 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 336 | if(_is_quantized) |
| 337 | { |
| 338 | _output_multipliers.map(); |
| 339 | _output_shifts.map(); |
| 340 | quantization::compute_quantized_multipliers_and_shifts(_input, |
| 341 | _original_weights, |
| 342 | _output, |
| 343 | reinterpret_cast<int32_t *>(_output_multipliers.ptr_to_element(Coordinates(0))), |
| 344 | reinterpret_cast<int32_t *>(_output_shifts.ptr_to_element(Coordinates(0)))); |
| 345 | _output_multipliers.unmap(); |
| 346 | _output_shifts.unmap(); |
| 347 | } |
| 348 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 349 | if(_needs_permute) |
| 350 | { |
| 351 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
| 352 | |
| 353 | _permuted_weights.allocator()->allocate(); |
| 354 | _permute_weights_to_nhwc.run(); |
| 355 | _original_weights->mark_as_unused(); |
| 356 | } |
| 357 | _is_prepared = true; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerInternal3x3::CLDepthwiseConvolutionLayerInternal3x3(std::shared_ptr<IMemoryManager> memory_manager) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 362 | : _memory_group(std::move(memory_manager)), |
| 363 | _kernel(nullptr), |
| 364 | _border_handler(), |
| 365 | _permute_input_to_nchw(), |
| 366 | _permute_weights_to_nchw(), |
| 367 | _permute_output_to_nhwc(), |
| 368 | _reshape_weights(), |
| 369 | _permuted_input(), |
| 370 | _permuted_weights(), |
| 371 | _permuted_output(), |
| 372 | _output_multipliers(), |
| 373 | _output_shifts(), |
| 374 | _original_weights(nullptr), |
| 375 | _input(nullptr), |
| 376 | _output(nullptr), |
| 377 | _needs_permute(false), |
| 378 | _needs_weights_reshape(false), |
| 379 | _is_prepared(false), |
| 380 | _is_quantized(false) |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 381 | { |
| 382 | } |
| 383 | |
| 384 | void CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerInternal3x3::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, |
| 385 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, ActivationLayerInfo act_info, const Size2D &dilation) |
| 386 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 387 | const GPUTarget gpu_target = CLScheduler::get().target(); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 388 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 389 | // Perform validation step |
| 390 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 391 | ARM_COMPUTE_ERROR_THROW_ON(CLDepthwiseConvolutionLayer3x3::validate(input->info(), |
| 392 | weights->info(), |
| 393 | biases != nullptr ? biases->info() : nullptr, |
| 394 | output->info(), |
| 395 | conv_info, |
| 396 | depth_multiplier, |
| 397 | act_info, |
| 398 | gpu_target, |
| 399 | dilation)); |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 400 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 401 | const bool is_nhwc = input->info()->data_layout() == DataLayout::NHWC; |
| 402 | _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 403 | _needs_permute = is_nhwc && (depth_multiplier > 1); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 404 | _needs_weights_reshape = is_nhwc && (depth_multiplier == 1) && _is_quantized; |
| 405 | |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 406 | _is_prepared = false; |
| 407 | _original_weights = weights; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 408 | _input = input; |
| 409 | _output = output; |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 410 | |
| 411 | ICLTensor *input_to_use = input; |
| 412 | const ICLTensor *weights_to_use = weights; |
| 413 | ICLTensor *output_to_use = output; |
| 414 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 415 | const bool is_quantized_per_channel = is_data_type_quantized_per_channel(weights->info()->data_type()); |
| 416 | const bool is_stride_1 = ((conv_info.stride().first == conv_info.stride().second) && (conv_info.stride().first == 1)); |
| 417 | const bool is_dot8_supported = dot8_supported(CLKernelLibrary::get().get_device()) && !is_quantized_per_channel; |
| 418 | const bool is_stride_1_dilation_1 = (is_stride_1 && dilation.x() == 1 && dilation.y() == 1); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 419 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 420 | DepthwiseConvolutionReshapeInfo info; |
| 421 | info.c0 = 4; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 422 | info.transpose = is_stride_1_dilation_1 && is_dot8_supported; |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 423 | |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 424 | if(_needs_permute) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 425 | { |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 426 | _memory_group.manage(&_permuted_input); |
| 427 | _memory_group.manage(&_permuted_output); |
| 428 | |
| 429 | // Configure the function to transform the input tensor from NHWC -> NCHW |
| 430 | _permute_input_to_nchw.configure(input, &_permuted_input, PermutationVector(1U, 2U, 0U)); |
| 431 | _permuted_input.info()->set_data_layout(DataLayout::NCHW); |
| 432 | |
| 433 | // Configure the function to transform the weights tensor from HWI -> IHW |
| 434 | _permute_weights_to_nchw.configure(weights, &_permuted_weights, PermutationVector(1U, 2U, 0U)); |
| 435 | _permuted_weights.info()->set_data_layout(DataLayout::NCHW); |
Pablo Tello | a28aebc | 2019-06-03 14:59:48 +0100 | [diff] [blame] | 436 | _permuted_output.info()->set_quantization_info(output->info()->quantization_info()); |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 437 | |
| 438 | input_to_use = &_permuted_input; |
| 439 | weights_to_use = &_permuted_weights; |
| 440 | output_to_use = &_permuted_output; |
| 441 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 442 | _kernel = arm_compute::support::cpp14::make_unique<CLDepthwiseConvolutionLayer3x3NCHWKernel>(); |
| 443 | } |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 444 | else if(is_nhwc) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 445 | { |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 446 | if(_needs_weights_reshape) |
| 447 | { |
| 448 | _reshape_weights.configure(weights, &_permuted_weights, info); |
| 449 | weights_to_use = &_permuted_weights; |
| 450 | } |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 451 | _kernel = arm_compute::support::cpp14::make_unique<CLDepthwiseConvolutionLayer3x3NHWCKernel>(); |
| 452 | } |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 453 | else |
| 454 | { |
| 455 | _kernel = arm_compute::support::cpp14::make_unique<CLDepthwiseConvolutionLayer3x3NCHWKernel>(); |
| 456 | } |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 457 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 458 | CLTensor *output_multipliers_to_use = nullptr; |
| 459 | CLTensor *output_shifts_to_use = nullptr; |
| 460 | if(_is_quantized) |
| 461 | { |
| 462 | const size_t idx_c = get_data_layout_dimension_index(weights->info()->data_layout(), DataLayoutDimension::CHANNEL); |
| 463 | const size_t num_filters = (is_quantized_per_channel) ? weights->info()->dimension(idx_c) : 1; |
| 464 | |
| 465 | _output_multipliers.allocator()->init(TensorInfo(TensorShape(num_filters), 1, DataType::S32)); |
| 466 | _output_shifts.allocator()->init(TensorInfo(TensorShape(num_filters), 1, DataType::S32)); |
| 467 | |
| 468 | output_multipliers_to_use = &_output_multipliers; |
| 469 | output_shifts_to_use = &_output_shifts; |
| 470 | } |
| 471 | |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 472 | // Configure kernel |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 473 | _kernel->set_target(gpu_target); |
| 474 | _kernel->configure(input_to_use, weights_to_use, biases, output_to_use, conv_info, depth_multiplier, |
| 475 | act_info, dilation, output_multipliers_to_use, output_shifts_to_use); |
| 476 | |
| 477 | if(_is_quantized) |
| 478 | { |
| 479 | _output_multipliers.allocator()->allocate(); |
| 480 | _output_shifts.allocator()->allocate(); |
| 481 | } |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 482 | |
| 483 | // Permute output if needed |
| 484 | if(_needs_permute) |
| 485 | { |
| 486 | // Configure the function to transform the convoluted output to ACL's native ordering format NCHW |
Georgios Pinitas | 3f8aac4 | 2018-12-24 13:09:02 +0000 | [diff] [blame] | 487 | _permuted_output.info()->set_data_layout(DataLayout::NCHW); |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 488 | _permute_output_to_nhwc.configure(&_permuted_output, output, PermutationVector(2U, 0U, 1U)); |
| 489 | |
| 490 | // Allocate tensors |
| 491 | _permuted_input.allocator()->allocate(); |
| 492 | _permuted_output.allocator()->allocate(); |
| 493 | } |
Diego Lopez Recas | fa0add1 | 2017-11-28 16:44:52 +0000 | [diff] [blame] | 494 | // Configure border handler |
| 495 | PixelValue &&zero_value(0.f); |
| 496 | if(is_data_type_quantized_asymmetric(input->info()->data_type())) |
| 497 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 498 | zero_value = PixelValue(static_cast<uint8_t>(input->info()->quantization_info().uniform().offset)); |
Diego Lopez Recas | fa0add1 | 2017-11-28 16:44:52 +0000 | [diff] [blame] | 499 | } |
Georgios Pinitas | 3f8aac4 | 2018-12-24 13:09:02 +0000 | [diff] [blame] | 500 | _border_handler.configure(input_to_use, _kernel->border_size(), BorderMode::CONSTANT, zero_value); |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 501 | } |
| 502 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 503 | Status CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerInternal3x3::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, |
| 504 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, ActivationLayerInfo act_info, GPUTarget gpu_target, const Size2D &dilation) |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 505 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 506 | return validate_arguments_3x3(input, weights, biases, output, conv_info, depth_multiplier, act_info, gpu_target, dilation); |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 509 | void CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerInternal3x3::run() |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 510 | { |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 511 | prepare(); |
| 512 | |
Georgios Pinitas | da953f2 | 2019-04-02 17:27:03 +0100 | [diff] [blame] | 513 | MemoryGroupResourceScope scope_mg(_memory_group); |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 514 | |
| 515 | if(_needs_permute) |
| 516 | { |
| 517 | _permute_input_to_nchw.run(); |
| 518 | } |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 519 | CLScheduler::get().enqueue(_border_handler); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 520 | CLScheduler::get().enqueue(*_kernel); |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 521 | |
| 522 | if(_needs_permute) |
| 523 | { |
| 524 | _permute_output_to_nhwc.run(); |
| 525 | } |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 528 | void CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayerInternal3x3::prepare() |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 529 | { |
| 530 | if(!_is_prepared) |
| 531 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame^] | 532 | if(_is_quantized) |
| 533 | { |
| 534 | _output_multipliers.map(); |
| 535 | _output_shifts.map(); |
| 536 | quantization::compute_quantized_multipliers_and_shifts(_input, |
| 537 | _original_weights, |
| 538 | _output, |
| 539 | reinterpret_cast<int32_t *>(_output_multipliers.ptr_to_element(Coordinates(0))), |
| 540 | reinterpret_cast<int32_t *>(_output_shifts.ptr_to_element(Coordinates(0)))); |
| 541 | _output_multipliers.unmap(); |
| 542 | _output_shifts.unmap(); |
| 543 | } |
| 544 | |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 545 | if(_needs_permute) |
| 546 | { |
| 547 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
| 548 | |
| 549 | _permuted_weights.allocator()->allocate(); |
| 550 | _permute_weights_to_nchw.run(); |
| 551 | _original_weights->mark_as_unused(); |
| 552 | } |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 553 | |
| 554 | if(_needs_weights_reshape) |
| 555 | { |
| 556 | ARM_COMPUTE_ERROR_ON(_needs_permute); |
| 557 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
| 558 | _permuted_weights.allocator()->allocate(); |
| 559 | CLScheduler::get().enqueue(_reshape_weights); |
| 560 | _original_weights->mark_as_unused(); |
| 561 | } |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 562 | _is_prepared = true; |
| 563 | } |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 566 | CLDepthwiseConvolutionLayer::CLDepthwiseConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager) |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 567 | : _memory_manager(std::move(memory_manager)), _depth_conv_func(DepthwiseConvolutionFunction::GENERIC), _func_3x3(), _func_generic() |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 568 | { |
| 569 | } |
| 570 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 571 | void CLDepthwiseConvolutionLayer::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 572 | ActivationLayerInfo act_info, const Size2D &dilation) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 573 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 574 | const GPUTarget gpu_target = CLScheduler::get().target(); |
| 575 | _depth_conv_func = get_depthwiseconvolution_function(input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), conv_info, depth_multiplier, act_info, |
| 576 | dilation, gpu_target); |
| 577 | switch(_depth_conv_func) |
Georgios Pinitas | de5a1cc | 2018-02-02 12:52:07 +0000 | [diff] [blame] | 578 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 579 | case DepthwiseConvolutionFunction::OPTIMIZED: |
| 580 | _func_3x3.set_memory_group(_memory_manager); |
| 581 | _func_3x3.configure(input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation); |
| 582 | break; |
| 583 | case DepthwiseConvolutionFunction::GENERIC: |
Pablo Tello | 8bf622a | 2018-12-03 15:54:49 +0000 | [diff] [blame] | 584 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 585 | _func_generic.set_memory_group(_memory_manager); |
| 586 | _func_generic.configure(input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation); |
Pablo Tello | 8bf622a | 2018-12-03 15:54:49 +0000 | [diff] [blame] | 587 | } |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 588 | break; |
| 589 | default: |
| 590 | ARM_COMPUTE_ERROR("Unsupported DepthwiseConvolutionFunction"); |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 591 | } |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 594 | Status CLDepthwiseConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 595 | unsigned int depth_multiplier, ActivationLayerInfo act_info, const Size2D &dilation) |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 596 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 597 | const GPUTarget gpu_target = CLScheduler::get().target(); |
| 598 | DepthwiseConvolutionFunction depth_conv_func = get_depthwiseconvolution_function(input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation, gpu_target); |
| 599 | switch(depth_conv_func) |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 600 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 601 | case DepthwiseConvolutionFunction::OPTIMIZED: |
| 602 | return CLDepthwiseConvolutionLayerInternal3x3::validate(input, weights, biases, output, conv_info, depth_multiplier, act_info, gpu_target, dilation); |
| 603 | case DepthwiseConvolutionFunction::GENERIC: |
| 604 | return CLDepthwiseConvolutionLayerGeneric::validate(input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation); |
| 605 | default: |
| 606 | ARM_COMPUTE_ERROR("Unsupported DepthwiseConvolutionFunction"); |
| 607 | } |
| 608 | } |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 609 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 610 | DepthwiseConvolutionFunction CLDepthwiseConvolutionLayer::get_depthwiseconvolution_function(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, |
| 611 | const PadStrideInfo &conv_info, |
| 612 | unsigned int depth_multiplier, ActivationLayerInfo act_info, const Size2D &dilation, GPUTarget gpu_target) |
| 613 | { |
| 614 | if(bool(CLDepthwiseConvolutionLayerInternal3x3::validate(input, weights, biases, output, conv_info, depth_multiplier, act_info, gpu_target, dilation)) && (is_data_type_float(input->data_type()) |
| 615 | || get_arch_from_target(gpu_target) == GPUTarget::MIDGARD)) |
| 616 | { |
| 617 | return DepthwiseConvolutionFunction::OPTIMIZED; |
Pablo Tello | 8bf622a | 2018-12-03 15:54:49 +0000 | [diff] [blame] | 618 | } |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 619 | else |
| 620 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 621 | return DepthwiseConvolutionFunction::GENERIC; |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 622 | } |
Giorgio Arena | ad0c738 | 2018-04-23 16:16:21 +0100 | [diff] [blame] | 623 | } |
| 624 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 625 | void CLDepthwiseConvolutionLayer::run() |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 626 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 627 | switch(_depth_conv_func) |
Georgios Pinitas | de5a1cc | 2018-02-02 12:52:07 +0000 | [diff] [blame] | 628 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 629 | case DepthwiseConvolutionFunction::OPTIMIZED: |
| 630 | _func_3x3.run(); |
| 631 | break; |
| 632 | case DepthwiseConvolutionFunction::GENERIC: |
| 633 | _func_generic.run(); |
| 634 | break; |
| 635 | default: |
| 636 | ARM_COMPUTE_ERROR("DepthwiseConvolutionFunction not properly configured"); |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 637 | } |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 638 | } |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 639 | |
| 640 | void CLDepthwiseConvolutionLayer::prepare() |
| 641 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 642 | switch(_depth_conv_func) |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 643 | { |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 644 | case DepthwiseConvolutionFunction::OPTIMIZED: |
| 645 | _func_3x3.prepare(); |
| 646 | break; |
| 647 | case DepthwiseConvolutionFunction::GENERIC: |
| 648 | _func_generic.prepare(); |
| 649 | break; |
| 650 | default: |
| 651 | ARM_COMPUTE_ERROR("DepthwiseConvolutionFunction not properly configured"); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 652 | } |
| 653 | } |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 654 | } // namespace arm_compute |