Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Mohammed Suhail Munshi | 8050d22 | 2024-02-04 17:55:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2024 Arm Limited. |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +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/core/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEGEMMConv2d.h" |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/NEON/functions/NEGEMMConvolutionLayer.h" |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/Tensor.h" |
| 30 | #include "arm_compute/runtime/TensorAllocator.h" |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 31 | |
| 32 | #include "src/core/CPP/Validate.h" |
Michele Di Giorgio | d7316eb | 2021-06-16 11:14:41 +0100 | [diff] [blame] | 33 | #include "src/core/helpers/MemoryHelpers.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 34 | #include "src/cpu/operators/CpuGemmConv2d.h" |
| 35 | #include "src/cpu/operators/CpuGemmDirectConv2d.h" |
| 36 | #include "src/cpu/operators/CpuWinogradConv2d.h" |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 37 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 38 | #include "tests/NEON/Accessor.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 39 | #include "tests/datasets/LargeConvolutionLayerDataset.h" |
| 40 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
| 41 | #include "tests/framework/Asserts.h" |
| 42 | #include "tests/framework/Macros.h" |
| 43 | #include "tests/framework/datasets/Datasets.h" |
| 44 | #include "tests/validation/Validation.h" |
| 45 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 46 | #include "tests/validation/fixtures/WinogradConvolutionLayerFixture.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 47 | |
| 48 | namespace arm_compute |
| 49 | { |
| 50 | namespace test |
| 51 | { |
| 52 | namespace validation |
| 53 | { |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 54 | using framework::dataset::make; |
| 55 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 56 | namespace detail |
| 57 | { |
| 58 | template <> |
| 59 | void configure_conv_function<NEGEMMConv2d, Tensor>(NEGEMMConv2d &func, |
| 60 | Tensor *src, const Tensor *weights, const Tensor *bias, Tensor *dst, |
| 61 | const PadStrideInfo &info, const WeightsInfo &weights_info, |
| 62 | const Size2D &dilation, const ActivationLayerInfo &act_info, unsigned int num_groups) |
| 63 | { |
| 64 | ARM_COMPUTE_UNUSED(weights_info); |
| 65 | |
| 66 | Conv2dInfo conv_info(info, dilation, act_info, false, num_groups); |
| 67 | func.configure(src, weights, bias, dst, conv_info); |
| 68 | } |
| 69 | } // namespace detail |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 70 | namespace |
| 71 | { |
Pablo Tello | af7e600 | 2018-10-08 15:53:14 +0100 | [diff] [blame] | 72 | const RelativeTolerance<float> rel_tolerance_f32(0.01f); /**< Relative tolerance for FP32 types */ |
| 73 | const RelativeTolerance<float> rel_tolerance_winograd_3x3_f32(0.05f); /**< Relative tolerance for FP32 types */ |
| 74 | const AbsoluteTolerance<float> abs_tolerance_f32(0.002f); /**< Absolute tolerance for FP32 types */ |
| 75 | const AbsoluteTolerance<float> abs_tolerance_1xN_f32(0.0041f); /**< Absolute tolerance for FP32 types */ |
Pablo Tello | 952aeb1 | 2018-09-12 09:47:25 +0100 | [diff] [blame] | 76 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 77 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 78 | const AbsoluteTolerance<half> tolerance_convolution_layer_f16(half(0.4f)); |
| 79 | constexpr float tolerance_num_f16 = 0.15f; |
| 80 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 81 | |
| 82 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Gian Marco Iodice | 41acb76 | 2018-08-23 10:25:06 +0100 | [diff] [blame] | 83 | const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for FP16 types */ |
| 84 | const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance for FP16 types */ |
| 85 | constexpr float tolerance_num = 0.07f; /**< Tolerance number for the FP16 implementation */ |
| 86 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Viet-Hoa Do | 4e84f24 | 2023-04-06 14:48:58 +0100 | [diff] [blame] | 87 | |
| 88 | #ifdef ARM_COMPUTE_ENABLE_SME |
| 89 | // TODO(COMPMID-6011): SME kernels and the reference model use different rounding mode. |
| 90 | // Temporarily increase the tolerance for quantized data. |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 91 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(1.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 92 | #else // ARM_COMPUTE_ENABLE_SME |
| 93 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 94 | #endif // ARM_COMPUTE_ENABLE_SME |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 95 | |
| 96 | /** CNN data types */ |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 97 | const auto CNNDataTypes = make("DataType", |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 98 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 99 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 100 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 101 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 102 | DataType::F32, |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 103 | DataType::QASYMM8, |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 104 | }); |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 105 | const auto ActivationFunctionsDataset = make("ActivationInfo", |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 106 | { |
| 107 | ActivationLayerInfo(), |
| 108 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 109 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f) |
| 110 | }); |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 111 | |
Gunes Bayir | 9167c9c | 2024-03-06 09:58:40 +0000 | [diff] [blame] | 112 | const auto NoActivation = make("ActivationInfo", |
| 113 | { |
| 114 | ActivationLayerInfo(), |
| 115 | }); |
| 116 | |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 117 | const auto ActivationFunctionsDatasetNightly = make("ActivationInfo", |
| 118 | { |
| 119 | ActivationLayerInfo(), |
| 120 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 121 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f), |
| 122 | |
| 123 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f, -0.5f), |
| 124 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LEAKY_RELU, 0.1f), |
| 125 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SOFT_RELU), |
| 126 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::ELU), |
| 127 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::ABS), |
| 128 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), |
| 129 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), |
| 130 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQUARE), |
| 131 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SWISH), |
| 132 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::HARD_SWISH), |
| 133 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 2.f, 1.f), |
| 134 | #ifdef __aarch64__ |
| 135 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::GELU), |
| 136 | #endif // __aarch64__ |
| 137 | }); |
| 138 | |
| 139 | const auto QuantizationData = make("QuantizationInfo", |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 140 | { |
| 141 | QuantizationInfo(0.5f, 10), |
| 142 | QuantizationInfo(0.3f, 3), |
| 143 | QuantizationInfo(1.f, 10), |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 144 | QuantizationInfo(1.1f, 10), |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 145 | }); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 146 | } // namespace |
| 147 | |
| 148 | TEST_SUITE(NEON) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 149 | TEST_SUITE(ConvolutionLayer) |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 150 | |
| 151 | // *INDENT-OFF* |
| 152 | // clang-format off |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 153 | DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 154 | make("InputInfo", { TensorInfo(TensorShape(18U, 18U, 32U), 1, DataType::F32), |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 155 | TensorInfo(TensorShape(23U, 27U, 32U, 4U), 1, DataType::F32), |
| 156 | TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32), |
| 157 | TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32) |
| 158 | }), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 159 | make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 32U, 21U), 1, DataType::F32), |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 160 | TensorInfo(TensorShape(5U, 5U, 32U, 21U), 1, DataType::F32), |
| 161 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32), |
| 162 | TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16) |
| 163 | })), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 164 | make("OutputInfo", { TensorInfo(TensorShape(16U, 16U, 21U), 1, DataType::F32), |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 165 | TensorInfo(TensorShape(19U, 23U, 21U, 4U), 1, DataType::F32), |
| 166 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 167 | TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32) |
| 168 | })), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 169 | make("ConvInfo", { PadStrideInfo(1, 1, 0, 0), |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 170 | PadStrideInfo(1, 1, 0, 0), |
| 171 | PadStrideInfo(2, 1, 0, 0), |
| 172 | PadStrideInfo(3, 2, 1, 0) |
| 173 | })), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 174 | make("FastMath", { true, |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 175 | true, |
| 176 | false, |
| 177 | false |
| 178 | })), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 179 | make("Expected", { ConvolutionMethod::WINOGRAD, ConvolutionMethod::WINOGRAD, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })), |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 180 | input_info, weights_info, output_info, conv_info, fast_math, expected) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 181 | { |
Michele Di Giorgio | a0efe69 | 2021-07-30 10:25:59 +0100 | [diff] [blame] | 182 | ConvolutionMethod is_valid = NEConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(true), |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 183 | &weights_info.clone()->set_is_resizable(true), |
| 184 | &output_info.clone()->set_is_resizable(true), conv_info, WeightsInfo(), Size2D(1U, 1U), ActivationLayerInfo(), fast_math); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 185 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 186 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 187 | // clang-format on |
| 188 | // *INDENT-ON* |
| 189 | TEST_SUITE_END() // ConvolutionLayer |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 190 | |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 191 | /* |
| 192 | Testing Strategy of Neon Winograd: |
| 193 | - There is no need to thoroughly test nchw cases because winograd kernels accept |
| 194 | nhwc and the tensors are permuted before and after if they're nchw. |
| 195 | - Except relu and bounded relu, testing activations for a single input |
| 196 | combination is enough because activation is not fused into winograd and called |
| 197 | separately. |
| 198 | */ |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 199 | TEST_SUITE(WinogradLayer) |
| 200 | template <typename T> |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 201 | using NEWinogradConvolutionLayerFixture = WinogradConvolutionLayerFastMathValidationFixture<Tensor, Accessor, NEWinogradConvolutionLayer, T>; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 202 | template <typename T> |
| 203 | using NEWinogradConvolutionLayerMixedDataLayoutFixture = WinogradConvolutionLayerFastMathValidationFixture<Tensor, Accessor, NEWinogradConvolutionLayer, T, T, true, true>; |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 204 | |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 205 | template <typename T> |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 206 | using NEWinogradConvolutionLayerNoBiasFixture = WinogradConvolutionLayerFastMathValidationFixture<Tensor, Accessor, NEWinogradConvolutionLayer, T, T, false>; |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 207 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 208 | /** Test case for memory injection in @ref cpu::CpuWinogradConv2d. |
| 209 | * |
| 210 | * Configure the operator once and inject memory at run-time in multiple executions. |
| 211 | * |
| 212 | * Checks performed in order: |
| 213 | * - Both runs compute the same output |
| 214 | */ |
| 215 | TEST_CASE(MemoryInjection, framework::DatasetMode::ALL) |
| 216 | { |
| 217 | auto winograd = std::make_unique<cpu::CpuWinogradConv2d>(); |
| 218 | const auto src_info = TensorInfo(TensorShape(8U, 8U, 32U), 1, DataType::F32); |
| 219 | const auto w_info = TensorInfo(TensorShape(1U), 1, DataType::F32); |
| 220 | const auto b_info = TensorInfo(TensorShape(1U, 3U, 32U, 1U), 1, DataType::F32); |
| 221 | auto dst_info = TensorInfo(TensorShape(8U, 6U, 1U), 1, DataType::F32); |
| 222 | const PadStrideInfo pad_info{}; |
| 223 | |
| 224 | winograd->configure(&src_info, &b_info, &w_info, &dst_info, pad_info); |
| 225 | |
| 226 | // telhs are newly created every call of this lambda function |
| 227 | auto a = create_tensor<Tensor>(src_info); |
| 228 | auto b = create_tensor<Tensor>(b_info); |
| 229 | auto c = create_tensor<Tensor>(w_info); |
| 230 | a.allocator()->allocate(); |
| 231 | b.allocator()->allocate(); |
| 232 | c.allocator()->allocate(); |
| 233 | |
| 234 | ITensorPack run_pack{ { TensorType::ACL_SRC_0, &a }, { TensorType::ACL_SRC_1, &b }, { TensorType::ACL_SRC_2, &c } }; |
| 235 | ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &b }, { TensorType::ACL_SRC_2, &c } }; |
| 236 | |
| 237 | auto mg = MemoryGroup{}; |
| 238 | auto ws = manage_workspace<Tensor>(winograd->workspace(), mg, run_pack, prep_pack); |
| 239 | auto run_conv = [&]() -> Tensor |
| 240 | { |
| 241 | auto dst = create_tensor<Tensor>(dst_info); |
| 242 | dst.allocator()->allocate(); |
| 243 | |
| 244 | run_pack.add_tensor(TensorType::ACL_DST, &dst); |
| 245 | library->fill_tensor_value(Accessor(a), 1.f); |
| 246 | library->fill_tensor_value(Accessor(b), 2.f); |
| 247 | library->fill_tensor_value(Accessor(c), 3.f); |
| 248 | |
| 249 | // This operator is configured once and captured by this lambda. |
| 250 | winograd->prepare(prep_pack); |
| 251 | winograd->run(run_pack); |
| 252 | return dst; |
| 253 | }; |
| 254 | |
| 255 | auto result_0 = run_conv(); |
| 256 | auto result_1 = run_conv(); |
| 257 | |
| 258 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 259 | { |
| 260 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /** Test case for memory injection in @ref NEWinogradConvolutionLayer. |
| 265 | * |
| 266 | * Make sure @ref NEWinogradConvolutionLayer still works through injecting the memory at configure time using the old API. |
| 267 | * |
| 268 | * Checks performed in order: |
| 269 | * - Both runs compute the same output |
| 270 | */ |
| 271 | TEST_CASE(MultipleExecutionWithConfigure, framework::DatasetMode::ALL) |
| 272 | { |
| 273 | auto gemm = std::make_unique<NEWinogradConvolutionLayer>(); |
| 274 | const auto src_info = TensorInfo(TensorShape(8U, 8U, 32U), 1, DataType::F32); |
| 275 | const auto w_info = TensorInfo(TensorShape(1U), 1, DataType::F32); |
| 276 | const auto b_info = TensorInfo(TensorShape(1U, 3U, 32U, 1U), 1, DataType::F32); |
| 277 | auto dst_info = TensorInfo(TensorShape(8U, 6U, 1U), 1, DataType::F32); |
| 278 | const PadStrideInfo pad_info{}; |
| 279 | |
| 280 | auto run_conv = [&]() |
| 281 | { |
| 282 | auto src = create_tensor<Tensor>(src_info); |
| 283 | auto w = create_tensor<Tensor>(w_info); |
| 284 | auto b = create_tensor<Tensor>(b_info); |
| 285 | auto dst = create_tensor<Tensor>(dst_info); |
| 286 | |
| 287 | gemm->configure(&src, &b, &w, &dst, pad_info); |
| 288 | |
| 289 | src.allocator()->allocate(); |
| 290 | b.allocator()->allocate(); |
| 291 | w.allocator()->allocate(); |
| 292 | dst.allocator()->allocate(); |
| 293 | |
| 294 | library->fill_tensor_value(Accessor(src), 1.f); |
| 295 | library->fill_tensor_value(Accessor(b), 2.f); |
| 296 | library->fill_tensor_value(Accessor(w), 3.f); |
| 297 | gemm->run(); |
| 298 | return dst; |
| 299 | }; |
| 300 | |
| 301 | auto result_0 = run_conv(); |
| 302 | auto result_1 = run_conv(); |
| 303 | |
| 304 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 305 | { |
| 306 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 307 | } |
| 308 | } |
| 309 | |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 310 | DATA_TEST_CASE(SupportedKernels, framework::DatasetMode::ALL, zip( |
| 311 | make("WeightsInfo", |
| 312 | { |
| 313 | // Shapes are always in NCHW format. When layout is NHWC, the shape is permuted |
| 314 | |
| 315 | // Fp32, NCHW/NHWC (layout does not matter as it's ) |
| 316 | // 3x1, 1x3, 3x3 --> all TRUE |
| 317 | TensorInfo(TensorShape(3U, 3U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 318 | TensorInfo(TensorShape(1U, 3U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 319 | TensorInfo(TensorShape(3U, 1U, 2U, 8U), 1, DataType::F32, DataLayout::NCHW), |
| 320 | |
| 321 | // 5x1, 1x5, 5x5 --> all TRUE |
| 322 | TensorInfo(TensorShape(5U, 5U, 2U, 8U), 1, DataType::F32, DataLayout::NCHW), |
| 323 | TensorInfo(TensorShape(1U, 5U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 324 | TensorInfo(TensorShape(5U, 1U, 2U, 8U), 1, DataType::F32, DataLayout::NCHW), |
| 325 | |
| 326 | // 7x1, 1x7, 7x7 |
| 327 | // --> all FALSE |
| 328 | TensorInfo(TensorShape(7U, 7U, 2U, 8U), 1, DataType::F32, DataLayout::NCHW), |
| 329 | TensorInfo(TensorShape(1U, 7U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 330 | TensorInfo(TensorShape(7U, 1U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 331 | |
| 332 | // unsupported kernel sizes |
| 333 | TensorInfo(TensorShape(2U, 2U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 334 | TensorInfo(TensorShape(5U, 2U, 2U, 8U), 1, DataType::F32, DataLayout::NHWC), |
| 335 | TensorInfo(TensorShape(3U, 6U, 2U, 8U), 1, DataType::F32, DataLayout::NCHW), |
| 336 | |
| 337 | // Fp16 |
| 338 | TensorInfo(TensorShape(3U, 3U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 339 | TensorInfo(TensorShape(1U, 3U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 340 | TensorInfo(TensorShape(3U, 1U, 2U, 8U), 1, DataType::F16, DataLayout::NCHW), |
| 341 | |
| 342 | // 5x1, 1x5, 5x5 --> all TRUE |
| 343 | TensorInfo(TensorShape(5U, 5U, 2U, 8U), 1, DataType::F16, DataLayout::NCHW), |
| 344 | TensorInfo(TensorShape(1U, 5U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 345 | TensorInfo(TensorShape(5U, 1U, 2U, 8U), 1, DataType::F16, DataLayout::NCHW), |
| 346 | |
| 347 | // 7x1, 1x7, 7x7 |
| 348 | // --> all FALSE |
| 349 | TensorInfo(TensorShape(7U, 7U, 2U, 8U), 1, DataType::F16, DataLayout::NCHW), |
| 350 | TensorInfo(TensorShape(1U, 7U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 351 | TensorInfo(TensorShape(7U, 1U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 352 | |
| 353 | // unsupported kernel sizes |
| 354 | TensorInfo(TensorShape(2U, 2U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 355 | TensorInfo(TensorShape(5U, 2U, 2U, 8U), 1, DataType::F16, DataLayout::NHWC), |
| 356 | TensorInfo(TensorShape(3U, 6U, 2U, 8U), 1, DataType::F16, DataLayout::NCHW), |
| 357 | |
| 358 | }), |
| 359 | make("Expected", |
| 360 | { |
| 361 | // fp32 |
| 362 | true, true, true, // 3x3, 1x3, 3x1 |
| 363 | true, true, true, // 5x5, 1x5, 5x1 |
| 364 | false, true, true, // 7x7, 1x7, 7x1 |
| 365 | false, false, false, // random unsupported kernels |
| 366 | |
| 367 | // fp16 |
| 368 | true, false, false, // 3x3, 1x3, 3x1 |
| 369 | false, false, false, // 5x5, 1x5, 5x1 |
| 370 | false, false, false, // 7x7, 1x7, 7x1 |
| 371 | false, false, false, // random unsupported kernels |
| 372 | })), |
| 373 | weights_info_const, expected_const) |
| 374 | { |
| 375 | DataType data_type = weights_info_const.data_type(); |
| 376 | DataLayout data_layout = weights_info_const.data_layout(); |
| 377 | |
| 378 | TensorInfo input_info = TensorInfo(TensorShape(17U, 31U, 2U), 1, data_type); |
| 379 | TensorInfo bias_info = TensorInfo(TensorShape(8U), 1, data_type); |
| 380 | TensorInfo weights_info = weights_info_const; |
| 381 | |
| 382 | if(data_layout == DataLayout::NHWC) |
| 383 | { |
| 384 | // Convert to NHWC |
| 385 | PermutationVector perm = PermutationVector(2U, 0U, 1U); |
| 386 | |
| 387 | TensorShape input_shape = input_info.tensor_shape(); |
| 388 | TensorShape weights_shape = weights_info.tensor_shape(); |
| 389 | permute(input_shape, perm); |
| 390 | permute(weights_shape, perm); |
| 391 | |
| 392 | input_info.set_tensor_shape(input_shape); |
| 393 | weights_info.set_tensor_shape(weights_shape); |
| 394 | |
| 395 | input_info.set_data_layout(data_layout); |
| 396 | weights_info.set_data_layout(data_layout); |
| 397 | bias_info.set_data_layout(data_layout); |
| 398 | } |
| 399 | |
| 400 | PadStrideInfo conv_info(1, 1, 0, 0); |
| 401 | |
| 402 | TensorShape output_shape = compute_deep_convolution_shape(input_info, weights_info, conv_info); |
| 403 | TensorInfo output_info = TensorInfo(output_shape, 1, data_type, data_layout); |
| 404 | |
| 405 | Status status = NEWinogradConvolutionLayer::validate( |
| 406 | &input_info, |
| 407 | &weights_info, |
| 408 | &bias_info, |
| 409 | &output_info, |
| 410 | conv_info, |
| 411 | ActivationLayerInfo(), |
| 412 | true /* fast math */); |
| 413 | |
| 414 | Status fp16_supported = ::arm_compute::error_on_unsupported_cpu_fp16("N/A", "N/A", 0, &input_info); |
| 415 | bool expected = expected_const && static_cast<bool>(fp16_supported); |
| 416 | |
| 417 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 418 | } |
| 419 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 420 | TEST_SUITE(FP32) |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 421 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 422 | TEST_SUITE(Conv1x3) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 423 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 424 | combine(datasets::SmallWinogradConvolutionLayer1x3Dataset(), |
| 425 | make("DataType", { DataType::F32 }), |
| 426 | ActivationFunctionsDataset, |
| 427 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 428 | { |
| 429 | // Validate output |
| 430 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 431 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 432 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEWinogradConvolutionLayerMixedDataLayoutFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 433 | combine( |
| 434 | make("Input", TensorShape(8U, 8U, 32U)), |
| 435 | make("Weight", TensorShape(1U, 3U, 32U, 1U)), |
| 436 | make("Bias", TensorShape(1U)), |
| 437 | make("Output", TensorShape(8U, 6U, 1U)), |
| 438 | make("PadStrideInfo", PadStrideInfo(1, 1, 0, 0)), |
| 439 | make("Dilation", Size2D(1U, 1U)), |
| 440 | make("DataType", { DataType::F32 }), |
| 441 | ActivationFunctionsDataset, |
| 442 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 443 | { |
| 444 | // Validate output |
| 445 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 446 | } |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 447 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 448 | combine(datasets::LargeWinogradConvolutionLayer1x3Dataset(), |
| 449 | make("DataType", { DataType::F32 }), |
| 450 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 451 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 452 | { |
| 453 | // Validate output |
Pablo Tello | 952aeb1 | 2018-09-12 09:47:25 +0100 | [diff] [blame] | 454 | validate(Accessor(_target), _reference, abs_tolerance_1xN_f32); |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | TEST_SUITE_END() // Conv1x3 |
| 458 | |
| 459 | TEST_SUITE(Conv3x1) |
| 460 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 461 | combine(datasets::SmallWinogradConvolutionLayer3x1Dataset(), |
| 462 | make("DataType", { DataType::F32 }), |
| 463 | ActivationFunctionsDataset, |
| 464 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 465 | { |
| 466 | // Validate output |
| 467 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 468 | } |
| 469 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 470 | combine(datasets::LargeWinogradConvolutionLayer3x1Dataset(), |
| 471 | make("DataType", { DataType::F32 }), |
| 472 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 473 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 474 | { |
| 475 | // Validate output |
Pablo Tello | 952aeb1 | 2018-09-12 09:47:25 +0100 | [diff] [blame] | 476 | validate(Accessor(_target), _reference, abs_tolerance_1xN_f32); |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | TEST_SUITE_END() // Conv3x1 |
| 480 | |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 481 | TEST_SUITE(Conv1x5) |
| 482 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 483 | combine(datasets::SmallWinogradConvolutionLayer1x5Dataset(), |
| 484 | make("DataType", { DataType::F32 }), |
| 485 | ActivationFunctionsDataset, |
| 486 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 487 | { |
| 488 | // Validate output |
| 489 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 490 | } |
| 491 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 492 | combine(datasets::LargeWinogradConvolutionLayer1x5Dataset(), |
| 493 | make("DataType", { DataType::F32 }), |
| 494 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 495 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 496 | { |
| 497 | // Validate output |
Pablo Tello | 952aeb1 | 2018-09-12 09:47:25 +0100 | [diff] [blame] | 498 | validate(Accessor(_target), _reference, abs_tolerance_1xN_f32); |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | TEST_SUITE_END() // Conv1x5 |
| 502 | |
| 503 | TEST_SUITE(Conv5x1) |
| 504 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 505 | combine(datasets::SmallWinogradConvolutionLayer5x1Dataset(), |
| 506 | make("DataType", { DataType::F32 }), |
| 507 | ActivationFunctionsDataset, |
| 508 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 509 | { |
| 510 | // Validate output |
| 511 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 512 | } |
| 513 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 514 | combine(datasets::LargeWinogradConvolutionLayer5x1Dataset(), |
| 515 | make("DataType", { DataType::F32 }), |
| 516 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 517 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 518 | { |
| 519 | // Validate output |
Pablo Tello | 952aeb1 | 2018-09-12 09:47:25 +0100 | [diff] [blame] | 520 | validate(Accessor(_target), _reference, abs_tolerance_1xN_f32); |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | TEST_SUITE_END() // Conv5x1 |
| 524 | |
Pablo Tello | 96e922e | 2018-09-26 11:25:15 +0100 | [diff] [blame] | 525 | TEST_SUITE(Conv7x1) |
| 526 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 527 | combine(datasets::SmallWinogradConvolutionLayer7x1Dataset(), |
| 528 | make("DataType", { DataType::F32 }), |
| 529 | ActivationFunctionsDataset, |
| 530 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | 96e922e | 2018-09-26 11:25:15 +0100 | [diff] [blame] | 531 | { |
| 532 | // Validate output |
| 533 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 534 | } |
| 535 | |
| 536 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
| 537 | combine(combine(combine(datasets::LargeWinogradConvolutionLayer7x1Dataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 538 | make("DataType", { DataType::F32 })), |
| 539 | make("ActivationInfo", { ActivationLayerInfo() })), |
| 540 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | 96e922e | 2018-09-26 11:25:15 +0100 | [diff] [blame] | 541 | { |
| 542 | // Validate output |
| 543 | validate(Accessor(_target), _reference, abs_tolerance_1xN_f32); |
| 544 | } |
| 545 | TEST_SUITE_END() // Conv7x1 |
| 546 | |
| 547 | TEST_SUITE(Conv1x7) |
| 548 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 549 | combine(datasets::SmallWinogradConvolutionLayer1x7Dataset(), |
| 550 | make("DataType", { DataType::F32 }), |
| 551 | ActivationFunctionsDataset, |
| 552 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | 96e922e | 2018-09-26 11:25:15 +0100 | [diff] [blame] | 553 | { |
| 554 | // Validate output |
| 555 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 556 | } |
| 557 | |
| 558 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 559 | combine(datasets::LargeWinogradConvolutionLayer7x1Dataset(), |
| 560 | make("DataType", { DataType::F32 }), |
| 561 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 562 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | 96e922e | 2018-09-26 11:25:15 +0100 | [diff] [blame] | 563 | { |
| 564 | // Validate output |
| 565 | validate(Accessor(_target), _reference, abs_tolerance_1xN_f32); |
| 566 | } |
| 567 | TEST_SUITE_END() // Conv1x7 |
| 568 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 569 | TEST_SUITE(Conv3x3) |
| 570 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 571 | combine(datasets::SmallWinogradConvolutionLayer3x3Dataset(), |
| 572 | make("DataType", { DataType::F32 }), |
| 573 | ActivationFunctionsDataset, |
| 574 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 575 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 576 | { |
| 577 | // Validate output |
Georgios Pinitas | 8dea602 | 2018-06-08 18:33:31 +0100 | [diff] [blame] | 578 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 579 | } |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 580 | |
| 581 | /// It's enough to run the activations for a single weight/input combination and data type because |
| 582 | /// activation function is called on top of the winograd output as a separate operator |
| 583 | /// TODO: Enable after COMPMID-6573 is resolved |
| 584 | FIXTURE_DATA_TEST_CASE(RunActivations, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::DISABLED, |
| 585 | combine( |
| 586 | make("Input", TensorShape(3U, 3U, 32U)), |
| 587 | make("Weight", TensorShape(3U, 3U, 32U, 4U)), |
| 588 | make("Bias", TensorShape(4U)), |
| 589 | make("Output", TensorShape(1U, 1U, 4U)), |
| 590 | make("PadStrideInfo", PadStrideInfo(1, 1, 0, 0)), |
| 591 | make("Dilation", Size2D(1U, 1U)), |
| 592 | make("DataType", { DataType::F32 }), |
| 593 | ActivationFunctionsDatasetNightly, |
| 594 | make("DataLayout", { DataLayout::NHWC }))) |
| 595 | { |
| 596 | // Validate output |
| 597 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 598 | } |
| 599 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 600 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 601 | combine(datasets::LargeWinogradConvolutionLayer3x3Dataset(), |
| 602 | make("DataType", { DataType::F32 }), |
| 603 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 604 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 605 | |
| 606 | { |
| 607 | // Validate output |
Pablo Tello | af7e600 | 2018-10-08 15:53:14 +0100 | [diff] [blame] | 608 | // floating point arithmetic the Winograd results will not be exactly the same as direct convolution, especially for big shapes |
| 609 | validate(Accessor(_target), _reference, rel_tolerance_winograd_3x3_f32, 0.f, float(abs_tolerance_f32)); |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 610 | } |
| 611 | TEST_SUITE_END() // Conv3x3 |
| 612 | |
| 613 | TEST_SUITE(Conv5x5) |
| 614 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 615 | combine(datasets::SmallWinogradConvolutionLayer5x5Dataset(), |
| 616 | make("DataType", { DataType::F32 }), |
| 617 | ActivationFunctionsDataset, |
| 618 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 619 | |
| 620 | { |
| 621 | // Validate output |
| 622 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 623 | } |
| 624 | FIXTURE_DATA_TEST_CASE(RunLarge, NEWinogradConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 625 | combine(datasets::LargeWinogradConvolutionLayer5x5Dataset(), |
| 626 | make("DataType", { DataType::F32 }), |
| 627 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 628 | make("DataLayout", { DataLayout::NHWC }))) |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 629 | |
| 630 | { |
| 631 | // Validate output |
| 632 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
| 633 | } |
| 634 | |
| 635 | TEST_SUITE_END() // Conv5x5 |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 636 | |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 637 | FIXTURE_DATA_TEST_CASE(RunSmallNoBias, NEWinogradConvolutionLayerNoBiasFixture<float>, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 638 | combine(framework::dataset::concat( |
| 639 | datasets::SmallWinogradConvolutionLayer3x3Dataset(), |
| 640 | datasets::SmallWinogradConvolutionLayer5x5Dataset()), |
| 641 | make("DataType", { DataType::F32 }), |
| 642 | ActivationFunctionsDataset, |
| 643 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 644 | { |
| 645 | // Validate output |
Georgios Pinitas | 8dea602 | 2018-06-08 18:33:31 +0100 | [diff] [blame] | 646 | validate(Accessor(_target), _reference, abs_tolerance_f32); |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 649 | TEST_SUITE_END() // FP32 |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 650 | |
| 651 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 652 | TEST_SUITE(FP16) |
| 653 | using CLWinogradConvolutionLayerFastMathFixture16 = WinogradConvolutionLayerFastMathValidationFixture<Tensor, Accessor, NEWinogradConvolutionLayer, half, float>; |
| 654 | |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 655 | DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip( |
| 656 | make("InputInfo", { TensorInfo(TensorShape(18U, 18U, 32U), 1, DataType::F16), |
| 657 | TensorInfo(TensorShape(18U, 18U, 32U), 1, DataType::F16) |
| 658 | }), |
| 659 | make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 32U, 21U), 1, DataType::F16), |
| 660 | TensorInfo(TensorShape(3U, 3U, 32U, 21U), 1, DataType::F16) |
| 661 | }), |
| 662 | make("OutputInfo", { TensorInfo(TensorShape(16U, 16U, 21U), 1, DataType::F32), |
| 663 | TensorInfo(TensorShape(16U, 16U, 21U), 1, DataType::F16) |
| 664 | }), |
| 665 | make("ConvInfo", { PadStrideInfo(1, 1, 0, 0), |
| 666 | PadStrideInfo(1, 1, 0, 0) |
| 667 | }), |
| 668 | make("FastMath", |
| 669 | { |
| 670 | false, // case fp16 and fast_math False then disable Winograd |
| 671 | true // case fp16 and fast_math True then enable Winograd |
| 672 | }), |
| 673 | make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::WINOGRAD })), |
| 674 | input_info, weights_info, output_info, conv_info, fast_math, expected) |
Ramy Elgammal | a4814e8 | 2022-09-08 15:05:19 +0100 | [diff] [blame] | 675 | { |
| 676 | ConvolutionMethod is_valid = NEConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(true), |
| 677 | &weights_info.clone()->set_is_resizable(true), |
| 678 | &output_info.clone()->set_is_resizable(true), conv_info, WeightsInfo(), Size2D(1U, 1U), ActivationLayerInfo(), fast_math); |
| 679 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 680 | } |
| 681 | |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 682 | TEST_SUITE(Conv3x3) |
| 683 | FIXTURE_DATA_TEST_CASE(RunSmall, CLWinogradConvolutionLayerFastMathFixture16, framework::DatasetMode::PRECOMMIT, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 684 | combine(datasets::SmallWinogradConvolutionLayer3x3Dataset(), |
| 685 | make("DataType", { DataType::F16 }), |
| 686 | ActivationFunctionsDataset, |
| 687 | make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 688 | |
| 689 | { |
| 690 | // Validate output |
| 691 | validate(Accessor(_target), _reference, tolerance_convolution_layer_f16, tolerance_num_f16); |
| 692 | } |
| 693 | |
| 694 | FIXTURE_DATA_TEST_CASE(RunLarge, CLWinogradConvolutionLayerFastMathFixture16, framework::DatasetMode::NIGHTLY, |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 695 | combine(datasets::LargeWinogradConvolutionLayer3x3Dataset(), |
| 696 | make("DataType", { DataType::F16 }), |
| 697 | make("ActivationInfo", { ActivationLayerInfo() }), |
| 698 | make("DataLayout", { DataLayout::NHWC }))) |
Georgios Pinitas | 5ce897f | 2020-04-29 11:44:10 +0100 | [diff] [blame] | 699 | |
| 700 | { |
| 701 | // Validate output |
| 702 | validate(Accessor(_target), _reference, tolerance_convolution_layer_f16, tolerance_num_f16); |
| 703 | } |
| 704 | TEST_SUITE_END() // Conv3x3 |
| 705 | TEST_SUITE_END() // FP16 |
| 706 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 707 | TEST_SUITE_END() // WinogradLayer |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 708 | |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 709 | #ifdef ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 710 | TEST_SUITE(FIXED_FORMAT_KERNELS) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 711 | TEST_SUITE(VariableWeightUtils) |
| 712 | |
| 713 | // UC2_1_* tests: the user requests a specific fixed format, but there is no kernel that supports it. |
| 714 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 715 | template <typename ConvolutionClass> |
| 716 | using HasOptImplFixtureNoFastMath = HasOptImplFixture<ConvolutionClass, /*enable_fast_math*/ false>; |
| 717 | |
| 718 | template <typename ConvolutionClass> |
| 719 | using HasOptImplFixtureFastMath = HasOptImplFixture<ConvolutionClass, /*enable_fast_math*/ true>; |
| 720 | |
| 721 | // UC2_1 |
| 722 | |
| 723 | FIXTURE_DATA_TEST_CASE(UC2_1_CpuGemmConv2d, HasOptImplFixtureNoFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 724 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 725 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo2 }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 726 | { |
| 727 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 728 | } |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 729 | FIXTURE_DATA_TEST_CASE(UC2_1_NEGEMMConvolutionLayer, HasOptImplFixtureNoFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 730 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 731 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo2 }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 732 | { |
| 733 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 734 | } |
| 735 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 736 | FIXTURE_DATA_TEST_CASE(UC2_1_CpuGemmConv2d_FastMath, HasOptImplFixtureFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
| 737 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
| 738 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo2 }))) |
| 739 | { |
| 740 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 741 | } |
| 742 | |
| 743 | FIXTURE_DATA_TEST_CASE(UC2_1_NEGEMMConvolutionLayer_FastMath, HasOptImplFixtureFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
| 744 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
| 745 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo2 }))) |
| 746 | { |
| 747 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 748 | } |
| 749 | |
| 750 | // UC2_2_* tests: the user requests a specific fixed format, and a |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 751 | // kernel that support that fixed format is found. |
| 752 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 753 | FIXTURE_DATA_TEST_CASE(UC2_2_CpuGemmConv2d, HasOptImplFixtureNoFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 754 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 755 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo4 }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 756 | { |
| 757 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 758 | ARM_COMPUTE_EXPECT(_computed_weight_format == arm_compute::WeightFormat::OHWIo4, framework::LogLevel::ERRORS); |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 761 | FIXTURE_DATA_TEST_CASE(UC2_2_NEGEMMConvolutionLayer, HasOptImplFixtureNoFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 762 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 763 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo4 }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 764 | { |
| 765 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 766 | ARM_COMPUTE_EXPECT(_computed_weight_format == arm_compute::WeightFormat::OHWIo4, framework::LogLevel::ERRORS); |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 767 | } |
| 768 | |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 769 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
| 770 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 771 | FIXTURE_DATA_TEST_CASE(UC2_2_CpuGemmConv2d_FastMath, HasOptImplFixtureFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
| 772 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
| 773 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo8i4_bf16 }))) |
| 774 | { |
| 775 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
| 776 | ARM_COMPUTE_EXPECT_EQUAL(_computed_weight_format, arm_compute::WeightFormat::OHWIo8i4_bf16, framework::LogLevel::ERRORS); |
| 777 | } |
| 778 | |
| 779 | FIXTURE_DATA_TEST_CASE(UC2_2_NEGEMMConvolutionLayer_FastMath, HasOptImplFixtureFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
| 780 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
| 781 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::OHWIo8i4_bf16 }))) |
| 782 | { |
| 783 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
| 784 | ARM_COMPUTE_EXPECT(_computed_weight_format == arm_compute::WeightFormat::OHWIo8i4_bf16, framework::LogLevel::ERRORS); |
| 785 | } |
| 786 | |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 787 | #endif // ARM_COMPUTE_ENABLE_BF16 |
| 788 | |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 789 | // UC3_1_* tests: the user queries for ANY fixed format, but there is |
| 790 | // no kernel that support the use case specified by the user (for |
| 791 | // example, there is no fixed format kernel for the datatype of the |
| 792 | // problem). |
| 793 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 794 | FIXTURE_DATA_TEST_CASE(UC3_1_CpuGemmConv2d, HasOptImplFixtureNoFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 795 | combine(framework::dataset::make("DataType", { DataType::S32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 796 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 797 | { |
| 798 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 799 | } |
| 800 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 801 | FIXTURE_DATA_TEST_CASE(UC3_1_NEGEMMConvolutionLayer, HasOptImplFixtureNoFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
| 802 | combine(framework::dataset::make("DataType", { DataType::S32 }), |
| 803 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
| 804 | { |
| 805 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 806 | } |
| 807 | |
| 808 | FIXTURE_DATA_TEST_CASE(UC3_1_CpuGemmConv2d_FastMath, HasOptImplFixtureFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
| 809 | combine(framework::dataset::make("DataType", { DataType::S32 }), |
| 810 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
| 811 | { |
| 812 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 813 | } |
| 814 | |
| 815 | FIXTURE_DATA_TEST_CASE(UC3_1_NEGEMMConvolutionLayer_FastMath, HasOptImplFixtureFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 816 | combine(framework::dataset::make("DataType", { DataType::S32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 817 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 818 | { |
| 819 | ARM_COMPUTE_EXPECT(!_kernel_found, framework::LogLevel::ERRORS); |
| 820 | } |
| 821 | |
| 822 | // UC3_2_* tests: the user queries for ANY fixed format. The search |
| 823 | // succeeded and the fixed format found is prompted back for |
| 824 | // consumption by the user. Note that we just test the |
| 825 | // _computed_weight_format to be anything but not the formats that are |
| 826 | // not fixed formats (ANY and UNSPECIFIED). This is because the weight |
| 827 | // format that the runtime produces depends on the size of the vector |
| 828 | // units of the hardware where the tests is executed. For example, a |
| 829 | // format like OHWIo4 for FP32 data returned for 128-bit NEON hardware |
| 830 | // is replaced by OHWIo8 when running on 256-bit SVE. |
| 831 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 832 | FIXTURE_DATA_TEST_CASE(UC3_2_CpuGemmConv2d, HasOptImplFixtureNoFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 833 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 834 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 835 | { |
| 836 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 837 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::ANY, framework::LogLevel::ERRORS); |
| 838 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::UNSPECIFIED, framework::LogLevel::ERRORS); |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 841 | FIXTURE_DATA_TEST_CASE(UC3_2_NEGEMMConvolutionLayer, HasOptImplFixtureNoFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 842 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 843 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 844 | { |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 845 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::ANY, framework::LogLevel::ERRORS); |
| 846 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::UNSPECIFIED, framework::LogLevel::ERRORS); |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 847 | } |
| 848 | |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 849 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
| 850 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 851 | FIXTURE_DATA_TEST_CASE(UC3_2_CpuGemmConv2d_FastMath, HasOptImplFixtureFastMath<cpu::CpuGemmConv2d>, framework::DatasetMode::ALL, |
| 852 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
| 853 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
| 854 | { |
| 855 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
| 856 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::ANY, framework::LogLevel::ERRORS); |
| 857 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::UNSPECIFIED, framework::LogLevel::ERRORS); |
| 858 | ARM_COMPUTE_EXPECT(arm_compute::is_fixed_format_fast_math(_computed_weight_format), framework::LogLevel::ERRORS); |
| 859 | } |
| 860 | |
| 861 | FIXTURE_DATA_TEST_CASE(UC3_2_NEGEMMConvolutionLayer_FastMath, HasOptImplFixtureFastMath<NEGEMMConvolutionLayer>, framework::DatasetMode::ALL, |
| 862 | combine(framework::dataset::make("DataType", { DataType::F32 }), |
| 863 | framework::dataset::make("QueryWeightFormat", { arm_compute::WeightFormat::ANY }))) |
| 864 | { |
| 865 | ARM_COMPUTE_EXPECT(_kernel_found, framework::LogLevel::ERRORS); |
| 866 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::ANY, framework::LogLevel::ERRORS); |
| 867 | ARM_COMPUTE_EXPECT(_computed_weight_format != arm_compute::WeightFormat::UNSPECIFIED, framework::LogLevel::ERRORS); |
| 868 | ARM_COMPUTE_EXPECT(arm_compute::is_fixed_format_fast_math(_computed_weight_format), framework::LogLevel::ERRORS); |
| 869 | } |
| 870 | |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 871 | #endif // ARM_COMPUTE_ENABLE_BF16 |
| 872 | |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 873 | namespace |
| 874 | { |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 875 | using TestCaseType = std::tuple<TensorShape, TensorShape, arm_compute::WeightFormat>; |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 876 | auto prepare_weights_shapes = framework::dataset::make("TensorShape", |
| 877 | { |
| 878 | // OHWIo<interleave_by>i<block_by> |
| 879 | // |
| 880 | // OHWI --> O'HWI', where: |
| 881 | // |
| 882 | // O'= smallest multiple of <interleave_by> such that O<=O' |
| 883 | // I'= smallest multiple of <block_by> such that I<=I' |
| 884 | // |
| 885 | |
| 886 | // Change N for OHWIo4 |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 887 | TestCaseType({ { 1U, 1U, 1U, 1U }, { 1U, 1U, 1U, 4U }, arm_compute::WeightFormat::OHWIo4 }), |
| 888 | TestCaseType({ { 1U, 1U, 1U, 2U }, { 1U, 1U, 1U, 4U }, arm_compute::WeightFormat::OHWIo4 }), |
| 889 | TestCaseType({ { 1U, 1U, 1U, 3U }, { 1U, 1U, 1U, 4U }, arm_compute::WeightFormat::OHWIo4 }), |
| 890 | TestCaseType({ { 1U, 1U, 1U, 4U }, { 1U, 1U, 1U, 4U }, arm_compute::WeightFormat::OHWIo4 }), |
| 891 | TestCaseType({ { 1U, 1U, 1U, 5U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo4 }), |
| 892 | TestCaseType({ { 1U, 1U, 1U, 6U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo4 }), |
| 893 | TestCaseType({ { 1U, 1U, 1U, 7U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo4 }), |
| 894 | TestCaseType({ { 1U, 1U, 1U, 8U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo4 }), |
| 895 | TestCaseType({ { 1U, 1U, 1U, 9U }, { 1U, 1U, 1U, 12U }, arm_compute::WeightFormat::OHWIo4 }), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 896 | // // Change N for OHWIo8 |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 897 | TestCaseType({ { 1U, 1U, 1U, 1U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 898 | TestCaseType({ { 1U, 1U, 1U, 2U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 899 | TestCaseType({ { 1U, 1U, 1U, 3U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 900 | TestCaseType({ { 1U, 1U, 1U, 4U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 901 | TestCaseType({ { 1U, 1U, 1U, 5U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 902 | TestCaseType({ { 1U, 1U, 1U, 6U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 903 | TestCaseType({ { 1U, 1U, 1U, 7U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 904 | TestCaseType({ { 1U, 1U, 1U, 8U }, { 1U, 1U, 1U, 8U }, arm_compute::WeightFormat::OHWIo8 }), |
| 905 | TestCaseType({ { 1U, 1U, 1U, 9U }, { 1U, 1U, 1U, 16U }, arm_compute::WeightFormat::OHWIo8 }), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 906 | // // Change N for OHWIo4 when H, W and C are not 1 |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 907 | TestCaseType({ { 3U, 4U, 2U, 1U }, { 3, 4, 2, 4 }, arm_compute::WeightFormat::OHWIo4 }), |
| 908 | TestCaseType({ { 3U, 4U, 2U, 2U }, { 3, 4, 2, 4 }, arm_compute::WeightFormat::OHWIo4 }), |
| 909 | TestCaseType({ { 3U, 4U, 2U, 3U }, { 3, 4, 2, 4 }, arm_compute::WeightFormat::OHWIo4 }), |
| 910 | TestCaseType({ { 3U, 4U, 2U, 4U }, { 3, 4, 2, 4 }, arm_compute::WeightFormat::OHWIo4 }), |
| 911 | TestCaseType({ { 3U, 4U, 2U, 5U }, { 3, 4, 2, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 912 | TestCaseType({ { 3U, 4U, 2U, 6U }, { 3, 4, 2, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 913 | TestCaseType({ { 3U, 4U, 2U, 7U }, { 3, 4, 2, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 914 | TestCaseType({ { 3U, 4U, 2U, 8U }, { 3, 4, 2, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 915 | TestCaseType({ { 3U, 4U, 2U, 9U }, { 3, 4, 2, 12 }, arm_compute::WeightFormat::OHWIo4 }), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 916 | |
| 917 | // // Fix N and move HWI around, with different data layouts and formats |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 918 | TestCaseType({ { 2U, 4U, 3U, 5U }, { 2, 4, 3, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 919 | TestCaseType({ { 3U, 4U, 2U, 5U }, { 3, 4, 2, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 920 | TestCaseType({ { 2U, 4U, 3U, 9U }, { 2, 4, 3, 16 }, arm_compute::WeightFormat::OHWIo8 }), |
| 921 | TestCaseType({ { 3U, 4U, 2U, 9U }, { 3, 4, 2, 16 }, arm_compute::WeightFormat::OHWIo8 }), |
| 922 | TestCaseType({ { 1024U, 1U, 1U, 1001U }, { 1024, 1, 1, 1008 }, arm_compute::WeightFormat::OHWIo8 }), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 923 | |
| 924 | // // Adding <block_by> on I (=C) |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 925 | TestCaseType({ { 1U, 4U, 3U, 5U }, { 2, 4, 3, 8 }, arm_compute::WeightFormat::OHWIo4i2 }), |
| 926 | TestCaseType({ { 2U, 4U, 3U, 5U }, { 2, 4, 3, 8 }, arm_compute::WeightFormat::OHWIo4i2 }), |
| 927 | TestCaseType({ { 3U, 4U, 3U, 5U }, { 4, 4, 3, 8 }, arm_compute::WeightFormat::OHWIo4i2 }), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 928 | |
| 929 | // --------- |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 930 | TestCaseType({ { 2, 2, 1, 5 }, { 2, 2, 1, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
| 931 | TestCaseType({ { 1, 2, 2, 5 }, { 1, 2, 2, 8 }, arm_compute::WeightFormat::OHWIo4 }), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 932 | |
| 933 | }); |
| 934 | } // unnamed namespace |
| 935 | |
| 936 | DATA_TEST_CASE(PrepareWeightShape, framework::DatasetMode::ALL, |
| 937 | prepare_weights_shapes, shapes) |
| 938 | { |
Ramy Elgammal | 9178002 | 2022-07-20 14:57:37 +0100 | [diff] [blame] | 939 | const TensorShape input_shape = std::get<0>(shapes); |
| 940 | const TensorShape expected_shape = std::get<1>(shapes); |
| 941 | const arm_compute::WeightFormat wf = std::get<2>(shapes); |
| 942 | const DataType DT = DataType::F32; |
| 943 | const DataLayout DL = DataLayout::NHWC; |
| 944 | const auto TI = TensorInfo(input_shape, 1 /*num_channels, deprecated*/, DT, DL); |
Jonathan Deakin | 464ed20 | 2023-01-12 11:41:14 +0000 | [diff] [blame] | 945 | const TensorInfo computed_info = ::arm_compute::test::validation::prepare_weights(TI, wf); |
| 946 | ARM_COMPUTE_EXPECT_EQUAL(computed_info.tensor_shape(), expected_shape, framework::LogLevel::ERRORS); |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | TEST_SUITE_END() // VariableWeightUtils |
| 950 | |
| 951 | TEST_SUITE(ExperimentalCpuAPIVariableWeightWithFixtures) |
| 952 | |
| 953 | template <typename ScalarType> |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 954 | using VarWidth = VariableWeightsFixture<cpu::CpuGemmConv2d, Tensor, Accessor, ScalarType, /*enable_fast_math*/ false>; |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 955 | |
| 956 | FIXTURE_DATA_TEST_CASE(RunSmallFloat, VarWidth<float>, framework::DatasetMode::ALL, |
| 957 | combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 958 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 959 | framework::dataset::make("ACL Scalar type", { DataType::F32 }))) |
| 960 | { |
| 961 | // Validate output |
| 962 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 963 | } |
| 964 | |
Mohammed Suhail Munshi | 8050d22 | 2024-02-04 17:55:40 +0000 | [diff] [blame] | 965 | #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 966 | FIXTURE_DATA_TEST_CASE(RunSmallHalf, VarWidth<half>, framework::DatasetMode::ALL, |
| 967 | combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 968 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 969 | framework::dataset::make("ACL Scalar type", { DataType::F16 }))) |
| 970 | { |
| 971 | // Validate output |
| 972 | validate(Accessor(_target), _reference, rel_tolerance_f16, 0.f, half(abs_tolerance_f16)); |
| 973 | } |
Mohammed Suhail Munshi | 8050d22 | 2024-02-04 17:55:40 +0000 | [diff] [blame] | 974 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 975 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 976 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
| 977 | template <typename ScalarType> |
| 978 | using VarWidthFastMath = VariableWeightsFixture<cpu::CpuGemmConv2d, Tensor, Accessor, ScalarType, /*enable_fast_math*/ true>; |
| 979 | |
| 980 | FIXTURE_DATA_TEST_CASE(RunSmallFloatFastMath, VarWidthFastMath<float>, framework::DatasetMode::ALL, |
| 981 | combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 982 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 983 | framework::dataset::make("ACL Scalar type", { DataType::F32 }))) |
| 984 | { |
| 985 | // Validate output |
| 986 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 987 | } |
| 988 | #endif // ARM_COMPUTE_ENABLE_BF16 |
| 989 | |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 990 | TEST_SUITE_END() // ExperimentalCpuAPIVariableWeightWithFixtures |
| 991 | |
| 992 | TEST_SUITE(ExperimentalNEAPIVariableWeightWithFixtures) |
| 993 | |
| 994 | template <typename ScalarType> |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 995 | using NEGEMMVarWidth = VariableWeightsFixtureNEInterface<NEGEMMConvolutionLayer, Tensor, Accessor, ScalarType, /*enable_fast_math*/ false>; |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 996 | |
| 997 | FIXTURE_DATA_TEST_CASE(NEGEMMRunSmallFloat, NEGEMMVarWidth<float>, framework::DatasetMode::ALL, |
| 998 | combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 999 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1000 | framework::dataset::make("ACL Scalar type", { DataType::F32 }))) |
| 1001 | { |
| 1002 | // Validate output |
| 1003 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1004 | } |
| 1005 | |
Mohammed Suhail Munshi | 8050d22 | 2024-02-04 17:55:40 +0000 | [diff] [blame] | 1006 | #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1007 | FIXTURE_DATA_TEST_CASE(NEGEMMRunSmallHalf, NEGEMMVarWidth<half>, framework::DatasetMode::ALL, |
| 1008 | combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 1009 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1010 | framework::dataset::make("ACL Scalar type", { DataType::F16 }))) |
| 1011 | { |
| 1012 | // Validate output |
| 1013 | validate(Accessor(_target), _reference, rel_tolerance_f16, 0.f, half(abs_tolerance_f16)); |
| 1014 | } |
Mohammed Suhail Munshi | 8050d22 | 2024-02-04 17:55:40 +0000 | [diff] [blame] | 1015 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1016 | |
Pablo Marquez Tello | 93581a5 | 2022-07-21 13:55:27 +0100 | [diff] [blame] | 1017 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
| 1018 | template <typename ScalarType> |
| 1019 | using NEGEMMVarWidthFastMath = VariableWeightsFixtureNEInterface<NEGEMMConvolutionLayer, Tensor, Accessor, ScalarType, /*enable_fast_math*/ true>; |
| 1020 | |
| 1021 | FIXTURE_DATA_TEST_CASE(NEGEMMRunSmallFloatFastMath, NEGEMMVarWidthFastMath<float>, framework::DatasetMode::ALL, |
| 1022 | combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 1023 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1024 | framework::dataset::make("ACL Scalar type", { DataType::F32 }))) |
| 1025 | { |
| 1026 | // Validate output |
| 1027 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1028 | } |
| 1029 | #endif // ARM_COMPUTE_ENABLE_BF16 |
| 1030 | |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1031 | TEST_SUITE_END() // ExperimentalNEAPIVariableWeightWithFixtures |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 1032 | TEST_SUITE_END() // FIXED_FORMAT_KERNELS |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 1033 | |
| 1034 | #endif // ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
| 1035 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 1036 | TEST_SUITE(GEMMConvolutionLayer) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1037 | template <typename T> |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1038 | using NEGEMMConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1039 | template <typename T> |
SiCong Li | c5ab4df | 2023-10-17 17:38:57 +0100 | [diff] [blame] | 1040 | using NEGEMMConvolutionLayerPaddedWeightsFixture = ConvolutionValidationPaddedWeightsFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
| 1041 | template <typename T> |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1042 | using NEGEMMConvolutionLayerMixedDataLayoutFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T, true>; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1043 | |
Georgios Pinitas | 1988463 | 2021-08-16 12:38:54 +0100 | [diff] [blame] | 1044 | /** Test case for memory injection in @ref cpu::CpuGemmConv2d. |
Manuel Bottini | 29599d0 | 2021-07-06 15:01:35 +0100 | [diff] [blame] | 1045 | * |
| 1046 | * Configure the operator once and inject memory at run-time in multiple executions. |
| 1047 | * |
| 1048 | * Checks performed in order: |
| 1049 | * - Both runs compute the same output |
| 1050 | */ |
| 1051 | TEST_CASE(MemoryInjection, framework::DatasetMode::ALL) |
| 1052 | { |
Georgios Pinitas | 1988463 | 2021-08-16 12:38:54 +0100 | [diff] [blame] | 1053 | auto conv = std::make_unique<cpu::CpuGemmConv2d>(); |
Manuel Bottini | 29599d0 | 2021-07-06 15:01:35 +0100 | [diff] [blame] | 1054 | const auto src_info = TensorInfo(TensorShape(1U, 5U, 2U), 1, DataType::F32, DataLayout::NCHW); |
| 1055 | const auto weight_info = TensorInfo(TensorShape(1U, 3U, 2U, 3U), 1, DataType::F32, DataLayout::NCHW); |
| 1056 | const auto bias_info = TensorInfo(TensorShape(3U), 1, DataType::F32, DataLayout::NCHW); |
| 1057 | auto dst_info = TensorInfo(TensorShape(1U, 7U, 3U), 1, DataType::F32, DataLayout::NCHW); |
| 1058 | const auto conv_info = PadStrideInfo(1, 1, 0, 0, 2, 2, DimensionRoundingType::FLOOR); |
| 1059 | WeightsInfo weights_info(false, 3U, 3U, 1U); |
| 1060 | conv->configure(&src_info, &weight_info, &bias_info, &dst_info, conv_info, weights_info); |
| 1061 | |
| 1062 | // tensors are newly created every call of this lambda function |
| 1063 | auto src = create_tensor<Tensor>(src_info); |
| 1064 | auto weight = create_tensor<Tensor>(weight_info); |
| 1065 | auto bias = create_tensor<Tensor>(bias_info); |
| 1066 | src.allocator()->allocate(); |
| 1067 | weight.allocator()->allocate(); |
| 1068 | bias.allocator()->allocate(); |
| 1069 | |
| 1070 | ITensorPack run_pack{ { TensorType::ACL_SRC_0, &src }, { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } }; |
| 1071 | ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } }; |
| 1072 | |
| 1073 | auto mg = MemoryGroup{}; |
| 1074 | auto ws = manage_workspace<Tensor>(conv->workspace(), mg, run_pack, prep_pack); |
| 1075 | |
| 1076 | auto run_conv = [&]() -> Tensor |
| 1077 | { |
| 1078 | auto dst = create_tensor<Tensor>(dst_info); |
| 1079 | dst.allocator()->allocate(); |
| 1080 | run_pack.add_tensor(TensorType::ACL_DST, &dst); |
| 1081 | |
| 1082 | library->fill_tensor_value(Accessor(src), 1.f); |
| 1083 | library->fill_tensor_value(Accessor(weight), 2.f); |
| 1084 | library->fill_tensor_value(Accessor(bias), 3.f); |
| 1085 | // This operator is configured once and captured by this lambda. |
| 1086 | conv->prepare(prep_pack); |
| 1087 | conv->run(run_pack); |
| 1088 | return dst; |
| 1089 | }; |
| 1090 | auto result_0 = run_conv(); |
| 1091 | auto result_1 = run_conv(); |
| 1092 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 1093 | { |
| 1094 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | /** Test case for memory injection in @ref NEGEMMConvolutionLayer. |
| 1099 | * |
| 1100 | * Make sure @ref NEGEMMConvolutionLayer still works through injecting the memory at configure time using the old API. |
| 1101 | * |
| 1102 | * Checks performed in order: |
| 1103 | * - Both runs compute the same output |
| 1104 | */ |
| 1105 | TEST_CASE(MultipleExecutionWithConfigure, framework::DatasetMode::ALL) |
| 1106 | { |
| 1107 | auto conv = std::make_unique<NEGEMMConvolutionLayer>(); |
| 1108 | const auto src_info = TensorInfo(TensorShape(1U, 5U, 2U), 1, DataType::F32, DataLayout::NCHW); |
| 1109 | const auto weight_info = TensorInfo(TensorShape(1U, 3U, 2U, 3U), 1, DataType::F32, DataLayout::NCHW); |
| 1110 | const auto bias_info = TensorInfo(TensorShape(3U), 1, DataType::F32, DataLayout::NCHW); |
| 1111 | auto dst_info = TensorInfo(TensorShape(1U, 7U, 3U), 1, DataType::F32, DataLayout::NCHW); |
| 1112 | const auto conv_info = PadStrideInfo(1, 1, 0, 0, 2, 2, DimensionRoundingType::FLOOR); |
| 1113 | WeightsInfo weights_info(false, 3U, 3U, 1U); |
| 1114 | auto run_conv = [&]() |
| 1115 | { |
| 1116 | auto src = create_tensor<Tensor>(src_info); |
| 1117 | auto weight = create_tensor<Tensor>(weight_info); |
| 1118 | auto bias = create_tensor<Tensor>(bias_info); |
| 1119 | auto dst = create_tensor<Tensor>(dst_info); |
| 1120 | conv->configure(&src, &weight, &bias, &dst, conv_info, weights_info); |
| 1121 | src.allocator()->allocate(); |
| 1122 | weight.allocator()->allocate(); |
| 1123 | bias.allocator()->allocate(); |
| 1124 | dst.allocator()->allocate(); |
| 1125 | library->fill_tensor_value(Accessor(src), 1.f); |
| 1126 | library->fill_tensor_value(Accessor(weight), 2.f); |
| 1127 | library->fill_tensor_value(Accessor(bias), 3.f); |
| 1128 | conv->run(); |
| 1129 | return dst; |
| 1130 | }; |
| 1131 | auto result_0 = run_conv(); |
| 1132 | auto result_1 = run_conv(); |
| 1133 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 1134 | { |
| 1135 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 1136 | } |
| 1137 | } |
| 1138 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1139 | TEST_SUITE(Float) |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 1140 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 1141 | TEST_SUITE(BFLOAT16) |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1142 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1143 | framework::dataset::make("ReshapeWeights", { true })), |
| 1144 | framework::dataset::make("DataType", DataType::BFLOAT16)), |
| 1145 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1146 | ActivationFunctionsDataset)) |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 1147 | { |
| 1148 | // Validate output |
| 1149 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1150 | } |
| 1151 | TEST_SUITE_END() // BFLOAT16 |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 1152 | #endif /* defined(ARM_COMPUTE_ENABLE_BF16) */ |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 1153 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 1154 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1155 | TEST_SUITE(FP16) |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1156 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1157 | framework::dataset::make("ReshapeWeights", { true })), |
| 1158 | framework::dataset::make("DataType", DataType::F16)), |
| 1159 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
| 1160 | ActivationFunctionsDataset)) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1161 | { |
| 1162 | // Validate output |
Gian Marco Iodice | 41acb76 | 2018-08-23 10:25:06 +0100 | [diff] [blame] | 1163 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1164 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 1165 | TEST_SUITE_END() // FP16 |
| 1166 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1167 | |
| 1168 | TEST_SUITE(FP32) |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1169 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1170 | framework::dataset::make("ReshapeWeights", { true })), |
| 1171 | framework::dataset::make("DataType", DataType::F32)), |
| 1172 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1173 | ActivationFunctionsDataset)) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1174 | { |
| 1175 | // Validate output |
Georgios Pinitas | 8dea602 | 2018-06-08 18:33:31 +0100 | [diff] [blame] | 1176 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1177 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1178 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEGEMMConvolutionLayerMixedDataLayoutFixture<float>, framework::DatasetMode::ALL, |
Sang-Hoon Park | b3be457 | 2021-05-18 10:46:00 +0100 | [diff] [blame] | 1179 | combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 1180 | framework::dataset::make("Input", TensorShape(23U, 27U, 5U)), |
| 1181 | framework::dataset::make("Weights", TensorShape(3U, 3U, 5U, 2U))), |
| 1182 | framework::dataset::make("Bias", TensorShape(2U))), |
| 1183 | framework::dataset::make("Output", TensorShape(11U, 25U, 2U))), |
| 1184 | framework::dataset::make("PadStrideInfo", PadStrideInfo(2, 1, 0, 0))), |
| 1185 | framework::dataset::make("Dilation", Size2D(1, 1))), |
| 1186 | framework::dataset::make("ReshapeWeights", { true })), |
| 1187 | framework::dataset::make("DataType", DataType::F32)), |
| 1188 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 1189 | ActivationFunctionsDataset)) |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1190 | { |
| 1191 | // Validate output |
| 1192 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1193 | } |
SiCong Li | c5ab4df | 2023-10-17 17:38:57 +0100 | [diff] [blame] | 1194 | /** Padded weights |
| 1195 | * CpuGemmConv2d uses two different paths for reshaping the weights based on if the weight tensor has holes (a common |
| 1196 | * way to have "holes" in tensor is via extended paddings) |
| 1197 | * |
| 1198 | * We only need to test the padded weight path here on a single floating data type and a single layout, because the fallback path is agnostic of them |
| 1199 | */ |
| 1200 | FIXTURE_DATA_TEST_CASE(RunPaddedWeights, NEGEMMConvolutionLayerPaddedWeightsFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallConvolutionLayerDataset(), |
| 1201 | framework::dataset::make("ReshapeWeights", { true }), |
| 1202 | framework::dataset::make("DataType", DataType::F32), |
| 1203 | framework::dataset::make("DataLayout", { DataLayout::NHWC }) |
| 1204 | )) |
| 1205 | { |
| 1206 | // Validate output |
| 1207 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1208 | } |
Gunes Bayir | 9167c9c | 2024-03-06 09:58:40 +0000 | [diff] [blame] | 1209 | |
| 1210 | // This very large shape test is required to test heuristic paths where the tensor size is > 1e7 bytes |
| 1211 | // and weight dimensions larger than 7 |
| 1212 | FIXTURE_DATA_TEST_CASE(RunVeryLarge, NEGEMMConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, |
| 1213 | combine(datasets::VeryLargeConvolutionLayerDataset(), |
| 1214 | framework::dataset::make("ReshapeWeights", { true }), |
| 1215 | framework::dataset::make("DataType", DataType::F32), |
| 1216 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }), |
| 1217 | NoActivation)) |
| 1218 | { |
| 1219 | // Validate output |
| 1220 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1221 | } |
| 1222 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 1223 | TEST_SUITE_END() // FP32 |
| 1224 | TEST_SUITE_END() // Float |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1225 | |
SiCong Li | c5ab4df | 2023-10-17 17:38:57 +0100 | [diff] [blame] | 1226 | // TODO: COMPMID-6596 Extend quantized tests with at least one suite where the weight is padded (the legacy case, see floating point's RunPaddedWeights) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1227 | template <typename T> |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1228 | using NEGEMMConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1229 | template <typename T> |
| 1230 | using NEGEMMConvolutionLayerQuantizedMixedDataLayoutFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEConvolutionLayer, T, true>; |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 1231 | |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 1232 | template <typename T> |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1233 | using NEGEMMConvolutionLayerQuantizedPerChannelFixture = ConvolutionValidationQuantizedPerChannelFixture<Tensor, Accessor, NEConvolutionLayer, T, int8_t>; |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 1234 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 1235 | const auto QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 1236 | { |
| 1237 | ActivationLayerInfo(), |
| 1238 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 1239 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f) |
| 1240 | }); |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 1241 | TEST_SUITE(Quantized) |
Gunes Bayir | 93a77cd | 2023-10-13 16:58:41 +0100 | [diff] [blame] | 1242 | /// @note: Every asymmetric quantized test where there's no fused activation will have its quantization info ignored |
| 1243 | /// This is because instead of using the same quantization information for all the tensors, the fixture generates |
| 1244 | /// separate quantization info for each input and the output tensor. |
| 1245 | /// When we can also support dynamic quantization with the presence of activation, these two versions should be merged |
| 1246 | /// again, with the explicitly specified quantization info removed |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 1247 | TEST_SUITE(QASYMM8) |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1248 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1249 | framework::dataset::make("ReshapeWeights", { true })), |
| 1250 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 1251 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Gunes Bayir | 93a77cd | 2023-10-13 16:58:41 +0100 | [diff] [blame] | 1252 | framework::dataset::make("QuantizationInfoIfActivationEnabled", { QuantizationInfo(2.f / 255.f, 10) })), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1253 | QuantizedActivationFunctionsDataset)) |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 1254 | { |
| 1255 | // Validate output |
| 1256 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1257 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1258 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEGEMMConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, |
Sang-Hoon Park | b3be457 | 2021-05-18 10:46:00 +0100 | [diff] [blame] | 1259 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 1260 | framework::dataset::make("Input", TensorShape(23U, 27U, 5U)), |
| 1261 | framework::dataset::make("Weights", TensorShape(3U, 3U, 5U, 2U))), |
| 1262 | framework::dataset::make("Bias", TensorShape(2U))), |
| 1263 | framework::dataset::make("Output", TensorShape(11U, 25U, 2U))), |
| 1264 | framework::dataset::make("PadStrideInfo", PadStrideInfo(2, 1, 0, 0))), |
| 1265 | framework::dataset::make("Dilation", Size2D(1, 1))), |
| 1266 | framework::dataset::make("ReshapeWeights", { true })), |
| 1267 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 1268 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Gunes Bayir | 93a77cd | 2023-10-13 16:58:41 +0100 | [diff] [blame] | 1269 | framework::dataset::make("QuantizationInfoIfActivationEnabled", { QuantizationInfo(2.f / 255.f, 10) })), |
Sang-Hoon Park | b3be457 | 2021-05-18 10:46:00 +0100 | [diff] [blame] | 1270 | QuantizedActivationFunctionsDataset)) |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1271 | { |
| 1272 | // Validate output |
| 1273 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1274 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 1275 | TEST_SUITE_END() // QASYMM8 |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 1276 | |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 1277 | TEST_SUITE(QASYMM8_SIGNED) |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1278 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMConvolutionLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1279 | framework::dataset::make("ReshapeWeights", { true })), |
| 1280 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 1281 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Gunes Bayir | 93a77cd | 2023-10-13 16:58:41 +0100 | [diff] [blame] | 1282 | framework::dataset::make("QuantizationInfoIfActivationEnabled", { QuantizationInfo(0.01f, -10) })), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1283 | QuantizedActivationFunctionsDataset)) |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 1284 | { |
| 1285 | // Validate output |
| 1286 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1287 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1288 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEGEMMConvolutionLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, |
Sang-Hoon Park | b3be457 | 2021-05-18 10:46:00 +0100 | [diff] [blame] | 1289 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 1290 | framework::dataset::make("Input", TensorShape(23U, 27U, 5U)), |
| 1291 | framework::dataset::make("Weights", TensorShape(3U, 3U, 5U, 2U))), |
| 1292 | framework::dataset::make("Bias", TensorShape(2U))), |
| 1293 | framework::dataset::make("Output", TensorShape(11U, 25U, 2U))), |
| 1294 | framework::dataset::make("PadStrideInfo", PadStrideInfo(2, 1, 0, 0))), |
| 1295 | framework::dataset::make("Dilation", Size2D(1, 1))), |
| 1296 | framework::dataset::make("ReshapeWeights", { true })), |
| 1297 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 1298 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Gunes Bayir | 93a77cd | 2023-10-13 16:58:41 +0100 | [diff] [blame] | 1299 | framework::dataset::make("QuantizationInfoIfActivationEnabled", { QuantizationInfo(2.f / 255.f, 10) })), |
Sang-Hoon Park | b3be457 | 2021-05-18 10:46:00 +0100 | [diff] [blame] | 1300 | QuantizedActivationFunctionsDataset)) |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 1301 | { |
| 1302 | // Validate output |
| 1303 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1304 | } |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 1305 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 1306 | |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 1307 | TEST_SUITE(QSYMM8_PER_CHANNEL) |
Michele Di Giorgio | e37662a | 2020-04-29 15:14:18 +0100 | [diff] [blame] | 1308 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMConvolutionLayerQuantizedPerChannelFixture<uint8_t>, framework::DatasetMode::ALL, |
Georgios Pinitas | 63d4dbd | 2019-11-08 11:51:56 +0000 | [diff] [blame] | 1309 | combine(combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 1310 | framework::dataset::make("ReshapeWeights", { true })), |
| 1311 | framework::dataset::make("DataType", { DataType::QASYMM8 })), |
| 1312 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 1313 | QuantizationData), |
| 1314 | QuantizedActivationFunctionsDataset), |
| 1315 | framework::dataset::make("WeightsDataType", { DataType::QSYMM8_PER_CHANNEL }))) |
| 1316 | { |
| 1317 | // Validate output |
| 1318 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1319 | } |
Sang-Hoon Park | 1fad814 | 2020-07-03 13:07:35 +0100 | [diff] [blame] | 1320 | FIXTURE_DATA_TEST_CASE(RunSmallSigned, NEGEMMConvolutionLayerQuantizedPerChannelFixture<int8_t>, framework::DatasetMode::ALL, |
| 1321 | combine(combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 1322 | framework::dataset::make("ReshapeWeights", { true })), |
| 1323 | framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })), |
| 1324 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 1325 | QuantizationData), |
| 1326 | QuantizedActivationFunctionsDataset), |
| 1327 | framework::dataset::make("WeightsDataType", { DataType::QSYMM8_PER_CHANNEL }))) |
| 1328 | { |
| 1329 | // Validate output |
| 1330 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1331 | } |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 1332 | TEST_SUITE_END() // QSYMM8_PER_CHANNEL |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 1333 | TEST_SUITE_END() // Quantized |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 1334 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 1335 | TEST_SUITE_END() // GEMMConvolutionLayer |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1336 | |
| 1337 | TEST_SUITE(DirectGEMMConv2d) |
| 1338 | template <typename T> |
| 1339 | using NEDirectGEMMConv2dLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEGEMMConv2d, T>; |
| 1340 | |
Michele Di Giorgio | d7316eb | 2021-06-16 11:14:41 +0100 | [diff] [blame] | 1341 | /** Test case for memory injection in @ref cpu::CpuGemmDirectConv2d. |
| 1342 | * |
| 1343 | * Configure the operator once and inject memory at run-time in multiple executions. |
| 1344 | * |
| 1345 | * Checks performed in order: |
| 1346 | * - Both runs compute the same output |
| 1347 | */ |
| 1348 | TEST_CASE(MemoryInjection, framework::DatasetMode::ALL) |
| 1349 | { |
| 1350 | auto conv = std::make_unique<cpu::CpuGemmDirectConv2d>(); |
| 1351 | const auto src_info = TensorInfo(TensorShape(1U, 5U, 2U), 1, DataType::F32, DataLayout::NHWC); |
| 1352 | const auto weight_info = TensorInfo(TensorShape(1U, 3U, 2U, 3U), 1, DataType::F32, DataLayout::NHWC); |
| 1353 | const auto bias_info = TensorInfo(TensorShape(3U), 1, DataType::F32, DataLayout::NHWC); |
| 1354 | auto dst_info = TensorInfo(TensorShape(1U, 7U, 3U), 1, DataType::F32, DataLayout::NHWC); |
| 1355 | const auto conv_info = Conv2dInfo{}; |
| 1356 | conv->configure(&src_info, &weight_info, &bias_info, &dst_info, conv_info); |
| 1357 | |
| 1358 | // tensors are newly created every call of this lambda function |
| 1359 | auto src = create_tensor<Tensor>(src_info); |
| 1360 | auto weight = create_tensor<Tensor>(weight_info); |
| 1361 | auto bias = create_tensor<Tensor>(bias_info); |
| 1362 | src.allocator()->allocate(); |
| 1363 | weight.allocator()->allocate(); |
| 1364 | bias.allocator()->allocate(); |
| 1365 | |
| 1366 | ITensorPack run_pack{ { TensorType::ACL_SRC_0, &src }, { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } }; |
| 1367 | ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } }; |
| 1368 | |
| 1369 | auto mg = MemoryGroup{}; |
| 1370 | auto ws = manage_workspace<Tensor>(conv->workspace(), mg, run_pack, prep_pack); |
| 1371 | |
| 1372 | auto run_conv = [&]() -> Tensor |
| 1373 | { |
| 1374 | auto dst = create_tensor<Tensor>(dst_info); |
| 1375 | dst.allocator()->allocate(); |
| 1376 | run_pack.add_tensor(TensorType::ACL_DST, &dst); |
| 1377 | |
| 1378 | library->fill_tensor_value(Accessor(src), 1.f); |
| 1379 | library->fill_tensor_value(Accessor(weight), 2.f); |
| 1380 | library->fill_tensor_value(Accessor(bias), 3.f); |
| 1381 | // This operator is configured once and captured by this lambda. |
| 1382 | conv->prepare(prep_pack); |
| 1383 | conv->run(run_pack); |
| 1384 | return dst; |
| 1385 | }; |
| 1386 | auto result_0 = run_conv(); |
| 1387 | auto result_1 = run_conv(); |
| 1388 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 1389 | { |
| 1390 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | /** Test case for memory injection in @ref NEGEMMConv2d. |
| 1395 | * |
| 1396 | * Make sure @ref NEGEMMConv2d still works through injecting the memory at configure time using the old API. |
| 1397 | * |
| 1398 | * Checks performed in order: |
| 1399 | * - Both runs compute the same output |
| 1400 | */ |
| 1401 | TEST_CASE(MultipleExecutionWithConfigure, framework::DatasetMode::ALL) |
| 1402 | { |
| 1403 | auto conv = std::make_unique<NEGEMMConv2d>(); |
| 1404 | const auto src_info = TensorInfo(TensorShape(1U, 5U, 2U), 1, DataType::F32, DataLayout::NHWC); |
| 1405 | const auto weight_info = TensorInfo(TensorShape(1U, 3U, 2U, 3U), 1, DataType::F32, DataLayout::NHWC); |
| 1406 | const auto bias_info = TensorInfo(TensorShape(3U), 1, DataType::F32, DataLayout::NHWC); |
| 1407 | auto dst_info = TensorInfo(TensorShape(1U, 7U, 3U), 1, DataType::F32, DataLayout::NHWC); |
| 1408 | const auto conv_info = Conv2dInfo{}; |
| 1409 | auto run_conv = [&]() |
| 1410 | { |
| 1411 | auto src = create_tensor<Tensor>(src_info); |
| 1412 | auto weight = create_tensor<Tensor>(weight_info); |
| 1413 | auto bias = create_tensor<Tensor>(bias_info); |
| 1414 | auto dst = create_tensor<Tensor>(dst_info); |
| 1415 | conv->configure(&src, &weight, &bias, &dst, conv_info); |
| 1416 | src.allocator()->allocate(); |
| 1417 | weight.allocator()->allocate(); |
| 1418 | bias.allocator()->allocate(); |
| 1419 | dst.allocator()->allocate(); |
| 1420 | library->fill_tensor_value(Accessor(src), 1.f); |
| 1421 | library->fill_tensor_value(Accessor(weight), 2.f); |
| 1422 | library->fill_tensor_value(Accessor(bias), 3.f); |
| 1423 | conv->run(); |
| 1424 | return dst; |
| 1425 | }; |
| 1426 | auto result_0 = run_conv(); |
| 1427 | auto result_1 = run_conv(); |
| 1428 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 1429 | { |
| 1430 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 1431 | } |
| 1432 | } |
| 1433 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1434 | TEST_SUITE(Float) |
| 1435 | TEST_SUITE(FP32) |
| 1436 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectGEMMConv2dLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1437 | framework::dataset::make("ReshapeWeights", { true })), |
| 1438 | framework::dataset::make("DataType", DataType::F32)), |
| 1439 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1440 | ActivationFunctionsDataset)) |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1441 | { |
| 1442 | // Validate output |
| 1443 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, float(abs_tolerance_f32)); |
| 1444 | } |
| 1445 | TEST_SUITE_END() // FP32 |
| 1446 | TEST_SUITE_END() // Float |
| 1447 | |
Georgios Pinitas | 61ffda4 | 2020-11-13 14:03:07 +0000 | [diff] [blame] | 1448 | #ifdef __aarch64__ |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1449 | template <typename T> |
| 1450 | using NEDirectGEMMConv2dLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConv2d, T>; |
| 1451 | |
| 1452 | template <typename T> |
| 1453 | using NEDirectGEMMConv2dLayerQuantizedPerChannelFixture = ConvolutionValidationQuantizedPerChannelFixture<Tensor, Accessor, NEGEMMConv2d, T, int8_t>; |
| 1454 | |
| 1455 | const auto QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 1456 | { |
| 1457 | ActivationLayerInfo(), |
| 1458 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 1459 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f) |
| 1460 | }); |
| 1461 | TEST_SUITE(Quantized) |
| 1462 | TEST_SUITE(QASYMM8) |
| 1463 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectGEMMConv2dLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1464 | framework::dataset::make("ReshapeWeights", { true })), |
| 1465 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 1466 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1467 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 1468 | QuantizedActivationFunctionsDataset)) |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1469 | { |
| 1470 | // Validate output |
| 1471 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1472 | } |
| 1473 | TEST_SUITE_END() // QASYMM8 |
| 1474 | |
| 1475 | TEST_SUITE(QASYMM8_SIGNED) |
| 1476 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectGEMMConv2dLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gunes Bayir | c2a51bd | 2023-09-28 10:30:18 +0100 | [diff] [blame] | 1477 | framework::dataset::make("ReshapeWeights", { true })), |
| 1478 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 1479 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1480 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.01f, -10) })), |
| 1481 | QuantizedActivationFunctionsDataset)) |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1482 | { |
| 1483 | // Validate output |
| 1484 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1485 | } |
| 1486 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 1487 | |
| 1488 | TEST_SUITE(QSYMM8_PER_CHANNEL) |
| 1489 | FIXTURE_DATA_TEST_CASE(RunSmallSigned, NEDirectGEMMConv2dLayerQuantizedPerChannelFixture<int8_t>, framework::DatasetMode::ALL, |
| 1490 | combine(combine(combine(combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 1491 | framework::dataset::make("ReshapeWeights", { true })), |
| 1492 | framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })), |
| 1493 | framework::dataset::make("DataLayout", { DataLayout::NHWC })), |
| 1494 | QuantizationData), |
| 1495 | QuantizedActivationFunctionsDataset), |
| 1496 | framework::dataset::make("WeightsDataType", { DataType::QSYMM8_PER_CHANNEL }))) |
| 1497 | { |
| 1498 | // Validate output |
| 1499 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 1500 | } |
| 1501 | TEST_SUITE_END() // QSYMM8_PER_CHANNEL |
| 1502 | TEST_SUITE_END() // Quantized |
Georgios Pinitas | 61ffda4 | 2020-11-13 14:03:07 +0000 | [diff] [blame] | 1503 | #endif // __aarch64__ |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 1504 | |
| 1505 | TEST_SUITE_END() // DirectGEMMConv2d |
| 1506 | |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 1507 | TEST_SUITE_END() // Neon |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1508 | } // namespace validation |
| 1509 | } // namespace test |
| 1510 | } // namespace arm_compute |