blob: 7bd090cb77f88344d20316942feabfcf0c36519d [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001/*
Anthony Barbierf45d5a92018-01-24 16:23:15 +00002 * Copyright (c) 2017-2018 ARM Limited.
Kaizen8938bd32017-09-28 14:38:23 +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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLPoolingLayer.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
Anthony Barbier06ea0482018-02-22 15:45:35 +000030#include "tests/datasets/PoolingLayerDataset.h"
Kaizen8938bd32017-09-28 14:38:23 +010031#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"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
Anthony Barbier8140e1e2017-12-14 23:48:46 +000047/** Input data set for floating-point data types */
Anthony Barbier06ea0482018-02-22 15:45:35 +000048const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(7, 7), Size2D(9, 9), Size2D(5, 7), Size2D(7, 9) })),
Anthony Barbier8140e1e2017-12-14 23:48:46 +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 }));
Kaizen8938bd32017-09-28 14:38:23 +010051
Anthony Barbier8140e1e2017-12-14 23:48:46 +000052/** Input data set for fixed-point data types */
Anthony Barbier06ea0482018-02-22 15:45:35 +000053const auto PoolingLayerDatasetQS = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })),
Anthony Barbier8140e1e2017-12-14 23:48:46 +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", { true, false }));
Kaizen8938bd32017-09-28 14:38:23 +010056
Anthony Barbier8140e1e2017-12-14 23:48:46 +000057/** Input data set for asymmetric data type */
Anthony Barbier06ea0482018-02-22 15:45:35 +000058const auto PoolingLayerDatasetQASYMM8 = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(5, 7), Size2D(8, 9) })),
Anthony Barbier8140e1e2017-12-14 23:48:46 +000059 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
Jenkinsb3a371b2018-05-23 11:36:53 +010060 framework::dataset::make("ExcludePadding", { true }));
Anthony Barbier8140e1e2017-12-14 23:48:46 +000061
62constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
63constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
64constexpr AbsoluteTolerance<float> tolerance_qs16(6); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit fixed-point type */
65constexpr AbsoluteTolerance<float> tolerance_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit fixed-point type */
66constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */
Kaizen8938bd32017-09-28 14:38:23 +010067} // namespace
68
69TEST_SUITE(CL)
70TEST_SUITE(PoolingLayer)
71
Anthony Barbier8140e1e2017-12-14 23:48:46 +000072// *INDENT-OFF*
73// clang-format off
74DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
75 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type
76 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink
77 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Mismatching fixed point position
Anthony Barbierf45d5a92018-01-24 16:23:15 +000078 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11),
Anthony Barbier8140e1e2017-12-14 23:48:46 +000079 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination
80 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination
81 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0), // Invalid parameters
82 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling
83 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling
84 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0),
85 }),
86 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0),
87 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0),
88 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5),
89 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11),
90 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0),
91 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0),
92 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0),
93 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0),
94 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0),
95 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0),
96 })),
97 framework::dataset::make("PoolInfo", { 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, 3, PadStrideInfo(1, 1, 0, 0)),
101 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)),
102 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)),
103 PoolingLayerInfo(PoolingType::L2, 3, PadStrideInfo(1, 1, 0, 0)),
104 PoolingLayerInfo(PoolingType::AVG),
105 PoolingLayerInfo(PoolingType::MAX),
106 PoolingLayerInfo(PoolingType::AVG),
107 })),
Anthony Barbier06ea0482018-02-22 15:45:35 +0000108 framework::dataset::make("Expected", { false, false, false, true, false, false, false, true, false, true })),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000109 input_info, output_info, pool_info, expected)
110{
111 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);
112}
113// clang-format on
114// *INDENT-ON*
115
Kaizen8938bd32017-09-28 14:38:23 +0100116template <typename T>
117using CLPoolingLayerFixture = PoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
118
Anthony Barbier06ea0482018-02-22 15:45:35 +0000119template <typename T>
120using CLSpecialPoolingLayerFixture = SpecialPoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
121
Kaizen8938bd32017-09-28 14:38:23 +0100122TEST_SUITE(Float)
123TEST_SUITE(FP32)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000124FIXTURE_DATA_TEST_CASE(RunSpecial, CLSpecialPoolingLayerFixture<float>, framework::DatasetMode::ALL, datasets::PoolingLayerDatasetSpecial() * framework::dataset::make("DataType", DataType::F32))
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000125{
126 // Validate output
127 validate(CLAccessor(_target), _reference, tolerance_f32);
128}
Jenkinsb3a371b2018-05-23 11:36:53 +0100129FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
130 DataType::F32))),
131 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Kaizen8938bd32017-09-28 14:38:23 +0100132{
133 // Validate output
134 validate(CLAccessor(_target), _reference, tolerance_f32);
135}
Jenkinsb3a371b2018-05-23 11:36:53 +0100136FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
137 framework::dataset::make("DataType",
138 DataType::F32))),
139 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Kaizen8938bd32017-09-28 14:38:23 +0100140{
141 // Validate output
142 validate(CLAccessor(_target), _reference, tolerance_f32);
143}
Jenkinsb3a371b2018-05-23 11:36:53 +0100144TEST_SUITE_END() // FP32
Kaizen8938bd32017-09-28 14:38:23 +0100145
146TEST_SUITE(FP16)
Jenkinsb3a371b2018-05-23 11:36:53 +0100147FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP,
148 framework::dataset::make("DataType", DataType::F16))),
149 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Kaizen8938bd32017-09-28 14:38:23 +0100150{
151 // Validate output
152 validate(CLAccessor(_target), _reference, tolerance_f16);
153}
Jenkinsb3a371b2018-05-23 11:36:53 +0100154FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
155 framework::dataset::make("DataType", DataType::F16))),
156 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Kaizen8938bd32017-09-28 14:38:23 +0100157{
158 // Validate output
159 validate(CLAccessor(_target), _reference, tolerance_f16);
160}
Jenkinsb3a371b2018-05-23 11:36:53 +0100161TEST_SUITE_END() // FP16
162TEST_SUITE_END() // Float
Kaizen8938bd32017-09-28 14:38:23 +0100163
164template <typename T>
165using CLPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
166
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000167TEST_SUITE(FixedPoint)
Kaizen8938bd32017-09-28 14:38:23 +0100168TEST_SUITE(QS8)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000169FIXTURE_DATA_TEST_CASE(RunTiny, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS,
170 framework::dataset::make("DataType", DataType::QS8))),
171 framework::dataset::make("FractionalBits", 1, 4)))
Kaizen8938bd32017-09-28 14:38:23 +0100172{
173 // Validate output
174 validate(CLAccessor(_target), _reference, tolerance_qs8);
175}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000176FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
Kaizen8938bd32017-09-28 14:38:23 +0100177 framework::dataset::make("DataType", DataType::QS8))),
178 framework::dataset::make("FractionalBits", 1, 4)))
179{
180 // Validate output
181 validate(CLAccessor(_target), _reference, tolerance_qs8);
182}
Jenkinsb3a371b2018-05-23 11:36:53 +0100183TEST_SUITE_END() // QS8
Kaizen8938bd32017-09-28 14:38:23 +0100184
185TEST_SUITE(QS16)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000186FIXTURE_DATA_TEST_CASE(RunTiny, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS,
187 framework::dataset::make("DataType", DataType::QS16))),
188 framework::dataset::make("FractionalBits", 1, 12)))
Kaizen8938bd32017-09-28 14:38:23 +0100189{
190 // Validate output
191 validate(CLAccessor(_target), _reference, tolerance_qs16);
192}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000193FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
Kaizen8938bd32017-09-28 14:38:23 +0100194 framework::dataset::make("DataType", DataType::QS16))),
195 framework::dataset::make("FractionalBits", 1, 12)))
196{
197 // Validate output
198 validate(CLAccessor(_target), _reference, tolerance_qs16);
199}
Jenkinsb3a371b2018-05-23 11:36:53 +0100200TEST_SUITE_END() // QS16
201TEST_SUITE_END() // fixedPoint
Kaizen8938bd32017-09-28 14:38:23 +0100202
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000203TEST_SUITE(Quantized)
204
205template <typename T>
206using CLPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
207
208TEST_SUITE(QASYMM8)
Jenkinsb3a371b2018-05-23 11:36:53 +0100209FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8,
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000210 framework::dataset::make("DataType", DataType::QASYMM8))),
Jenkinsb3a371b2018-05-23 11:36:53 +0100211 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127),
212 QuantizationInfo(7.f / 255, 123)
213 })),
214 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000215{
216 // Validate output
217 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
218}
Jenkinsb3a371b2018-05-23 11:36:53 +0100219FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8,
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000220 framework::dataset::make("DataType", DataType::QASYMM8))),
Jenkinsb3a371b2018-05-23 11:36:53 +0100221 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })),
222 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000223{
224 // Validate output
225 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
226}
Jenkinsb3a371b2018-05-23 11:36:53 +0100227TEST_SUITE_END() // QASYMM8
228TEST_SUITE_END() // Quantized
229TEST_SUITE_END() // PoolingLayer
230TEST_SUITE_END() // CL
Kaizen8938bd32017-09-28 14:38:23 +0100231} // namespace validation
232} // namespace test
233} // namespace arm_compute