blob: 07d1f1f702c4df5ca2a8f7b43bc25af5005a462a [file] [log] [blame]
Georgios Pinitasdc460f12017-08-24 19:02:44 +01001/*
Manuel Bottinib4bb8272019-12-18 18:01:27 +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/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"
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 float data types */
Isabella Gottardi7567f5f2018-01-30 15:26:00 +000048
Michalis Spyrou5ce99a22019-01-25 14:17:49 +000049const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(7, 7), Size2D(3, 7), Size2D(7, 8) })),
50 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
Georgios Pinitasadaae7e2017-10-30 15:56:32 +000051 framework::dataset::make("ExcludePadding", { true, false }));
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +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 }));
Georgios Pinitasdc460f12017-08-24 19:02:44 +010055
Michalis Spyrou064add62018-11-01 18:14:27 +000056/** Input data sets for asymmetric data type */
Isabella Gottardi7567f5f2018-01-30 15:26:00 +000057
Michalis Spyrou5ce99a22019-01-25 14:17:49 +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(3, 7), Size2D(7, 8) })),
59 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
Michalis Spyrou57dac842018-03-01 16:03:50 +000060 framework::dataset::make("ExcludePadding", { true }));
Michalis Spyrou064add62018-11-01 18:14:27 +000061const auto PoolingLayerDatasetQASYMM8Small = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 7) })),
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000062 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(1, 2, 1, 1) })),
Michalis Spyrou064add62018-11-01 18:14:27 +000063 framework::dataset::make("ExcludePadding", { true }));
Georgios Pinitas55186712018-01-08 17:37:12 +000064
Georgios Pinitasdc460f12017-08-24 19:02:44 +010065constexpr 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 +000066#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Manuel Bottinib4bb8272019-12-18 18:01:27 +000067constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */
68#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
69constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for unsigned 8-bit asymmetric type */
70constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_s(1); /**< Tolerance value for comparing reference's output against implementation's output for signed 8-bit asymmetric type */
Pablo Telloa52e4cf2019-04-01 14:55:18 +010071const auto pool_data_layout_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC });
72
Georgios Pinitasdc460f12017-08-24 19:02:44 +010073} // namespace
74
75TEST_SUITE(NEON)
76TEST_SUITE(PoolingLayer)
77
Michalis Spyrouafa5d812017-11-30 14:25:57 +000078// *INDENT-OFF*
79// clang-format off
80DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010081 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
83 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
84 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
85 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32), // Non-rectangular Global Pooling
86 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), // Invalid output Global Pooling
87 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +000088 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010089 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
90 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32),
91 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32),
92 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32),
93 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
94 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32),
95 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +000096 })),
Sang-Hoon Park11fedda2020-01-15 14:44:04 +000097 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0)),
98 PoolingLayerInfo(PoolingType::AVG, 3, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 0)),
99 PoolingLayerInfo(PoolingType::AVG, 2, DataLayout::NCHW, PadStrideInfo(1, 1, 2, 0)),
100 PoolingLayerInfo(PoolingType::AVG, 2, DataLayout::NCHW, PadStrideInfo(1, 1, 0, 2)),
101 PoolingLayerInfo(PoolingType::AVG, DataLayout::NCHW),
102 PoolingLayerInfo(PoolingType::MAX, DataLayout::NCHW),
103 PoolingLayerInfo(PoolingType::AVG, DataLayout::NCHW),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000104 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +0100105 framework::dataset::make("Expected", { false, false, false, false, true, false, false, true })),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000106 input_info, output_info, pool_info, expected)
107{
108 bool is_valid = bool(NEPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info));
109 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
110}
111// clang-format on
112// *INDENT-ON*
113
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100114template <typename T>
115using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>;
116
Georgios Pinitas15997872018-02-19 13:58:22 +0000117template <typename T>
118using NESpecialPoolingLayerFixture = SpecialPoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>;
119
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100120TEST_SUITE(Float)
121TEST_SUITE(FP32)
Georgios Pinitas15997872018-02-19 13:58:22 +0000122FIXTURE_DATA_TEST_CASE(RunSpecial, NESpecialPoolingLayerFixture<float>, framework::DatasetMode::ALL, datasets::PoolingLayerDatasetSpecial() * framework::dataset::make("DataType", DataType::F32))
123{
124 // Validate output
125 validate(Accessor(_target), _reference, tolerance_f32);
126}
Michalis Spyrou064add62018-11-01 18:14:27 +0000127FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall,
128 framework::dataset::make("DataType",
129 DataType::F32))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100130 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100131{
132 // Validate output
133 validate(Accessor(_target), _reference, tolerance_f32);
134}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000135FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
136 framework::dataset::make("DataType",
137 DataType::F32))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100138 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100139{
140 // Validate output
141 validate(Accessor(_target), _reference, tolerance_f32);
142}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000143TEST_SUITE_END() // FP32
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100144
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000145#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100146TEST_SUITE(FP16)
Michalis Spyrou064add62018-11-01 18:14:27 +0000147FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall,
148 framework::dataset::make("DataType", DataType::F16))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100149 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100150{
151 // Validate output
152 validate(Accessor(_target), _reference, tolerance_f16);
153}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000154FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
155 framework::dataset::make("DataType", DataType::F16))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100156 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100157{
158 // Validate output
159 validate(Accessor(_target), _reference, tolerance_f16);
160}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000161TEST_SUITE_END() // FP16
162#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
163TEST_SUITE_END() // Float
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100164
Georgios Pinitas55186712018-01-08 17:37:12 +0000165TEST_SUITE(Quantized)
166
167template <typename T>
168using NEPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<Tensor, Accessor, NEPoolingLayer, T>;
169
170TEST_SUITE(QASYMM8)
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100171FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small,
Michalis Spyrou064add62018-11-01 18:14:27 +0000172 framework::dataset::make("DataType", DataType::QASYMM8))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100173 pool_data_layout_dataset))
Georgios Pinitas55186712018-01-08 17:37:12 +0000174{
175 // Validate output
176 validate(Accessor(_target), _reference, tolerance_qasymm8);
177}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000178TEST_SUITE_END() // QASYMM8
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000179TEST_SUITE(QASYMM8_SIGNED)
180FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small,
181 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED))),
182 pool_data_layout_dataset))
183{
184 // Validate output
185 validate(Accessor(_target), _reference, tolerance_qasymm8_s);
186}
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000187TEST_SUITE_END() // QASYMM8_SIGNED
Michalis Spyrou57dac842018-03-01 16:03:50 +0000188TEST_SUITE_END() // Quantized
189TEST_SUITE_END() // PoolingLayer
190TEST_SUITE_END() // NEON
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100191} // namespace validation
192} // namespace test
193} // namespace arm_compute