blob: 4697d4db015b228b53704a3518d9f06e615c0580 [file] [log] [blame]
Georgios Pinitasdc460f12017-08-24 19:02:44 +01001/*
Georgios Pinitas55186712018-01-08 17:37:12 +00002 * Copyright (c) 2017-2018 ARM Limited.
Georgios Pinitasdc460f12017-08-24 19:02:44 +01003 *
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 Pinitasdc460f12017-08-24 19:02:44 +010028#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#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 Pinitasdc460f12017-08-24 19:02:44 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Input data set for float data types */
Isabella Gottardi7567f5f2018-01-30 15:26:00 +000047
48const 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 Pinitasadaae7e2017-10-30 15:56:32 +000049 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
50 framework::dataset::make("ExcludePadding", { true, false }));
Georgios Pinitasdc460f12017-08-24 19:02:44 +010051
52/** Input data set for quantized data types */
Isabella Gottardi6e464c32018-01-26 12:32:45 +000053const auto PoolingLayerDatasetQS = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })),
Georgios Pinitasadaae7e2017-10-30 15:56:32 +000054 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
55 framework::dataset::make("ExcludePadding", { false }));
Georgios Pinitasdc460f12017-08-24 19:02:44 +010056
Georgios Pinitas55186712018-01-08 17:37:12 +000057/** Input data set for asymmetric data type */
Isabella Gottardi7567f5f2018-01-30 15:26:00 +000058
59const 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 Pinitas55186712018-01-08 17:37:12 +000060 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
61 framework::dataset::make("ExcludePadding", { true, false }));
62
Georgios Pinitasdc460f12017-08-24 19:02:44 +010063constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for float types */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000064#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitas55186712018-01-08 17:37:12 +000065constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */
66#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
67constexpr AbsoluteTolerance<float> tolerance_qs8(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */
68constexpr AbsoluteTolerance<float> tolerance_qs16(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */
69constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */
Georgios Pinitasdc460f12017-08-24 19:02:44 +010070} // namespace
71
72TEST_SUITE(NEON)
73TEST_SUITE(PoolingLayer)
74
75//TODO(COMPMID-415): Configuration tests?
76
Michalis Spyrouafa5d812017-11-30 14:25:57 +000077// *INDENT-OFF*
78// clang-format off
79DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
80 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type
81 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Mismatching fixed point position
83 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11), // Window shrink
84 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination
85 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination
86 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling
87 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling
88 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0),
89 }),
90 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0),
91 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32, 0),
92 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5),
93 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11),
94 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0),
95 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0),
96 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0),
97 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0),
98 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0),
99 })),
100 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
101 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
102 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
103 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
104 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)),
105 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)),
106 PoolingLayerInfo(PoolingType::AVG),
107 PoolingLayerInfo(PoolingType::MAX),
108 PoolingLayerInfo(PoolingType::AVG),
109 })),
Isabella Gottardi7567f5f2018-01-30 15:26:00 +0000110 framework::dataset::make("Expected", { false, false, false, false, false, false, true, false, false, true })),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000111 input_info, output_info, pool_info, expected)
112{
113 bool is_valid = bool(NEPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info));
114 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
115}
116// clang-format on
117// *INDENT-ON*
118
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100119template <typename T>
120using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>;
121
122TEST_SUITE(Float)
123TEST_SUITE(FP32)
124FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
125 DataType::F32))))
126{
127 // Validate output
128 validate(Accessor(_target), _reference, tolerance_f32);
129}
130FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
131 DataType::F32))))
132{
133 // Validate output
134 validate(Accessor(_target), _reference, tolerance_f32);
135}
136TEST_SUITE_END()
137
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000138#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100139TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100140FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP,
141 framework::dataset::make("DataType", DataType::F16))))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100142{
143 // Validate output
144 validate(Accessor(_target), _reference, tolerance_f16);
145}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100146FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
147 framework::dataset::make("DataType", DataType::F16))))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100148{
149 // Validate output
150 validate(Accessor(_target), _reference, tolerance_f16);
151}
152TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000153#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100154TEST_SUITE_END()
155
156template <typename T>
157using NEPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<Tensor, Accessor, NEPoolingLayer, T>;
158
Georgios Pinitas55186712018-01-08 17:37:12 +0000159TEST_SUITE(FixedPoint)
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100160TEST_SUITE(QS8)
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000161FIXTURE_DATA_TEST_CASE(RunTiny, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS,
162 framework::dataset::make("DataType", DataType::QS8))),
163 framework::dataset::make("FractionalBits", 1, 5)))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100164{
165 // Validate output
166 validate(Accessor(_target), _reference, tolerance_qs8);
167}
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000168FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100169 framework::dataset::make("DataType", DataType::QS8))),
170 framework::dataset::make("FractionalBits", 1, 5)))
171{
172 // Validate output
173 validate(Accessor(_target), _reference, tolerance_qs8);
174}
175TEST_SUITE_END()
176
177TEST_SUITE(QS16)
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000178FIXTURE_DATA_TEST_CASE(RunTiny, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS,
179 framework::dataset::make("DataType", DataType::QS16))),
180 framework::dataset::make("FractionalBits", 1, 13)))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100181{
182 // Validate output
183 validate(Accessor(_target), _reference, tolerance_qs16);
184}
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000185FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100186 framework::dataset::make("DataType", DataType::QS16))),
187 framework::dataset::make("FractionalBits", 1, 13)))
188{
189 // Validate output
190 validate(Accessor(_target), _reference, tolerance_qs16);
191}
192TEST_SUITE_END()
193TEST_SUITE_END()
194
Georgios Pinitas55186712018-01-08 17:37:12 +0000195TEST_SUITE(Quantized)
196
197template <typename T>
198using NEPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<Tensor, Accessor, NEPoolingLayer, T>;
199
200TEST_SUITE(QASYMM8)
201FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8,
202 framework::dataset::make("DataType", DataType::QASYMM8))),
203 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127),
204 QuantizationInfo(7.f / 255, 123)
205 })))
206{
207 // Validate output
208 validate(Accessor(_target), _reference, tolerance_qasymm8);
209}
210FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8,
211 framework::dataset::make("DataType", DataType::QASYMM8))),
212 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })))
213{
214 // Validate output
215 validate(Accessor(_target), _reference, tolerance_qasymm8);
216}
217TEST_SUITE_END()
218TEST_SUITE_END()
219
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100220TEST_SUITE_END()
221TEST_SUITE_END()
222} // namespace validation
223} // namespace test
224} // namespace arm_compute