Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | edafe7f | 2023-05-04 17:39:30 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2023 Arm Limited. |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/operators/CpuDepthwiseConv2d.h" |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/TensorInfo.h" |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/utils/misc/InfoHelpers.h" |
| 28 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Validate.h" |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 31 | |
ramelg01 | 3ae3d88 | 2021-09-12 23:07:47 +0100 | [diff] [blame] | 32 | #include "src/common/utils/Log.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 33 | #include "src/cpu/kernels/CpuDepthwiseConv2dNativeKernel.h" |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace cpu |
| 38 | { |
| 39 | namespace |
| 40 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 41 | Status validate_arguments_optimized(const ITensorInfo *src, |
| 42 | const ITensorInfo *weights, |
| 43 | const ITensorInfo *biases, |
| 44 | const ITensorInfo *dst, |
| 45 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 46 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 47 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, weights, dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, |
| 49 | DataType::F16, DataType::F32); |
| 50 | if (!is_data_type_quantized_per_channel(weights->data_type())) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 51 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, weights); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 53 | } |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 54 | ARM_COMPUTE_RETURN_ERROR_ON(src->data_layout() == DataLayout::UNKNOWN); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 55 | ARM_COMPUTE_RETURN_ERROR_ON(info.dilation.x() < 1 || info.dilation.y() < 1); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 56 | const size_t idx_w = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::WIDTH); |
| 57 | const size_t idx_h = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::HEIGHT); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 58 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_w) + (weights->dimension(idx_w) - 1) * (info.dilation.x() - 1) > |
| 59 | src->dimension(idx_w) + info.pad_stride_info.pad_left() + |
| 60 | info.pad_stride_info.pad_right()); |
| 61 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_h) + (weights->dimension(idx_h) - 1) * (info.dilation.y() - 1) > |
| 62 | src->dimension(idx_h) + info.pad_stride_info.pad_top() + |
| 63 | info.pad_stride_info.pad_bottom()); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 64 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 65 | if (biases != nullptr) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 66 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 67 | const unsigned int channel_idx = |
| 68 | get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::CHANNEL); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 69 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(channel_idx)); |
| 71 | } |
| 72 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ON_ERROR(CpuDepthwiseConv2dAssemblyDispatch::validate(src, weights, biases, dst, info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 74 | |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 75 | // Validate Activation Layer |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 76 | if (info.act_info.enabled() && !CpuDepthwiseConv2dAssemblyDispatch::is_activation_supported(info.act_info)) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 77 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 78 | ARM_COMPUTE_RETURN_ON_ERROR(CpuActivation::validate(dst, nullptr, info.act_info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 79 | } |
| 80 | return Status{}; |
| 81 | } |
| 82 | } // namespace |
| 83 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 84 | void CpuDepthwiseConv2d::CpuDepthwiseConv2dOptimizedInternal::configure(ITensorInfo *src, |
| 85 | const ITensorInfo *weights, |
| 86 | const ITensorInfo *biases, |
| 87 | ITensorInfo *dst, |
| 88 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 89 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 90 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, weights, dst); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 91 | // Perform validation step |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 92 | ARM_COMPUTE_ERROR_THROW_ON( |
| 93 | CpuDepthwiseConv2dOptimizedInternal::validate(src, weights, (biases == nullptr) ? nullptr : biases, dst, info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 94 | |
Ramy Elgammal | a8db612 | 2023-05-08 03:33:43 +0100 | [diff] [blame] | 95 | _is_quantized = is_data_type_quantized_asymmetric(src->data_type()); |
| 96 | _has_bias = biases != nullptr; |
| 97 | _is_nchw = src->data_layout() == DataLayout::NCHW; |
| 98 | _permute = _is_nchw; |
| 99 | _is_prepared = false; |
Milos Puzovic | a7077e9 | 2022-10-28 16:49:15 +0100 | [diff] [blame] | 100 | _are_weights_const = weights->are_values_constant(); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 101 | |
| 102 | // Configure pipeline |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 103 | _is_activationlayer_enabled = |
| 104 | info.act_info.enabled() && !CpuDepthwiseConv2dAssemblyDispatch::is_activation_supported(info.act_info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 105 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 106 | _dwc_optimized_func = std::make_unique<CpuDepthwiseConv2dAssemblyDispatch>(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 107 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 108 | { |
| 109 | _permute_input = std::make_unique<cpu::CpuPermute>(); |
| 110 | _permute_weights = std::make_unique<cpu::CpuPermute>(); |
| 111 | _permute_output = std::make_unique<cpu::CpuPermute>(); |
| 112 | |
| 113 | auto input_perm = std::make_unique<TensorInfo>(); |
| 114 | auto weights_perm = std::make_unique<TensorInfo>(); |
| 115 | auto output_perm = std::make_unique<TensorInfo>(); |
| 116 | |
| 117 | // Configure the function to transform the input tensor from NCHW -> NHWC |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 118 | _permute_input->configure(src, input_perm.get(), PermutationVector(2U, 0U, 1U)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 119 | input_perm->set_data_layout(DataLayout::NHWC); |
| 120 | |
| 121 | // Configure the function to transform the weights tensor from IHW -> HWI |
| 122 | _permute_weights->configure(weights, weights_perm.get(), PermutationVector(2U, 0U, 1U)); |
| 123 | weights_perm->set_data_layout(DataLayout::NHWC); |
| 124 | |
| 125 | output_perm->set_data_layout(DataLayout::NHWC); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 126 | output_perm->set_quantization_info(dst->quantization_info()); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 127 | |
| 128 | // Configure optimized depthwise |
| 129 | _dwc_optimized_func->configure(input_perm.get(), weights_perm.get(), biases, output_perm.get(), info); |
| 130 | |
| 131 | // Configure the function to transform the convoluted output to ACL's native ordering format NCHW |
| 132 | output_perm->set_data_layout(DataLayout::NHWC); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 133 | _permute_output->configure(output_perm.get(), dst, PermutationVector(1U, 2U, 0U)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 134 | } |
| 135 | else |
| 136 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 137 | _dwc_optimized_func->configure(src, weights, biases, dst, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // Configure activation |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 141 | if (_is_activationlayer_enabled) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 142 | { |
| 143 | _activationlayer_function = std::make_unique<cpu::CpuActivation>(); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 144 | _activationlayer_function->configure(dst, nullptr, info.act_info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 148 | Status CpuDepthwiseConv2d::CpuDepthwiseConv2dOptimizedInternal::validate(const ITensorInfo *src, |
| 149 | const ITensorInfo *weights, |
| 150 | const ITensorInfo *biases, |
| 151 | const ITensorInfo *dst, |
| 152 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 153 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 154 | return validate_arguments_optimized(src, weights, biases, dst, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 157 | void CpuDepthwiseConv2d::CpuDepthwiseConv2dOptimizedInternal::run(ITensorPack &tensors) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 158 | { |
| 159 | ARM_COMPUTE_ERROR_ON_MSG(tensors.empty(), "No inputs provided"); |
| 160 | prepare(tensors); |
| 161 | |
| 162 | auto bias = tensors.get_const_tensor(TensorType::ACL_SRC_2); |
| 163 | auto dst = tensors.get_tensor(TensorType::ACL_DST_0); |
| 164 | auto workspace = tensors.get_tensor(TensorType::ACL_INT_3); |
| 165 | auto packed_weights = tensors.get_tensor(TensorType::ACL_INT_4); |
| 166 | |
| 167 | // Permute input |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 168 | if (_permute) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 169 | { |
| 170 | ITensorPack pack; |
Michalis Spyrou | a7a7436 | 2021-04-23 10:32:48 +0100 | [diff] [blame] | 171 | auto src = tensors.get_const_tensor(TensorType::ACL_SRC_0); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 172 | auto src_perm = tensors.get_tensor(TensorType::ACL_INT_0); |
| 173 | pack.add_tensor(TensorType::ACL_SRC, src); |
| 174 | pack.add_tensor(TensorType::ACL_DST, src_perm); |
| 175 | _permute_input->run(pack); |
| 176 | } |
| 177 | |
| 178 | // Run assembly function |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 179 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 180 | { |
| 181 | auto src_perm = tensors.get_tensor(TensorType::ACL_INT_0); |
| 182 | auto weights_perm = tensors.get_tensor(TensorType::ACL_INT_1); |
| 183 | auto dst_perm = tensors.get_tensor(TensorType::ACL_INT_2); |
| 184 | |
| 185 | ITensorPack pack; |
| 186 | pack.add_tensor(TensorType::ACL_SRC_0, src_perm); |
| 187 | pack.add_tensor(TensorType::ACL_SRC_1, weights_perm); |
| 188 | pack.add_tensor(TensorType::ACL_SRC_2, bias); |
| 189 | pack.add_tensor(TensorType::ACL_INT_0, workspace); |
| 190 | pack.add_tensor(TensorType::ACL_INT_1, packed_weights); |
| 191 | pack.add_tensor(TensorType::ACL_DST, dst_perm); |
| 192 | _dwc_optimized_func->run(pack); |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | auto src = tensors.get_tensor(TensorType::ACL_SRC_0); |
| 197 | auto weights = tensors.get_tensor(TensorType::ACL_SRC_1); |
| 198 | auto dst = tensors.get_tensor(TensorType::ACL_DST); |
| 199 | |
| 200 | ITensorPack pack; |
| 201 | pack.add_tensor(TensorType::ACL_SRC_0, src); |
| 202 | pack.add_tensor(TensorType::ACL_SRC_1, weights); |
| 203 | pack.add_tensor(TensorType::ACL_SRC_2, bias); |
| 204 | pack.add_tensor(TensorType::ACL_INT_0, workspace); |
| 205 | pack.add_tensor(TensorType::ACL_INT_1, packed_weights); |
| 206 | pack.add_tensor(TensorType::ACL_DST, dst); |
| 207 | _dwc_optimized_func->run(pack); |
| 208 | } |
| 209 | |
| 210 | // Permute output |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 211 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 212 | { |
| 213 | ITensorPack pack; |
| 214 | auto dst_perm = tensors.get_tensor(TensorType::ACL_INT_2); |
| 215 | pack.add_tensor(TensorType::ACL_SRC, dst_perm); |
| 216 | pack.add_tensor(TensorType::ACL_DST, dst); |
| 217 | _permute_output->run(pack); |
| 218 | } |
| 219 | |
| 220 | // Run activation |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 221 | if (_is_activationlayer_enabled) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 222 | { |
| 223 | ITensorPack pack; |
| 224 | pack.add_tensor(TensorType::ACL_SRC, dst); |
| 225 | pack.add_tensor(TensorType::ACL_DST, dst); |
| 226 | _activationlayer_function->run(pack); |
| 227 | } |
| 228 | } |
| 229 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 230 | void CpuDepthwiseConv2d::CpuDepthwiseConv2dOptimizedInternal::prepare(ITensorPack &tensors) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 231 | { |
Milos Puzovic | a7077e9 | 2022-10-28 16:49:15 +0100 | [diff] [blame] | 232 | // if weights are not constant then we need to repack so that weights |
| 233 | // can be updated in-place |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 234 | if (!_are_weights_const) |
Milos Puzovic | a7077e9 | 2022-10-28 16:49:15 +0100 | [diff] [blame] | 235 | { |
| 236 | auto weights = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 237 | auto bias = tensors.get_const_tensor(TensorType::ACL_SRC_2); |
| 238 | auto packed_weights = tensors.get_tensor(TensorType::ACL_INT_4); |
| 239 | |
| 240 | ITensorPack pack_opt; |
| 241 | pack_opt.add_tensor(TensorType::ACL_SRC_1, weights); |
| 242 | pack_opt.add_tensor(TensorType::ACL_SRC_2, bias); |
| 243 | pack_opt.add_tensor(TensorType::ACL_INT_1, packed_weights); |
| 244 | |
| 245 | // Prepare optimized function |
| 246 | _dwc_optimized_func->prepare(pack_opt); |
| 247 | |
| 248 | return; |
| 249 | } |
| 250 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 251 | if (!_is_prepared) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 252 | { |
| 253 | auto weights = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 254 | auto bias = tensors.get_const_tensor(TensorType::ACL_SRC_2); |
| 255 | auto packed_weights = tensors.get_tensor(TensorType::ACL_INT_4); |
| 256 | |
| 257 | // Permute weights |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 258 | if (_permute) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 259 | { |
| 260 | auto permuted_weights = tensors.get_tensor(TensorType::ACL_INT_1); |
| 261 | |
| 262 | ITensorPack pack; |
| 263 | pack.add_tensor(TensorType::ACL_SRC, weights); |
| 264 | pack.add_tensor(TensorType::ACL_DST, permuted_weights); |
| 265 | _permute_weights->run(pack); |
| 266 | |
Michalis Spyrou | a7a7436 | 2021-04-23 10:32:48 +0100 | [diff] [blame] | 267 | weights->mark_as_unused(); |
| 268 | |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 269 | ITensorPack pack_opt; |
| 270 | pack_opt.add_const_tensor(TensorType::ACL_SRC_1, permuted_weights); |
| 271 | pack_opt.add_tensor(TensorType::ACL_SRC_2, bias); |
| 272 | pack_opt.add_tensor(TensorType::ACL_INT_1, packed_weights); |
| 273 | |
| 274 | // Prepare optimized function |
| 275 | _dwc_optimized_func->prepare(pack_opt); |
| 276 | } |
| 277 | else |
| 278 | { |
| 279 | ITensorPack pack_opt; |
| 280 | pack_opt.add_tensor(TensorType::ACL_SRC_1, weights); |
| 281 | pack_opt.add_tensor(TensorType::ACL_SRC_2, bias); |
| 282 | pack_opt.add_tensor(TensorType::ACL_INT_1, packed_weights); |
| 283 | |
| 284 | // Prepare optimized function |
| 285 | _dwc_optimized_func->prepare(pack_opt); |
| 286 | } |
| 287 | |
| 288 | _is_prepared = true; |
| 289 | } |
| 290 | } |
| 291 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 292 | void CpuDepthwiseConv2d::CpuDepthwiseConv2dGeneric::configure(ITensorInfo *src, |
| 293 | const ITensorInfo *weights, |
| 294 | const ITensorInfo *biases, |
| 295 | ITensorInfo *dst, |
| 296 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 297 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 298 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, weights, dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 299 | ARM_COMPUTE_ERROR_THROW_ON( |
| 300 | CpuDepthwiseConv2d::validate(src, weights, (biases == nullptr) ? nullptr : biases, dst, info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 301 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 302 | _is_nchw = src->data_layout() == DataLayout::NCHW; |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 303 | _is_prepared = !_is_nchw; |
| 304 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 305 | ITensorInfo *input_to_use = src; |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 306 | const ITensorInfo *weights_to_use = weights; |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 307 | ITensorInfo *output_to_use = dst; |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 308 | |
| 309 | auto input_perm = std::make_unique<TensorInfo>(); |
| 310 | auto weights_perm = std::make_unique<TensorInfo>(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 311 | auto output_perm = std::make_unique<TensorInfo>( |
| 312 | dst->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(TensorShape())); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 313 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 314 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 315 | { |
| 316 | _permute_input = std::make_unique<cpu::CpuPermute>(); |
| 317 | _permute_weights = std::make_unique<cpu::CpuPermute>(); |
| 318 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 319 | _permute_input->configure(src, input_perm.get(), PermutationVector(2U, 0U, 1U)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 320 | input_perm->set_data_layout(DataLayout::NHWC); |
| 321 | input_to_use = input_perm.get(); |
| 322 | |
| 323 | _permute_weights->configure(weights, weights_perm.get(), PermutationVector(2U, 0U, 1U)); |
| 324 | weights_perm->set_data_layout(DataLayout::NHWC); |
| 325 | weights_to_use = weights_perm.get(); |
| 326 | |
| 327 | output_to_use = output_perm.get(); |
| 328 | } |
| 329 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 330 | _depthwise_conv_kernel = std::make_unique<cpu::kernels::CpuDepthwiseConv2dNativeKernel>(); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 331 | _depthwise_conv_kernel->configure(input_to_use, weights_to_use, biases, output_to_use, info); |
| 332 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 333 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 334 | { |
| 335 | _permute_output = std::make_unique<cpu::CpuPermute>(); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 336 | _permute_output->configure(output_perm.get(), dst, PermutationVector(1U, 2U, 0U)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 337 | output_perm->set_data_layout(DataLayout::NHWC); |
| 338 | } |
| 339 | |
| 340 | //Configure Activation Layer |
| 341 | _is_activationlayer_enabled = info.act_info.enabled(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 342 | if (_is_activationlayer_enabled) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 343 | { |
| 344 | _activationlayer_function = std::make_unique<cpu::CpuActivation>(); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 345 | _activationlayer_function->configure(dst, nullptr, info.act_info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 349 | Status CpuDepthwiseConv2d::CpuDepthwiseConv2dGeneric::validate(const ITensorInfo *src, |
| 350 | const ITensorInfo *weights, |
| 351 | const ITensorInfo *biases, |
| 352 | const ITensorInfo *dst, |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 353 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 354 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 355 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, weights, dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 356 | if (src->data_layout() == DataLayout::NCHW) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 357 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 358 | TensorShape permuted_input_shape = src->tensor_shape(); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 359 | TensorShape permuted_weights_shape = weights->tensor_shape(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 360 | TensorShape permuted_output_shape = |
| 361 | misc::shape_calculator::compute_depthwise_convolution_shape(*src, *weights, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 362 | permute(permuted_input_shape, PermutationVector(2U, 0U, 1U)); |
| 363 | permute(permuted_weights_shape, PermutationVector(2U, 0U, 1U)); |
| 364 | permute(permuted_output_shape, PermutationVector(2U, 0U, 1U)); |
| 365 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 366 | const TensorInfo permuted_input = TensorInfo(src->clone() |
| 367 | ->set_is_resizable(true) |
| 368 | .reset_padding() |
| 369 | .set_tensor_shape(permuted_input_shape) |
| 370 | .set_data_layout(DataLayout::NHWC)); |
| 371 | const TensorInfo permuted_weights = TensorInfo(weights->clone() |
| 372 | ->set_is_resizable(true) |
| 373 | .reset_padding() |
| 374 | .set_tensor_shape(permuted_weights_shape) |
| 375 | .set_data_layout(DataLayout::NHWC)); |
| 376 | const TensorInfo permuted_output = TensorInfo(dst->clone() |
| 377 | ->set_is_resizable(true) |
| 378 | .reset_padding() |
| 379 | .set_tensor_shape(permuted_output_shape) |
| 380 | .set_data_layout(DataLayout::NCHW)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 381 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 382 | ARM_COMPUTE_RETURN_ON_ERROR(CpuPermute::validate(src, &permuted_input, PermutationVector(2U, 0U, 1U))); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 383 | ARM_COMPUTE_RETURN_ON_ERROR(CpuPermute::validate(weights, &permuted_weights, PermutationVector(2U, 0U, 1U))); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 384 | ARM_COMPUTE_RETURN_ON_ERROR(CpuPermute::validate(&permuted_output, dst, PermutationVector(1U, 2U, 0U))); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 385 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 386 | ARM_COMPUTE_RETURN_ON_ERROR(cpu::kernels::CpuDepthwiseConv2dNativeKernel::validate( |
| 387 | &permuted_input, &permuted_weights, biases, &permuted_output, info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 388 | } |
| 389 | else |
| 390 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 391 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 392 | cpu::kernels::CpuDepthwiseConv2dNativeKernel::validate(src, weights, biases, dst, info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // Validate Activation Layer |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 396 | if (info.act_info.enabled() && !CpuDepthwiseConv2dAssemblyDispatch::is_activation_supported(info.act_info)) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 397 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 398 | ARM_COMPUTE_RETURN_ON_ERROR(CpuActivation::validate(dst, nullptr, info.act_info)); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | return Status{}; |
| 402 | } |
| 403 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 404 | void CpuDepthwiseConv2d::CpuDepthwiseConv2dGeneric::run(ITensorPack &tensors) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 405 | { |
| 406 | auto src = tensors.get_const_tensor(TensorType::ACL_SRC_0); |
| 407 | auto weights = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 408 | auto biases = tensors.get_const_tensor(TensorType::ACL_SRC_2); |
| 409 | auto dst = tensors.get_tensor(TensorType::ACL_DST_0); |
| 410 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 411 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 412 | { |
| 413 | prepare(tensors); |
| 414 | auto src_perm = tensors.get_tensor(TensorType::ACL_INT_0); |
| 415 | auto weights_perm = tensors.get_tensor(TensorType::ACL_INT_1); |
| 416 | auto dst_perm = tensors.get_tensor(TensorType::ACL_INT_2); |
| 417 | |
| 418 | ITensorPack pack; |
| 419 | pack.add_tensor(TensorType::ACL_SRC, src); |
| 420 | pack.add_tensor(TensorType::ACL_DST, src_perm); |
| 421 | _permute_input->run(pack); |
| 422 | |
| 423 | ITensorPack pack_depth; |
| 424 | pack_depth.add_const_tensor(TensorType::ACL_SRC_0, src_perm); |
| 425 | pack_depth.add_const_tensor(TensorType::ACL_SRC_1, weights_perm); |
| 426 | pack_depth.add_tensor(TensorType::ACL_SRC_2, biases); |
| 427 | pack_depth.add_tensor(TensorType::ACL_DST, dst_perm); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 428 | NEScheduler::get().schedule_op(_depthwise_conv_kernel.get(), Window::DimY, _depthwise_conv_kernel->window(), |
| 429 | pack_depth); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 430 | } |
| 431 | else |
| 432 | { |
| 433 | ITensorPack pack_depth; |
| 434 | pack_depth.add_tensor(TensorType::ACL_SRC_0, src); |
| 435 | pack_depth.add_tensor(TensorType::ACL_SRC_1, weights); |
| 436 | pack_depth.add_tensor(TensorType::ACL_SRC_2, biases); |
| 437 | pack_depth.add_tensor(TensorType::ACL_DST, dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 438 | NEScheduler::get().schedule_op(_depthwise_conv_kernel.get(), Window::DimY, _depthwise_conv_kernel->window(), |
| 439 | pack_depth); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 442 | if (_is_nchw) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 443 | { |
| 444 | ITensorPack pack; |
| 445 | auto dst_perm = tensors.get_tensor(TensorType::ACL_INT_2); |
| 446 | pack.add_tensor(TensorType::ACL_SRC, dst_perm); |
| 447 | pack.add_tensor(TensorType::ACL_DST, dst); |
| 448 | _permute_output->run(pack); |
| 449 | } |
| 450 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 451 | if (_is_activationlayer_enabled) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 452 | { |
| 453 | ITensorPack pack; |
| 454 | pack.add_tensor(TensorType::ACL_SRC, dst); |
| 455 | pack.add_tensor(TensorType::ACL_DST, dst); |
| 456 | _activationlayer_function->run(pack); |
| 457 | } |
| 458 | } |
| 459 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 460 | void CpuDepthwiseConv2d::CpuDepthwiseConv2dGeneric::prepare(ITensorPack &tensors) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 461 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 462 | if (!_is_prepared) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 463 | { |
| 464 | auto weights = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 465 | auto weights_perm = tensors.get_tensor(TensorType::ACL_INT_1); |
| 466 | |
| 467 | ARM_COMPUTE_ERROR_ON(!weights->is_used()); |
| 468 | |
| 469 | ITensorPack pack; |
| 470 | pack.add_tensor(TensorType::ACL_SRC, weights); |
| 471 | pack.add_tensor(TensorType::ACL_DST, weights_perm); |
| 472 | |
| 473 | _permute_weights->run(pack); |
| 474 | weights->mark_as_unused(); |
| 475 | _is_prepared = true; |
| 476 | } |
| 477 | } |
| 478 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 479 | void CpuDepthwiseConv2d::configure(ITensorInfo *src, |
| 480 | const ITensorInfo *weights, |
| 481 | const ITensorInfo *biases, |
| 482 | ITensorInfo *dst, |
| 483 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 484 | { |
ramelg01 | 3ae3d88 | 2021-09-12 23:07:47 +0100 | [diff] [blame] | 485 | ARM_COMPUTE_LOG_PARAMS(src, weights, biases, dst, info); |
| 486 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 487 | _depth_conv_func = |
| 488 | get_depthwiseconvolution_function(src, weights, (biases != nullptr) ? biases : nullptr, dst, info); |
| 489 | switch (_depth_conv_func) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 490 | { |
| 491 | case DepthwiseConvolutionFunction::OPTIMIZED: |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 492 | _func_optimized.configure(src, weights, biases, dst, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 493 | break; |
| 494 | case DepthwiseConvolutionFunction::GENERIC: |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 495 | _func_generic.configure(src, weights, biases, dst, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 496 | break; |
| 497 | default: |
| 498 | ARM_COMPUTE_ERROR("Unsupported DepthwiseConvolutionFunction"); |
| 499 | } |
| 500 | } |
| 501 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 502 | Status CpuDepthwiseConv2d::validate(const ITensorInfo *src, |
| 503 | const ITensorInfo *weights, |
| 504 | const ITensorInfo *biases, |
| 505 | const ITensorInfo *dst, |
| 506 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 507 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 508 | DepthwiseConvolutionFunction depth_conv_func = get_depthwiseconvolution_function(src, weights, biases, dst, info); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 509 | switch (depth_conv_func) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 510 | { |
| 511 | case DepthwiseConvolutionFunction::OPTIMIZED: |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 512 | return CpuDepthwiseConv2dOptimizedInternal::validate(src, weights, biases, dst, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 513 | break; |
| 514 | case DepthwiseConvolutionFunction::GENERIC: |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 515 | return CpuDepthwiseConv2dGeneric::validate(src, weights, biases, dst, info); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 516 | break; |
| 517 | default: |
| 518 | ARM_COMPUTE_ERROR("Unsupported DepthwiseConvolutionFunction"); |
| 519 | } |
| 520 | } |
| 521 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 522 | DepthwiseConvolutionFunction CpuDepthwiseConv2d::get_depthwiseconvolution_function(const ITensorInfo *src, |
| 523 | const ITensorInfo *weights, |
| 524 | const ITensorInfo *biases, |
| 525 | const ITensorInfo *dst, |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 526 | const ConvolutionInfo &info) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 527 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 528 | if (bool(CpuDepthwiseConv2dOptimizedInternal::validate(src, weights, biases, dst, info))) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 529 | { |
| 530 | return DepthwiseConvolutionFunction::OPTIMIZED; |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | return DepthwiseConvolutionFunction::GENERIC; |
| 535 | } |
| 536 | } |
| 537 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 538 | void CpuDepthwiseConv2d::run(ITensorPack &tensors) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 539 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 540 | switch (_depth_conv_func) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 541 | { |
| 542 | case DepthwiseConvolutionFunction::OPTIMIZED: |
| 543 | _func_optimized.run(tensors); |
| 544 | break; |
| 545 | case DepthwiseConvolutionFunction::GENERIC: |
| 546 | _func_generic.run(tensors); |
| 547 | break; |
| 548 | default: |
| 549 | ARM_COMPUTE_ERROR("DepthwiseConvolutionFunction not properly configured"); |
| 550 | } |
| 551 | } |
| 552 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 553 | void CpuDepthwiseConv2d::prepare(ITensorPack &tensors) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 554 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 555 | switch (_depth_conv_func) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 556 | { |
| 557 | case DepthwiseConvolutionFunction::OPTIMIZED: |
| 558 | _func_optimized.prepare(tensors); |
| 559 | break; |
| 560 | case DepthwiseConvolutionFunction::GENERIC: |
| 561 | _func_generic.prepare(tensors); |
| 562 | break; |
| 563 | default: |
| 564 | ARM_COMPUTE_ERROR("DepthwiseConvolutionFunction not properly configured"); |
| 565 | } |
| 566 | } |
| 567 | } // namespace cpu |
| 568 | } // namespace arm_compute |