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