Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +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/NEPoolingLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/datasets/PoolingTypesDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/PoolingLayerFixture.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | /** Input data set for float data types */ |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame^] | 47 | const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(7, 7), Size2D(9, 9) })), |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 48 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })), |
| 49 | framework::dataset::make("ExcludePadding", { true, false })); |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 50 | |
| 51 | /** Input data set for quantized data types */ |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame^] | 52 | const auto PoolingLayerDatasetQS = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })), |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 53 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })), |
| 54 | framework::dataset::make("ExcludePadding", { false })); |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 55 | |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 56 | /** Input data set for asymmetric data type */ |
Isabella Gottardi | 6e464c3 | 2018-01-26 12:32:45 +0000 | [diff] [blame^] | 57 | const auto PoolingLayerDatasetQASYMM8 = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(9, 9) })), |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 58 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })), |
| 59 | framework::dataset::make("ExcludePadding", { true, false })); |
| 60 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 61 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 62 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 63 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
| 64 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 65 | constexpr AbsoluteTolerance<float> tolerance_qs8(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ |
| 66 | constexpr AbsoluteTolerance<float> tolerance_qs16(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ |
| 67 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */ |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 68 | } // namespace |
| 69 | |
| 70 | TEST_SUITE(NEON) |
| 71 | TEST_SUITE(PoolingLayer) |
| 72 | |
| 73 | //TODO(COMPMID-415): Configuration tests? |
| 74 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 75 | // *INDENT-OFF* |
| 76 | // clang-format off |
| 77 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 78 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type |
| 79 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink |
| 80 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Mismatching fixed point position |
| 81 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11), // Window shrink |
| 82 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination |
| 83 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination |
| 84 | TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling |
| 85 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling |
| 86 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), |
| 87 | }), |
| 88 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0), |
| 89 | TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32, 0), |
| 90 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5), |
| 91 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11), |
| 92 | TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0), |
| 93 | TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0), |
| 94 | TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0), |
| 95 | TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0), |
| 96 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0), |
| 97 | })), |
| 98 | framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 99 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 100 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 101 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 102 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)), |
| 103 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)), |
| 104 | PoolingLayerInfo(PoolingType::AVG), |
| 105 | PoolingLayerInfo(PoolingType::MAX), |
| 106 | PoolingLayerInfo(PoolingType::AVG), |
| 107 | })), |
| 108 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, true })), |
| 109 | input_info, output_info, pool_info, expected) |
| 110 | { |
| 111 | bool is_valid = bool(NEPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info)); |
| 112 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 113 | } |
| 114 | // clang-format on |
| 115 | // *INDENT-ON* |
| 116 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 117 | template <typename T> |
| 118 | using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 119 | |
| 120 | TEST_SUITE(Float) |
| 121 | TEST_SUITE(FP32) |
| 122 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 123 | DataType::F32)))) |
| 124 | { |
| 125 | // Validate output |
| 126 | validate(Accessor(_target), _reference, tolerance_f32); |
| 127 | } |
| 128 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 129 | DataType::F32)))) |
| 130 | { |
| 131 | // Validate output |
| 132 | validate(Accessor(_target), _reference, tolerance_f32); |
| 133 | } |
| 134 | TEST_SUITE_END() |
| 135 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 136 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 137 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 138 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, |
| 139 | framework::dataset::make("DataType", DataType::F16)))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 140 | { |
| 141 | // Validate output |
| 142 | validate(Accessor(_target), _reference, tolerance_f16); |
| 143 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 144 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, |
| 145 | framework::dataset::make("DataType", DataType::F16)))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 146 | { |
| 147 | // Validate output |
| 148 | validate(Accessor(_target), _reference, tolerance_f16); |
| 149 | } |
| 150 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 151 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 152 | TEST_SUITE_END() |
| 153 | |
| 154 | template <typename T> |
| 155 | using NEPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 156 | |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 157 | TEST_SUITE(FixedPoint) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 158 | TEST_SUITE(QS8) |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 159 | FIXTURE_DATA_TEST_CASE(RunTiny, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS, |
| 160 | framework::dataset::make("DataType", DataType::QS8))), |
| 161 | framework::dataset::make("FractionalBits", 1, 5))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 162 | { |
| 163 | // Validate output |
| 164 | validate(Accessor(_target), _reference, tolerance_qs8); |
| 165 | } |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 166 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 167 | framework::dataset::make("DataType", DataType::QS8))), |
| 168 | framework::dataset::make("FractionalBits", 1, 5))) |
| 169 | { |
| 170 | // Validate output |
| 171 | validate(Accessor(_target), _reference, tolerance_qs8); |
| 172 | } |
| 173 | TEST_SUITE_END() |
| 174 | |
| 175 | TEST_SUITE(QS16) |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 176 | FIXTURE_DATA_TEST_CASE(RunTiny, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS, |
| 177 | framework::dataset::make("DataType", DataType::QS16))), |
| 178 | framework::dataset::make("FractionalBits", 1, 13))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 179 | { |
| 180 | // Validate output |
| 181 | validate(Accessor(_target), _reference, tolerance_qs16); |
| 182 | } |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 183 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 184 | framework::dataset::make("DataType", DataType::QS16))), |
| 185 | framework::dataset::make("FractionalBits", 1, 13))) |
| 186 | { |
| 187 | // Validate output |
| 188 | validate(Accessor(_target), _reference, tolerance_qs16); |
| 189 | } |
| 190 | TEST_SUITE_END() |
| 191 | TEST_SUITE_END() |
| 192 | |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 193 | TEST_SUITE(Quantized) |
| 194 | |
| 195 | template <typename T> |
| 196 | using NEPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 197 | |
| 198 | TEST_SUITE(QASYMM8) |
| 199 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8, |
| 200 | framework::dataset::make("DataType", DataType::QASYMM8))), |
| 201 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127), |
| 202 | QuantizationInfo(7.f / 255, 123) |
| 203 | }))) |
| 204 | { |
| 205 | // Validate output |
| 206 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 207 | } |
| 208 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, |
| 209 | framework::dataset::make("DataType", DataType::QASYMM8))), |
| 210 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) }))) |
| 211 | { |
| 212 | // Validate output |
| 213 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 214 | } |
| 215 | TEST_SUITE_END() |
| 216 | TEST_SUITE_END() |
| 217 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 218 | TEST_SUITE_END() |
| 219 | TEST_SUITE_END() |
| 220 | } // namespace validation |
| 221 | } // namespace test |
| 222 | } // namespace arm_compute |