Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLPoolingLayer.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.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 | { |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 46 | /** Input data set for floating-point data types */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 47 | const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3, 4, 7, 9 })), |
| 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 | |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 51 | /** Input data set for fixed-point data types */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 52 | const auto PoolingLayerDatasetQS = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { 2, 3 })), |
| 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", { true, false })); |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 55 | |
| 56 | /** Input data set for asymmetric data type */ |
| 57 | const auto PoolingLayerDatasetQASYMM8 = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { 2, 3 })), |
| 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 | |
| 61 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */ |
| 62 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */ |
| 63 | constexpr AbsoluteTolerance<float> tolerance_qs16(6); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit fixed-point type */ |
| 64 | constexpr AbsoluteTolerance<float> tolerance_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit fixed-point type */ |
| 65 | 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] | 66 | } // namespace |
| 67 | |
| 68 | TEST_SUITE(CL) |
| 69 | TEST_SUITE(PoolingLayer) |
| 70 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 71 | // *INDENT-OFF* |
| 72 | // clang-format off |
| 73 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 74 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 75 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 76 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Mismatching fixed point position |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 77 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11), // Window shrink |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 78 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination |
| 79 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination |
| 80 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0), // Invalid parameters |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 81 | TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling |
| 82 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling |
| 83 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 84 | }), |
| 85 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0), |
| 86 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0), |
| 87 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5), |
| 88 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11), |
| 89 | TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0), |
| 90 | TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0), |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 91 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0), |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 92 | TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0), |
| 93 | TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0), |
| 94 | TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 95 | })), |
| 96 | framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 97 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 98 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 99 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 100 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)), |
| 101 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)), |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 102 | PoolingLayerInfo(PoolingType::L2, 3, PadStrideInfo(1, 1, 0, 0)), |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 103 | PoolingLayerInfo(PoolingType::AVG), |
| 104 | PoolingLayerInfo(PoolingType::MAX), |
| 105 | PoolingLayerInfo(PoolingType::AVG), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 106 | })), |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 107 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, true })), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 108 | input_info, output_info, pool_info, expected) |
| 109 | { |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 110 | ARM_COMPUTE_EXPECT(bool(CLPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info)) == expected, framework::LogLevel::ERRORS); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 111 | } |
| 112 | // clang-format on |
| 113 | // *INDENT-ON* |
| 114 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 115 | template <typename T> |
| 116 | using CLPoolingLayerFixture = PoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>; |
| 117 | |
| 118 | TEST_SUITE(Float) |
| 119 | TEST_SUITE(FP32) |
| 120 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 121 | DataType::F32)))) |
| 122 | { |
| 123 | // Validate output |
| 124 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 125 | } |
| 126 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 127 | DataType::F32)))) |
| 128 | { |
| 129 | // Validate output |
| 130 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 131 | } |
| 132 | TEST_SUITE_END() |
| 133 | |
| 134 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 135 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, |
| 136 | framework::dataset::make("DataType", DataType::F16)))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 137 | { |
| 138 | // Validate output |
| 139 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 140 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 141 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, |
| 142 | framework::dataset::make("DataType", DataType::F16)))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 143 | { |
| 144 | // Validate output |
| 145 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 146 | } |
| 147 | TEST_SUITE_END() |
| 148 | TEST_SUITE_END() |
| 149 | |
| 150 | template <typename T> |
| 151 | using CLPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<CLTensor, CLAccessor, CLPoolingLayer, T>; |
| 152 | |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 153 | TEST_SUITE(FixedPoint) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 154 | TEST_SUITE(QS8) |
| 155 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
| 156 | framework::dataset::make("DataType", DataType::QS8))), |
| 157 | framework::dataset::make("FractionalBits", 1, 4))) |
| 158 | { |
| 159 | // Validate output |
| 160 | validate(CLAccessor(_target), _reference, tolerance_qs8); |
| 161 | } |
| 162 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS, |
| 163 | framework::dataset::make("DataType", DataType::QS8))), |
| 164 | framework::dataset::make("FractionalBits", 1, 4))) |
| 165 | { |
| 166 | // Validate output |
| 167 | validate(CLAccessor(_target), _reference, tolerance_qs8); |
| 168 | } |
| 169 | TEST_SUITE_END() |
| 170 | |
| 171 | TEST_SUITE(QS16) |
| 172 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
| 173 | framework::dataset::make("DataType", DataType::QS16))), |
| 174 | framework::dataset::make("FractionalBits", 1, 12))) |
| 175 | { |
| 176 | // Validate output |
| 177 | validate(CLAccessor(_target), _reference, tolerance_qs16); |
| 178 | } |
| 179 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS, |
| 180 | framework::dataset::make("DataType", DataType::QS16))), |
| 181 | framework::dataset::make("FractionalBits", 1, 12))) |
| 182 | { |
| 183 | // Validate output |
| 184 | validate(CLAccessor(_target), _reference, tolerance_qs16); |
| 185 | } |
| 186 | TEST_SUITE_END() |
| 187 | TEST_SUITE_END() |
| 188 | |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 189 | TEST_SUITE(Quantized) |
| 190 | |
| 191 | template <typename T> |
| 192 | using CLPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPoolingLayer, T>; |
| 193 | |
| 194 | TEST_SUITE(QASYMM8) |
| 195 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8, |
| 196 | framework::dataset::make("DataType", DataType::QASYMM8))), |
| 197 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127), |
| 198 | QuantizationInfo(7.f / 255, 123) |
| 199 | }))) |
| 200 | { |
| 201 | // Validate output |
| 202 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 203 | } |
| 204 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8, |
| 205 | framework::dataset::make("DataType", DataType::QASYMM8))), |
| 206 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) }))) |
| 207 | { |
| 208 | // Validate output |
| 209 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 210 | } |
| 211 | TEST_SUITE_END() |
| 212 | TEST_SUITE_END() |
| 213 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 214 | TEST_SUITE_END() |
| 215 | TEST_SUITE_END() |
| 216 | } // namespace validation |
| 217 | } // namespace test |
| 218 | } // namespace arm_compute |