blob: 611c01b37a1c94650bcdd35fa67d84af69886670 [file] [log] [blame]
Georgios Pinitasdc460f12017-08-24 19:02:44 +01001/*
Michele Di Giorgiocbbed282019-12-20 13:26:08 +00002 * Copyright (c) 2017-2020 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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLPoolingLayer.h"
Georgios Pinitasdc460f12017-08-24 19:02:44 +010028#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
Georgios Pinitas15997872018-02-19 13:58:22 +000030#include "tests/datasets/PoolingLayerDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +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"
Georgios Pinitasdc460f12017-08-24 19:02:44 +010038
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
Michalis Spyrou064add62018-11-01 18:14:27 +000047/** Input data sets for floating-point data types */
Michalis Spyrou5ce99a22019-01-25 14:17:49 +000048const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(5, 7) })),
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
Michalis Spyrou80943252019-01-10 17:19:50 +000052const auto PoolingLayerDatasetFPSmall = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })),
53 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0) })),
Michalis Spyrou064add62018-11-01 18:14:27 +000054 framework::dataset::make("ExcludePadding", { true, false }));
55
56/** Input data sets for asymmetric data type */
57const auto PoolingLayerDatasetQASYMM8 = combine(concat(combine(combine(framework::dataset::make("PoolingType",
58{
59 PoolingType::MAX, PoolingType::AVG,
60}),
Michalis Spyrou5ce99a22019-01-25 14:17:49 +000061framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })),
62framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
63combine(combine(framework::dataset::make("PoolingType", { PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(5, 7) })), framework::dataset::make("PadStride", { PadStrideInfo(2, 1, 0, 0) }))),
Michalis Spyrou064add62018-11-01 18:14:27 +000064framework::dataset::make("ExcludePadding", { true }));
65
66const auto PoolingLayerDatasetQASYMM8Small = combine(combine(combine(framework::dataset::make("PoolingType",
67{
68 PoolingType::MAX, PoolingType::AVG,
69}),
Michalis Spyrou80943252019-01-10 17:19:50 +000070framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(5, 7) })),
71framework::dataset::make("PadStride", { PadStrideInfo(1, 2, 1, 1) })),
Michalis Spyrou064add62018-11-01 18:14:27 +000072framework::dataset::make("ExcludePadding", { true }));
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000073
Michele Di Giorgiocbbed282019-12-20 13:26:08 +000074constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
75constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
76constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */
77constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_s(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit signed asymmetric type */
Pablo Telloa52e4cf2019-04-01 14:55:18 +010078const auto pool_data_layout_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC });
79
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +010080const auto pool_fp_mixed_precision_dataset = framework::dataset::make("FpMixedPrecision", { true, false });
81
Georgios Pinitasdc460f12017-08-24 19:02:44 +010082} // namespace
83
84TEST_SUITE(CL)
85TEST_SUITE(PoolingLayer)
86
Georgios Pinitas3faea252017-10-30 14:13:50 +000087// *INDENT-OFF*
88// clang-format off
89DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010090 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
91 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
92 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
93 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
94 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), // Invalid parameters
95 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32), // Non-rectangular Global Pooling
96 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), // Invalid output Global Pooling
Michele Di Giorgio2c877192020-02-18 19:06:27 +000097 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::QASYMM8), // Invalid exclude_padding = false with quantized type, no actual padding and NHWC
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010098 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32),
Georgios Pinitas3faea252017-10-30 14:13:50 +000099 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100100 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
101 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
102 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32),
103 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32),
104 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8),
105 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
106 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32),
Michele Di Giorgio2c877192020-02-18 19:06:27 +0000107 TensorInfo(TensorShape(12U, 12U, 5U), 1, DataType::QASYMM8),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100108 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000109 })),
Sang-Hoon Park11fedda2020-01-15 14:44:04 +0000110 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0)),
111 PoolingLayerInfo(PoolingType::AVG, 3, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0)),
112 PoolingLayerInfo(PoolingType::AVG, 2, DataLayout::NCHW, PadStrideInfo(1, 1, 2, 0)),
113 PoolingLayerInfo(PoolingType::AVG, 2, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 2)),
114 PoolingLayerInfo(PoolingType::L2, 3, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0)),
115 PoolingLayerInfo(PoolingType::AVG, DataLayout::NCHW),
116 PoolingLayerInfo(PoolingType::MAX, DataLayout::NCHW),
Michele Di Giorgio2c877192020-02-18 19:06:27 +0000117 PoolingLayerInfo(PoolingType::AVG, 2, DataLayout::NHWC, PadStrideInfo(), false),
Sang-Hoon Park11fedda2020-01-15 14:44:04 +0000118 PoolingLayerInfo(PoolingType::AVG, DataLayout::NCHW),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000119 })),
Michele Di Giorgio2c877192020-02-18 19:06:27 +0000120 framework::dataset::make("Expected", { false, false, false, false, false, true, false, false, true })),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000121 input_info, output_info, pool_info, expected)
122{
Giorgio Arena9f26b3e2017-11-28 14:35:00 +0000123 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 Pinitas3faea252017-10-30 14:13:50 +0000124}
125// clang-format on
126// *INDENT-ON*
127
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100128template <typename T>
129using CLPoolingLayerFixture = PoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
130
Georgios Pinitas15997872018-02-19 13:58:22 +0000131template <typename T>
132using CLSpecialPoolingLayerFixture = SpecialPoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
133
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +0100134template <typename T>
135using CLMixedPrecesionPoolingLayerFixture = PoolingLayerValidationMixedPrecisionFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
136
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100137TEST_SUITE(Float)
138TEST_SUITE(FP32)
Georgios Pinitas15997872018-02-19 13:58:22 +0000139FIXTURE_DATA_TEST_CASE(RunSpecial, CLSpecialPoolingLayerFixture<float>, framework::DatasetMode::ALL, datasets::PoolingLayerDatasetSpecial() * framework::dataset::make("DataType", DataType::F32))
Diego Lopez Recas61ef5bf2017-12-11 12:36:55 +0000140{
141 // Validate output
142 validate(CLAccessor(_target), _reference, tolerance_f32);
143}
Michalis Spyrou064add62018-11-01 18:14:27 +0000144FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall,
145 framework::dataset::make("DataType",
146 DataType::F32))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100147 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100148{
149 // Validate output
150 validate(CLAccessor(_target), _reference, tolerance_f32);
151}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000152FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
153 framework::dataset::make("DataType",
154 DataType::F32))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100155 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100156{
157 // Validate output
158 validate(CLAccessor(_target), _reference, tolerance_f32);
159}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000160TEST_SUITE_END() // FP32
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100161
162TEST_SUITE(FP16)
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +0100163FIXTURE_DATA_TEST_CASE(RunSmall, CLMixedPrecesionPoolingLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall,
164 framework::dataset::make("DataType", DataType::F16))),
165 pool_data_layout_dataset),
166 pool_fp_mixed_precision_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100167{
168 // Validate output
169 validate(CLAccessor(_target), _reference, tolerance_f16);
170}
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +0100171FIXTURE_DATA_TEST_CASE(RunLarge, CLMixedPrecesionPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
172 framework::dataset::make("DataType", DataType::F16))),
173 pool_data_layout_dataset),
174 pool_fp_mixed_precision_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_f16);
178}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000179TEST_SUITE_END() // FP16
180TEST_SUITE_END() // Float
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100181
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000182TEST_SUITE(Quantized)
183
184template <typename T>
185using CLPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
186
187TEST_SUITE(QASYMM8)
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100188FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small,
Michalis Spyrou064add62018-11-01 18:14:27 +0000189 framework::dataset::make("DataType", DataType::QASYMM8))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100190 pool_data_layout_dataset))
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000191{
192 // Validate output
193 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
194}
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000195TEST_SUITE_END() // QASYMM8
196
197TEST_SUITE(QASYMM8_SIGNED)
198FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small,
199 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED))),
200 pool_data_layout_dataset))
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000201{
202 // Validate output
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000203 validate(CLAccessor(_target), _reference, tolerance_qasymm8_s);
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000204}
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000205TEST_SUITE_END() // QASYMM8_SIGNED
Michalis Spyrou57dac842018-03-01 16:03:50 +0000206TEST_SUITE_END() // Quantized
Michalis Spyrou57dac842018-03-01 16:03:50 +0000207TEST_SUITE_END() // PoolingLayer
208TEST_SUITE_END() // CL
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100209} // namespace validation
210} // namespace test
211} // namespace arm_compute