Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 1 | /* |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" |
| 26 | #include "arm_compute/runtime/NEON/functions/NEGEMMConvolutionLayer.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 29 | #include "src/cpu/operators/CpuConv2d.h" |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 30 | #include "tests/NEON/Accessor.h" |
| 31 | #include "tests/PaddingCalculator.h" |
| 32 | #include "tests/datasets/DilatedConvolutionLayerDataset.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/framework/datasets/Datasets.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 48 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Gian Marco Iodice | 35aea37 | 2018-08-24 14:30:36 +0100 | [diff] [blame] | 49 | const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 50 | const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 51 | constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */ |
| 52 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 53 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 54 | |
| 55 | /** CNN data types */ |
| 56 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 57 | { |
| 58 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 59 | DataType::F16, |
| 60 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 61 | DataType::F32, |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 62 | DataType::QASYMM8, |
| 63 | }); |
| 64 | } // namespace |
| 65 | |
| 66 | TEST_SUITE(NEON) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 67 | TEST_SUITE(DilatedConvolutionLayer) |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 68 | |
| 69 | // *INDENT-OFF* |
| 70 | // clang-format off |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 71 | DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 72 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(8U, 8U, 2U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32), |
| 74 | TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32) |
| 76 | }), |
| 77 | framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32), |
| 78 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32), |
| 79 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32), |
| 80 | TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16) |
| 81 | })), |
| 82 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(6U, 6U, 1U), 1, DataType::F32), |
| 83 | TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32), |
| 84 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 85 | TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32) |
| 86 | })), |
| 87 | framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0), |
| 88 | PadStrideInfo(1, 1, 0, 0), |
| 89 | PadStrideInfo(2, 1, 0, 0), |
| 90 | PadStrideInfo(3, 2, 1, 0) |
| 91 | })), |
| 92 | framework::dataset::make("Dilation", { Size2D(1U, 2U), |
| 93 | Size2D(2U, 1U), |
| 94 | Size2D(2U, 2U), |
| 95 | Size2D(3U, 3U) |
| 96 | })), |
| 97 | framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })), |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 98 | input_info, weights_info, output_info, conv_info, dilation, expected) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 99 | { |
Michalis Spyrou | b55f8e8 | 2021-07-22 11:23:11 +0100 | [diff] [blame] | 100 | ConvolutionMethod is_valid = cpu::CpuConv2d::get_convolution_method(&input_info.clone()->set_is_resizable(false), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 101 | &weights_info.clone()->set_is_resizable(false), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 102 | &output_info.clone()->set_is_resizable(false), |
| 103 | conv_info, WeightsInfo(), dilation); |
| 104 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 105 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 106 | // clang-format on |
| 107 | // *INDENT-ON* |
| 108 | TEST_SUITE_END() // DilatedConvolutionLayer |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 109 | |
| 110 | TEST_SUITE(GEMMDilatedConvolutionLayer) |
| 111 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 112 | template <typename T> |
| 113 | using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
| 114 | |
| 115 | TEST_SUITE(Float) |
| 116 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 117 | TEST_SUITE(FP16) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 118 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 119 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 120 | framework::dataset::make("DataType", DataType::F16)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 121 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 122 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 123 | { |
| 124 | // Validate output |
Gian Marco Iodice | 35aea37 | 2018-08-24 14:30:36 +0100 | [diff] [blame] | 125 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 126 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 127 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 128 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 129 | framework::dataset::make("DataType", DataType::F16)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 130 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 131 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 132 | { |
| 133 | // Validate output |
Gian Marco Iodice | 35aea37 | 2018-08-24 14:30:36 +0100 | [diff] [blame] | 134 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 135 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 136 | TEST_SUITE_END() // FP16 |
| 137 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 138 | |
| 139 | TEST_SUITE(FP32) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 140 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 141 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 142 | framework::dataset::make("DataType", DataType::F32)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 143 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 144 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 145 | { |
| 146 | // Validate output |
| 147 | validate(Accessor(_target), _reference, tolerance_f32); |
| 148 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 149 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 150 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 151 | framework::dataset::make("DataType", DataType::F32)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 152 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 153 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 154 | { |
| 155 | // Validate output |
| 156 | validate(Accessor(_target), _reference, tolerance_f32); |
| 157 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 158 | TEST_SUITE_END() // FP32 |
| 159 | TEST_SUITE_END() // Float |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 160 | |
| 161 | template <typename T> |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 162 | using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>; |
| 163 | |
| 164 | TEST_SUITE(Quantized) |
| 165 | TEST_SUITE(QASYMM8) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 166 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 167 | combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 168 | framework::dataset::make("ReshapeWeights", { true })), |
| 169 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 170 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 171 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 172 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 173 | { |
| 174 | // Validate output |
| 175 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 176 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 177 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 178 | combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 179 | framework::dataset::make("ReshapeWeights", { true })), |
| 180 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 181 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 182 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 183 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 184 | { |
| 185 | // Validate output |
| 186 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 187 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 188 | TEST_SUITE_END() // QASYMM8 |
| 189 | TEST_SUITE_END() // Quantized |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 190 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 191 | TEST_SUITE_END() // GEMMDilatedConvolutionLayer |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 192 | TEST_SUITE_END() // Neon |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 193 | } // namespace validation |
| 194 | } // namespace test |
| 195 | } // namespace arm_compute |