blob: dc9604423f5a25faa51abf0140d0dd132909db09 [file] [log] [blame]
Georgios Pinitasdc460f12017-08-24 19:02:44 +01001/*
Diego Lopez Recas61ef5bf2017-12-11 12:36:55 +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/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"
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{
Diego Lopez Recas61ef5bf2017-12-11 12:36:55 +000046/** Failing data set */
47const auto PoolingLayerDatasetSpecial = ((((framework::dataset::make("Shape", TensorShape{ 60U, 52U, 3U, 5U })
48 * framework::dataset::make("PoolType", PoolingType::AVG))
Isabella Gottardi6e464c32018-01-26 12:32:45 +000049 * framework::dataset::make("PoolingSize", Size2D(100, 100)))
Diego Lopez Recas61ef5bf2017-12-11 12:36:55 +000050 * framework::dataset::make("PadStride", PadStrideInfo(5, 5, 50, 50)))
51 * framework::dataset::make("ExcludePadding", true));
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000052/** Input data set for floating-point data types */
Isabella Gottardia527e8c2018-01-31 17:49:25 +000053const 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) })),
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", { true, false }));
Georgios Pinitasdc460f12017-08-24 19:02:44 +010056
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000057/** Input data set for fixed-point data types */
Isabella Gottardi6e464c32018-01-26 12:32:45 +000058const 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 +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) })),
60 framework::dataset::make("ExcludePadding", { true, false }));
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000061
62/** Input data set for asymmetric data type */
Isabella Gottardia527e8c2018-01-31 17:49:25 +000063const 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) })),
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000064 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
65 framework::dataset::make("ExcludePadding", { true, false }));
66
67constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
68constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
69constexpr AbsoluteTolerance<float> tolerance_qs16(6); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit fixed-point type */
70constexpr AbsoluteTolerance<float> tolerance_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit fixed-point type */
71constexpr 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 +010072} // namespace
73
74TEST_SUITE(CL)
75TEST_SUITE(PoolingLayer)
76
Georgios Pinitas3faea252017-10-30 14:13:50 +000077// *INDENT-OFF*
78// clang-format off
79DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000080 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type
Giorgio Arena9f26b3e2017-11-28 14:35:00 +000081 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000082 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Mismatching fixed point position
Diego Lopez Recas61ef5bf2017-12-11 12:36:55 +000083 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11),
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000084 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(27U, 13U, 2U), 1, DataType::QASYMM8, 0), // Invalid parameters
Georgios Pinitas4c2dd542017-11-13 12:58:41 +000087 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling
88 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling
89 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0),
Georgios Pinitas3faea252017-10-30 14:13:50 +000090 }),
91 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0),
92 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0),
93 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5),
94 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11),
95 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0),
96 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0),
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000097 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0),
Georgios Pinitas4c2dd542017-11-13 12:58:41 +000098 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0),
99 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0),
100 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000101 })),
102 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
103 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
104 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
105 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
106 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)),
107 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)),
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000108 PoolingLayerInfo(PoolingType::L2, 3, PadStrideInfo(1, 1, 0, 0)),
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000109 PoolingLayerInfo(PoolingType::AVG),
110 PoolingLayerInfo(PoolingType::MAX),
111 PoolingLayerInfo(PoolingType::AVG),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000112 })),
Isabella Gottardia527e8c2018-01-31 17:49:25 +0000113 framework::dataset::make("Expected", { false, false, false, true, false, false, false, true, false, true })),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000114 input_info, output_info, pool_info, expected)
115{
Giorgio Arena9f26b3e2017-11-28 14:35:00 +0000116 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 +0000117}
118// clang-format on
119// *INDENT-ON*
120
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100121template <typename T>
122using CLPoolingLayerFixture = PoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
123
124TEST_SUITE(Float)
125TEST_SUITE(FP32)
Diego Lopez Recas61ef5bf2017-12-11 12:36:55 +0000126FIXTURE_DATA_TEST_CASE(RunSpecial, CLPoolingLayerFixture<float>, framework::DatasetMode::ALL, PoolingLayerDatasetSpecial * framework::dataset::make("DataType", DataType::F32))
127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance_f32);
130}
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100131FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
132 DataType::F32))))
133{
134 // Validate output
135 validate(CLAccessor(_target), _reference, tolerance_f32);
136}
137FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
138 DataType::F32))))
139{
140 // Validate output
141 validate(CLAccessor(_target), _reference, tolerance_f32);
142}
143TEST_SUITE_END()
144
145TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100146FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP,
147 framework::dataset::make("DataType", DataType::F16))))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100148{
149 // Validate output
150 validate(CLAccessor(_target), _reference, tolerance_f16);
151}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100152FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
153 framework::dataset::make("DataType", DataType::F16))))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100154{
155 // Validate output
156 validate(CLAccessor(_target), _reference, tolerance_f16);
157}
158TEST_SUITE_END()
159TEST_SUITE_END()
160
161template <typename T>
162using CLPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
163
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000164TEST_SUITE(FixedPoint)
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100165TEST_SUITE(QS8)
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000166FIXTURE_DATA_TEST_CASE(RunTiny, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS,
167 framework::dataset::make("DataType", DataType::QS8))),
168 framework::dataset::make("FractionalBits", 1, 4)))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100169{
170 // Validate output
171 validate(CLAccessor(_target), _reference, tolerance_qs8);
172}
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000173FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100174 framework::dataset::make("DataType", DataType::QS8))),
175 framework::dataset::make("FractionalBits", 1, 4)))
176{
177 // Validate output
178 validate(CLAccessor(_target), _reference, tolerance_qs8);
179}
180TEST_SUITE_END()
181
182TEST_SUITE(QS16)
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000183FIXTURE_DATA_TEST_CASE(RunTiny, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), combine(PoolingLayerDatasetQS,
184 framework::dataset::make("DataType", DataType::QS16))),
185 framework::dataset::make("FractionalBits", 1, 12)))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100186{
187 // Validate output
188 validate(CLAccessor(_target), _reference, tolerance_qs16);
189}
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +0000190FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS,
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100191 framework::dataset::make("DataType", DataType::QS16))),
192 framework::dataset::make("FractionalBits", 1, 12)))
193{
194 // Validate output
195 validate(CLAccessor(_target), _reference, tolerance_qs16);
196}
197TEST_SUITE_END()
198TEST_SUITE_END()
199
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000200TEST_SUITE(Quantized)
201
202template <typename T>
203using CLPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
204
205TEST_SUITE(QASYMM8)
206FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8,
207 framework::dataset::make("DataType", DataType::QASYMM8))),
208 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127),
209 QuantizationInfo(7.f / 255, 123)
210 })))
211{
212 // Validate output
213 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
214}
215FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8,
216 framework::dataset::make("DataType", DataType::QASYMM8))),
217 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })))
218{
219 // Validate output
220 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
221}
222TEST_SUITE_END()
223TEST_SUITE_END()
224
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100225TEST_SUITE_END()
226TEST_SUITE_END()
227} // namespace validation
228} // namespace test
229} // namespace arm_compute