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" |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 30 | #include "tests/datasets/PoolingLayerDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/datasets/PoolingTypesDataset.h" |
| 32 | #include "tests/datasets/ShapeDatasets.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/PoolingLayerFixture.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | /** Input data set for float data types */ |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 48 | |
| 49 | const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(7, 7), Size2D(9, 9), Size2D(4, 4), Size2D(3, 7), Size2D(7, 8) })), |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 50 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })), |
| 51 | framework::dataset::make("ExcludePadding", { true, false })); |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 52 | |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 53 | /** Input data set for asymmetric data type */ |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 54 | |
| 55 | 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(4, 4), Size2D(9, 9), Size2D(3, 7), Size2D(7, 8) })), |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 56 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })), |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 57 | framework::dataset::make("ExcludePadding", { true })); |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 58 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 59 | 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] | 60 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 61 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
| 62 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 63 | 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] | 64 | } // namespace |
| 65 | |
| 66 | TEST_SUITE(NEON) |
| 67 | TEST_SUITE(PoolingLayer) |
| 68 | |
| 69 | //TODO(COMPMID-415): Configuration tests? |
| 70 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 71 | // *INDENT-OFF* |
| 72 | // clang-format off |
| 73 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame^] | 74 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type |
| 75 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink |
| 76 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination |
| 77 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination |
| 78 | TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32), // Non-rectangular Global Pooling |
| 79 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), // Invalid output Global Pooling |
| 80 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 81 | }), |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame^] | 82 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16), |
| 83 | TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32), |
| 84 | TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), |
| 85 | TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32), |
| 86 | TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32), |
| 87 | TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32), |
| 88 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 89 | })), |
| 90 | framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 91 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 92 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)), |
| 93 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)), |
| 94 | PoolingLayerInfo(PoolingType::AVG), |
| 95 | PoolingLayerInfo(PoolingType::MAX), |
| 96 | PoolingLayerInfo(PoolingType::AVG), |
| 97 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 98 | framework::dataset::make("Expected", { false, false, false, false, true, false, false, true })), |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 99 | input_info, output_info, pool_info, expected) |
| 100 | { |
| 101 | bool is_valid = bool(NEPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info)); |
| 102 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 103 | } |
| 104 | // clang-format on |
| 105 | // *INDENT-ON* |
| 106 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 107 | template <typename T> |
| 108 | using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 109 | |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 110 | template <typename T> |
| 111 | using NESpecialPoolingLayerFixture = SpecialPoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 112 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 113 | TEST_SUITE(Float) |
| 114 | TEST_SUITE(FP32) |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 115 | FIXTURE_DATA_TEST_CASE(RunSpecial, NESpecialPoolingLayerFixture<float>, framework::DatasetMode::ALL, datasets::PoolingLayerDatasetSpecial() * framework::dataset::make("DataType", DataType::F32)) |
| 116 | { |
| 117 | // Validate output |
| 118 | validate(Accessor(_target), _reference, tolerance_f32); |
| 119 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 120 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 121 | DataType::F32))), |
| 122 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 123 | { |
| 124 | // Validate output |
| 125 | validate(Accessor(_target), _reference, tolerance_f32); |
| 126 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 127 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, |
| 128 | framework::dataset::make("DataType", |
| 129 | DataType::F32))), |
| 130 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 131 | { |
| 132 | // Validate output |
| 133 | validate(Accessor(_target), _reference, tolerance_f32); |
| 134 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 135 | TEST_SUITE_END() // FP32 |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 136 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 137 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 138 | TEST_SUITE(FP16) |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 139 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, |
| 140 | framework::dataset::make("DataType", DataType::F16))), |
| 141 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 142 | { |
| 143 | // Validate output |
| 144 | validate(Accessor(_target), _reference, tolerance_f16); |
| 145 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 146 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, |
| 147 | framework::dataset::make("DataType", DataType::F16))), |
| 148 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 149 | { |
| 150 | // Validate output |
| 151 | validate(Accessor(_target), _reference, tolerance_f16); |
| 152 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 153 | TEST_SUITE_END() // FP16 |
| 154 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 155 | TEST_SUITE_END() // Float |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 156 | |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 157 | TEST_SUITE(Quantized) |
| 158 | |
| 159 | template <typename T> |
| 160 | using NEPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 161 | |
| 162 | TEST_SUITE(QASYMM8) |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 163 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8, |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 164 | framework::dataset::make("DataType", DataType::QASYMM8))), |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 165 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127), |
| 166 | QuantizationInfo(7.f / 255, 123) |
| 167 | })), |
| 168 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 169 | { |
| 170 | // Validate output |
| 171 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 172 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 173 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 174 | framework::dataset::make("DataType", DataType::QASYMM8))), |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 175 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })), |
| 176 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 177 | { |
| 178 | // Validate output |
| 179 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 180 | } |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 181 | TEST_SUITE_END() // QASYMM8 |
| 182 | TEST_SUITE_END() // Quantized |
| 183 | TEST_SUITE_END() // PoolingLayer |
| 184 | TEST_SUITE_END() // NEON |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 185 | } // namespace validation |
| 186 | } // namespace test |
| 187 | } // namespace arm_compute |