blob: 129f53bef27ed665f34c31edddf7a73edd06746b [file] [log] [blame]
Georgios Pinitasdc460f12017-08-24 19:02:44 +01001/*
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +00002 * Copyright (c) 2017-2019 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
Georgios Pinitas55186712018-01-08 17:37:12 +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 */
Georgios Pinitas55186712018-01-08 17:37:12 +000069constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric type */
Pablo Telloa52e4cf2019-04-01 14:55:18 +010070const auto pool_data_layout_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC });
71
Georgios Pinitasdc460f12017-08-24 19:02:44 +010072} // namespace
73
74TEST_SUITE(NEON)
75TEST_SUITE(PoolingLayer)
76
Michalis Spyrouafa5d812017-11-30 14:25:57 +000077// *INDENT-OFF*
78// clang-format off
79DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010080 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
81 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
83 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
84 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32), // Non-rectangular Global Pooling
85 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), // Invalid output Global Pooling
86 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +000087 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010088 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
89 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32),
90 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32),
91 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32),
92 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
93 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32),
94 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
Michalis Spyrouafa5d812017-11-30 14:25:57 +000095 })),
96 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
97 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
Michalis Spyrouafa5d812017-11-30 14:25:57 +000098 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)),
99 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)),
100 PoolingLayerInfo(PoolingType::AVG),
101 PoolingLayerInfo(PoolingType::MAX),
102 PoolingLayerInfo(PoolingType::AVG),
103 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +0100104 framework::dataset::make("Expected", { false, false, false, false, true, false, false, true })),
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000105 input_info, output_info, pool_info, expected)
106{
107 bool is_valid = bool(NEPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info));
108 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
109}
110// clang-format on
111// *INDENT-ON*
112
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100113template <typename T>
114using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>;
115
Georgios Pinitas15997872018-02-19 13:58:22 +0000116template <typename T>
117using NESpecialPoolingLayerFixture = SpecialPoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>;
118
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100119TEST_SUITE(Float)
120TEST_SUITE(FP32)
Georgios Pinitas15997872018-02-19 13:58:22 +0000121FIXTURE_DATA_TEST_CASE(RunSpecial, NESpecialPoolingLayerFixture<float>, framework::DatasetMode::ALL, datasets::PoolingLayerDatasetSpecial() * framework::dataset::make("DataType", DataType::F32))
122{
123 // Validate output
124 validate(Accessor(_target), _reference, tolerance_f32);
125}
Michalis Spyrou064add62018-11-01 18:14:27 +0000126FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall,
127 framework::dataset::make("DataType",
128 DataType::F32))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100129 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100130{
131 // Validate output
132 validate(Accessor(_target), _reference, tolerance_f32);
133}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000134FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
135 framework::dataset::make("DataType",
136 DataType::F32))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100137 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100138{
139 // Validate output
140 validate(Accessor(_target), _reference, tolerance_f32);
141}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000142TEST_SUITE_END() // FP32
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100143
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000144#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100145TEST_SUITE(FP16)
Michalis Spyrou064add62018-11-01 18:14:27 +0000146FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFPSmall,
147 framework::dataset::make("DataType", DataType::F16))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100148 pool_data_layout_dataset))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100149{
150 // Validate output
151 validate(Accessor(_target), _reference, tolerance_f16);
152}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000153FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
154 framework::dataset::make("DataType", DataType::F16))),
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(Accessor(_target), _reference, tolerance_f16);
159}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000160TEST_SUITE_END() // FP16
161#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
162TEST_SUITE_END() // Float
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100163
Georgios Pinitas55186712018-01-08 17:37:12 +0000164TEST_SUITE(Quantized)
165
166template <typename T>
167using NEPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<Tensor, Accessor, NEPoolingLayer, T>;
168
169TEST_SUITE(QASYMM8)
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100170FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8Small,
Michalis Spyrou064add62018-11-01 18:14:27 +0000171 framework::dataset::make("DataType", DataType::QASYMM8))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100172 pool_data_layout_dataset))
Georgios Pinitas55186712018-01-08 17:37:12 +0000173{
174 // Validate output
175 validate(Accessor(_target), _reference, tolerance_qasymm8);
176}
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100177FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8,
Georgios Pinitas55186712018-01-08 17:37:12 +0000178 framework::dataset::make("DataType", DataType::QASYMM8))),
Pablo Telloa52e4cf2019-04-01 14:55:18 +0100179 pool_data_layout_dataset))
Georgios Pinitas55186712018-01-08 17:37:12 +0000180{
181 // Validate output
182 validate(Accessor(_target), _reference, tolerance_qasymm8);
183}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000184TEST_SUITE_END() // QASYMM8
185TEST_SUITE_END() // Quantized
186TEST_SUITE_END() // PoolingLayer
187TEST_SUITE_END() // NEON
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100188} // namespace validation
189} // namespace test
190} // namespace arm_compute