Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 | */ |
| 24 | #include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" |
| 25 | |
| 26 | #include "arm_compute/core/PixelValue.h" |
| 27 | #include "arm_compute/core/Utils.h" |
| 28 | #include "arm_compute/core/Validate.h" |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/NEON/functions/NEDirectConvolutionLayer.h" |
| 31 | #include "arm_compute/runtime/NEON/functions/NEFFTConvolutionLayer.h" |
| 32 | #include "arm_compute/runtime/NEON/functions/NEGEMMConv2d.h" |
| 33 | #include "arm_compute/runtime/NEON/functions/NEGEMMConvolutionLayer.h" |
| 34 | #include "arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h" |
| 35 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | #include <cmath> |
| 37 | #include <tuple> |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 38 | #include <utility> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
Anthony Barbier | 61b4fca | 2018-03-29 11:31:55 +0100 | [diff] [blame] | 42 | NEConvolutionLayer::NEConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager) //NOLINT |
| 43 | : _memory_manager(std::move(memory_manager)), |
| 44 | _function() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 48 | void NEConvolutionLayer::configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info, |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 49 | const Size2D &dilation, const ActivationLayerInfo &act_info, bool enable_fast_math, unsigned int num_groups) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | { |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 51 | // Perform validate step |
| 52 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 53 | ARM_COMPUTE_UNUSED(num_groups); |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 54 | ARM_COMPUTE_ERROR_THROW_ON(NEConvolutionLayer::validate(input->info(), weights->info(), ((biases != nullptr) ? biases->info() : nullptr), output->info(), conv_info, weights_info, dilation, act_info, |
Alexander Jung | 187558f | 2020-08-05 16:26:41 +0200 | [diff] [blame] | 55 | enable_fast_math, num_groups)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 57 | const Conv2dInfo info(conv_info, dilation, act_info, enable_fast_math, num_groups); |
Georgios Pinitas | 0905028 | 2020-05-14 10:03:56 +0100 | [diff] [blame] | 58 | switch(NEConvolutionLayer::get_convolution_method(input->info(), weights->info(), output->info(), conv_info, weights_info, dilation, act_info, enable_fast_math)) |
Moritz Pflanzer | 80373f6 | 2017-09-15 10:42:58 +0100 | [diff] [blame] | 59 | { |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 60 | case ConvolutionMethod::WINOGRAD: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | { |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame^] | 62 | auto f = std::make_unique<NEWinogradConvolutionLayer>(_memory_manager); |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 63 | f->configure(input, weights, biases, output, conv_info, act_info, enable_fast_math); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 64 | _function = std::move(f); |
| 65 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 67 | case ConvolutionMethod::GEMM: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | { |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame^] | 69 | auto f = std::make_unique<NEGEMMConvolutionLayer>(_memory_manager); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 70 | f->configure(input, weights, biases, output, conv_info, weights_info, dilation, act_info); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 71 | _function = std::move(f); |
| 72 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | } |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 74 | case ConvolutionMethod::GEMM_CONV2D: |
| 75 | { |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame^] | 76 | auto f = std::make_unique<NEGEMMConv2d>(_memory_manager); |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 77 | f->configure(input, weights, biases, output, info); |
| 78 | _function = std::move(f); |
| 79 | break; |
| 80 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 81 | case ConvolutionMethod::DIRECT: |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 82 | { |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame^] | 83 | auto f = std::make_unique<NEDirectConvolutionLayer>(_memory_manager); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 84 | f->configure(input, weights, biases, output, conv_info, act_info); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 85 | _function = std::move(f); |
| 86 | break; |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 87 | } |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 88 | case ConvolutionMethod::FFT: |
| 89 | { |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame^] | 90 | auto f = std::make_unique<NEFFTConvolutionLayer>(_memory_manager); |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 91 | f->configure(input, weights, biases, output, conv_info, act_info); |
| 92 | _function = std::move(f); |
| 93 | break; |
| 94 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 95 | default: |
| 96 | ARM_COMPUTE_ERROR("Not supported."); |
| 97 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 101 | Status NEConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 102 | const WeightsInfo &weights_info, const Size2D &dilation, const ActivationLayerInfo &act_info, bool enable_fast_math, unsigned int num_groups) |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 103 | { |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 104 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((num_groups != 1), "Grouping (num_groups != 1) is not supported on NEON"); |
| 105 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 106 | const Conv2dInfo info(conv_info, dilation, act_info, enable_fast_math, num_groups); |
Georgios Pinitas | 0905028 | 2020-05-14 10:03:56 +0100 | [diff] [blame] | 107 | switch(NEConvolutionLayer::get_convolution_method(input, weights, output, conv_info, weights_info, dilation, act_info, enable_fast_math)) |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 108 | { |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 109 | case ConvolutionMethod::WINOGRAD: |
Isabella Gottardi | 96b86a9 | 2018-05-14 15:52:07 +0100 | [diff] [blame] | 110 | ARM_COMPUTE_RETURN_ON_ERROR(NEWinogradConvolutionLayer::validate(input, weights, biases, output, conv_info, act_info, enable_fast_math)); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 111 | break; |
| 112 | case ConvolutionMethod::GEMM: |
Isabella Gottardi | 96b86a9 | 2018-05-14 15:52:07 +0100 | [diff] [blame] | 113 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMConvolutionLayer::validate(input, weights, biases, output, conv_info, weights_info, dilation, act_info)); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 114 | break; |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 115 | case ConvolutionMethod::GEMM_CONV2D: |
| 116 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMConv2d::validate(input, weights, biases, output, info)); |
| 117 | break; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 118 | case ConvolutionMethod::DIRECT: |
Isabella Gottardi | 96b86a9 | 2018-05-14 15:52:07 +0100 | [diff] [blame] | 119 | ARM_COMPUTE_RETURN_ON_ERROR(NEDirectConvolutionLayer::validate(input, weights, biases, output, conv_info, act_info)); |
Georgios Pinitas | 49f8349 | 2019-06-27 17:08:07 +0100 | [diff] [blame] | 120 | break; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 121 | case ConvolutionMethod::FFT: |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 122 | ARM_COMPUTE_RETURN_ON_ERROR(NEFFTConvolutionLayer::validate(input, weights, nullptr, output, conv_info, act_info)); |
| 123 | break; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 124 | default: |
| 125 | ARM_COMPUTE_ERROR("Not supported."); |
| 126 | break; |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 127 | } |
Giorgio Arena | 7c23ad0 | 2017-11-30 15:08:38 +0000 | [diff] [blame] | 128 | |
| 129 | return Status{}; |
| 130 | } |
| 131 | |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 132 | ConvolutionMethod NEConvolutionLayer::get_convolution_method(const ITensorInfo *input, const ITensorInfo *weights, |
| 133 | const ITensorInfo *output, const PadStrideInfo &conv_info, |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 134 | const WeightsInfo &weights_info, const Size2D &dilation, const ActivationLayerInfo &act_info, bool enable_fast_math) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 135 | { |
Gian Marco Iodice | a8aef29 | 2018-05-14 14:21:39 +0100 | [diff] [blame] | 136 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, weights); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 137 | ARM_COMPUTE_UNUSED(weights_info); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 138 | |
Giorgio Arena | e083771 | 2018-06-12 11:30:50 +0100 | [diff] [blame] | 139 | const size_t idx_w = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH); |
| 140 | const size_t idx_h = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT); |
| 141 | const size_t idx_c = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL); |
| 142 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 143 | const Conv2dInfo info(conv_info, dilation, act_info, enable_fast_math, 1); |
| 144 | |
Giorgio Arena | e083771 | 2018-06-12 11:30:50 +0100 | [diff] [blame] | 145 | /* Input spatial dims, kernel size, IFM/OFM, conv info*/ |
| 146 | using ConvolutionConfiguration = std::tuple<Size2D, Size2D, Size2D, PadStrideInfo>; |
| 147 | using ConfigurationMethod = std::pair<ConvolutionConfiguration, ConvolutionMethod>; |
| 148 | |
| 149 | const std::vector<ConfigurationMethod> known_configs = |
| 150 | { |
| 151 | // Alexnet |
| 152 | ConfigurationMethod(ConvolutionConfiguration(Size2D(27U, 27U), Size2D(5U, 5U), Size2D(48U, 128U), PadStrideInfo(1U, 1U, 2U, 2U)), ConvolutionMethod::GEMM), |
| 153 | // VGG16 / VGG19 |
| 154 | ConfigurationMethod(ConvolutionConfiguration(Size2D(224U, 224U), Size2D(3U, 3U), Size2D(3U, 64U), PadStrideInfo(1U, 1U, 1U, 1U)), ConvolutionMethod::GEMM), |
| 155 | // Mobilenet 224 |
| 156 | ConfigurationMethod(ConvolutionConfiguration(Size2D(224U, 224U), Size2D(3U, 3U), Size2D(3U, 32U), PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR)), ConvolutionMethod::GEMM), |
| 157 | // Mobilenet 160 |
| 158 | ConfigurationMethod(ConvolutionConfiguration(Size2D(160U, 160U), Size2D(3U, 3U), Size2D(3U, 24U), PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::FLOOR)), ConvolutionMethod::GEMM) |
| 159 | }; |
| 160 | |
| 161 | const auto find_config = [&](ConfigurationMethod c) |
| 162 | { |
| 163 | const ConvolutionConfiguration config = c.first; |
| 164 | const PadStrideInfo info = std::get<3>(config); |
| 165 | |
| 166 | return std::get<0>(config) == Size2D(input->dimension(idx_w), input->dimension(idx_h)) && std::get<1>(config) == Size2D(weights->dimension(idx_w), weights->dimension(idx_h)) |
| 167 | && std::get<2>(config) == Size2D(weights->dimension(idx_c), weights->dimension(3)) && info.pad_top() == conv_info.pad_top() && info.pad_right() == conv_info.pad_right() |
| 168 | && info.pad_bottom() == conv_info.pad_bottom() && info.pad_left() == conv_info.pad_left() && info.stride() == conv_info.stride(); |
| 169 | }; |
| 170 | |
| 171 | std::vector<ConfigurationMethod>::const_iterator found; |
| 172 | if((found = std::find_if(known_configs.begin(), known_configs.end(), find_config)) != known_configs.end()) |
| 173 | { |
| 174 | return (*found).second; |
| 175 | } |
| 176 | |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 177 | if(dilation != Size2D(1U, 1U)) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 178 | { |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 179 | return ConvolutionMethod::GEMM; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 180 | } |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 181 | else |
| 182 | { |
Michalis Spyrou | 26dcbc7 | 2019-06-04 17:23:04 +0100 | [diff] [blame] | 183 | // SRGAN |
Manuel Bottini | 6e10aa3 | 2020-04-30 13:28:23 +0100 | [diff] [blame] | 184 | // Output might not be initialized when it is an internal tensor of the layer using the convolution |
| 185 | if(input->total_size() > 1e7 && (weights->dimension(idx_h) > 7) |
Michalis Spyrou | 26dcbc7 | 2019-06-04 17:23:04 +0100 | [diff] [blame] | 186 | && (NEDirectConvolutionLayer::validate(input, weights, nullptr, output, conv_info, act_info))) |
| 187 | { |
| 188 | return ConvolutionMethod::DIRECT; |
| 189 | } |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 190 | if((weights->dimension(idx_h) > 7) && (input->dimension(idx_c) > output->dimension(idx_c)) && (NEFFTConvolutionLayer::validate(input, weights, nullptr, output, conv_info, act_info))) |
| 191 | { |
| 192 | return ConvolutionMethod::FFT; |
| 193 | } |
| 194 | if(input->dimension(idx_c) < 16) |
| 195 | { |
| 196 | return ConvolutionMethod::GEMM; |
| 197 | } |
SiCong Li | 6b6a16f | 2020-05-28 08:55:51 +0100 | [diff] [blame] | 198 | |
| 199 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 200 | // This heuristics only applies to F16 data type on A55r1 |
| 201 | if(NEScheduler::get().cpu_info().get_cpu_model() == CPUModel::A55r1 && enable_fast_math && input->data_type() == DataType::F16) |
| 202 | { |
| 203 | // Exclude known bad winograd configs (and defaults to GEMM) |
| 204 | const std::vector<ConvolutionConfiguration> known_bad_winograd_f16_with_fastmath_configs = |
| 205 | { |
| 206 | // Squeezenet_V1_1 fire2 and fire3 |
| 207 | ConvolutionConfiguration(Size2D(56U, 56U), Size2D(3U, 3U), Size2D(16U, 64U), PadStrideInfo(1U, 1U, 1U, 1U)), |
| 208 | // Squeezenet_V1_1 fire6 and fire7 |
| 209 | ConvolutionConfiguration(Size2D(14U, 14U), Size2D(3U, 3U), Size2D(48U, 192U), PadStrideInfo(1U, 1U, 1U, 1U)), |
| 210 | // Squeezenet_V1_1 fire8 and fire9 |
| 211 | ConvolutionConfiguration(Size2D(14U, 14U), Size2D(3U, 3U), Size2D(64U, 256U), PadStrideInfo(1U, 1U, 1U, 1U)), |
| 212 | }; |
| 213 | const auto find_conv_config = [&](ConvolutionConfiguration c) |
| 214 | { |
| 215 | const PadStrideInfo info = std::get<3>(c); |
| 216 | |
| 217 | return std::get<0>(c) == Size2D(input->dimension(idx_w), input->dimension(idx_h)) && std::get<1>(c) == Size2D(weights->dimension(idx_w), weights->dimension(idx_h)) |
| 218 | && std::get<2>(c) == Size2D(weights->dimension(idx_c), weights->dimension(3)) && info.pad_top() == conv_info.pad_top() && info.pad_right() == conv_info.pad_right() |
| 219 | && info.pad_bottom() == conv_info.pad_bottom() && info.pad_left() == conv_info.pad_left() && info.stride() == conv_info.stride(); |
| 220 | }; |
| 221 | |
| 222 | bool found_bad = std::find_if(known_bad_winograd_f16_with_fastmath_configs.begin(), known_bad_winograd_f16_with_fastmath_configs.end(), |
| 223 | find_conv_config) |
| 224 | != known_bad_winograd_f16_with_fastmath_configs.end(); |
| 225 | if(found_bad) |
| 226 | { |
| 227 | return ConvolutionMethod::GEMM; |
| 228 | } |
| 229 | } |
| 230 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 231 | // For 1x1 convolutions run the default GEMM |
| 232 | if(weights->dimension(idx_w) == 1 && weights->dimension(idx_h) == 1) |
| 233 | { |
| 234 | return ConvolutionMethod::GEMM; |
| 235 | } |
| 236 | |
| 237 | if(bool(NEWinogradConvolutionLayer::validate(input, weights, nullptr, output, conv_info, act_info, enable_fast_math))) |
| 238 | { |
| 239 | return ConvolutionMethod::WINOGRAD; |
| 240 | } |
| 241 | if(bool(NEGEMMConv2d::validate(input, weights, nullptr, output, info))) |
| 242 | { |
| 243 | return ConvolutionMethod::GEMM_CONV2D; |
| 244 | } |
| 245 | return ConvolutionMethod::GEMM; |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 246 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 249 | void NEConvolutionLayer::run() |
| 250 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 251 | prepare(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 252 | _function->run(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 253 | } |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 254 | |
| 255 | void NEConvolutionLayer::prepare() |
| 256 | { |
| 257 | _function->prepare(); |
| 258 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 259 | } // namespace arm_compute |