blob: 79a732a59a26b5afb43ea294f51ae80f60c4bb64 [file] [log] [blame]
Georgios Pinitasdc460f12017-08-24 19:02:44 +01001/*
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/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 */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +000047const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3, 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 Pinitasdc460f12017-08-24 19:02:44 +010050
51/** Input data set for quantized data types */
Georgios Pinitasadaae7e2017-10-30 15:56:32 +000052const 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", { false }));
Georgios Pinitasdc460f12017-08-24 19:02:44 +010055
56constexpr 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 +000057#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitasdc460f12017-08-24 19:02:44 +010058constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000059#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitasdc460f12017-08-24 19:02:44 +010060constexpr AbsoluteTolerance<float> tolerance_qs8(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */
61constexpr AbsoluteTolerance<float> tolerance_qs16(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */
62} // namespace
63
64TEST_SUITE(NEON)
65TEST_SUITE(PoolingLayer)
66
67//TODO(COMPMID-415): Configuration tests?
68
Michalis Spyrouafa5d812017-11-30 14:25:57 +000069// *INDENT-OFF*
70// clang-format off
71DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
72 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type
73 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink
74 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Mismatching fixed point position
75 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11), // Window shrink
76 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination
77 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination
78 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling
79 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling
80 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0),
81 }),
82 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0),
83 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32, 0),
84 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5),
85 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11),
86 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0),
87 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0),
88 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0),
89 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0),
90 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0),
91 })),
92 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
93 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
94 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
95 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
96 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)),
97 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)),
98 PoolingLayerInfo(PoolingType::AVG),
99 PoolingLayerInfo(PoolingType::MAX),
100 PoolingLayerInfo(PoolingType::AVG),
101 })),
102 framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, true })),
103 input_info, output_info, pool_info, expected)
104{
105 bool is_valid = bool(NEPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info));
106 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
107}
108// clang-format on
109// *INDENT-ON*
110
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100111template <typename T>
112using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>;
113
114TEST_SUITE(Float)
115TEST_SUITE(FP32)
116FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
117 DataType::F32))))
118{
119 // Validate output
120 validate(Accessor(_target), _reference, tolerance_f32);
121}
122FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
123 DataType::F32))))
124{
125 // Validate output
126 validate(Accessor(_target), _reference, tolerance_f32);
127}
128TEST_SUITE_END()
129
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000130#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100131TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100132FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP,
133 framework::dataset::make("DataType", DataType::F16))))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100134{
135 // Validate output
136 validate(Accessor(_target), _reference, tolerance_f16);
137}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100138FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
139 framework::dataset::make("DataType", DataType::F16))))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100140{
141 // Validate output
142 validate(Accessor(_target), _reference, tolerance_f16);
143}
144TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000145#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100146TEST_SUITE_END()
147
148template <typename T>
149using NEPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<Tensor, Accessor, NEPoolingLayer, T>;
150
151TEST_SUITE(Quantized)
152TEST_SUITE(QS8)
153FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
154 framework::dataset::make("DataType", DataType::QS8))),
155 framework::dataset::make("FractionalBits", 1, 5)))
156{
157 // Validate output
158 validate(Accessor(_target), _reference, tolerance_qs8);
159}
160FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS,
161 framework::dataset::make("DataType", DataType::QS8))),
162 framework::dataset::make("FractionalBits", 1, 5)))
163{
164 // Validate output
165 validate(Accessor(_target), _reference, tolerance_qs8);
166}
167TEST_SUITE_END()
168
169TEST_SUITE(QS16)
170FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
171 framework::dataset::make("DataType", DataType::QS16))),
172 framework::dataset::make("FractionalBits", 1, 13)))
173{
174 // Validate output
175 validate(Accessor(_target), _reference, tolerance_qs16);
176}
177FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS,
178 framework::dataset::make("DataType", DataType::QS16))),
179 framework::dataset::make("FractionalBits", 1, 13)))
180{
181 // Validate output
182 validate(Accessor(_target), _reference, tolerance_qs16);
183}
184TEST_SUITE_END()
185TEST_SUITE_END()
186
187TEST_SUITE_END()
188TEST_SUITE_END()
189} // namespace validation
190} // namespace test
191} // namespace arm_compute