blob: 133152219faec5853c9b0b003cb6fb79ebb821ce [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"
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{
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000047/** Input data set for floating-point data types */
Isabella Gottardia527e8c2018-01-31 17:49:25 +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) })),
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
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000052/** Input data set for asymmetric data type */
Isabella Gottardia527e8c2018-01-31 17:49:25 +000053const 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 +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) })),
Michalis Spyrou57dac842018-03-01 16:03:50 +000055 framework::dataset::make("ExcludePadding", { true }));
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000056
57constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
58constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000059constexpr 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 +010060} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(PoolingLayer)
64
Georgios Pinitas3faea252017-10-30 14:13:50 +000065// *INDENT-OFF*
66// clang-format off
67DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010068 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
69 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
70 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
71 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
72 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), // Invalid parameters
73 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32), // Non-rectangular Global Pooling
74 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), // Invalid output Global Pooling
75 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32),
Georgios Pinitas3faea252017-10-30 14:13:50 +000076 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010077 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
78 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
79 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32),
80 TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32),
81 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8),
82 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
83 TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32),
84 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
Georgios Pinitas3faea252017-10-30 14:13:50 +000085 })),
86 framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
87 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)),
Georgios Pinitas3faea252017-10-30 14:13:50 +000088 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)),
89 PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)),
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +000090 PoolingLayerInfo(PoolingType::L2, 3, PadStrideInfo(1, 1, 0, 0)),
Georgios Pinitas4c2dd542017-11-13 12:58:41 +000091 PoolingLayerInfo(PoolingType::AVG),
92 PoolingLayerInfo(PoolingType::MAX),
93 PoolingLayerInfo(PoolingType::AVG),
Georgios Pinitas3faea252017-10-30 14:13:50 +000094 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010095 framework::dataset::make("Expected", { false, false, false, false, false, true, false, true })),
Georgios Pinitas3faea252017-10-30 14:13:50 +000096 input_info, output_info, pool_info, expected)
97{
Giorgio Arena9f26b3e2017-11-28 14:35:00 +000098 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 +000099}
100// clang-format on
101// *INDENT-ON*
102
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100103template <typename T>
104using CLPoolingLayerFixture = PoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
105
Georgios Pinitas15997872018-02-19 13:58:22 +0000106template <typename T>
107using CLSpecialPoolingLayerFixture = SpecialPoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
108
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100109TEST_SUITE(Float)
110TEST_SUITE(FP32)
Georgios Pinitas15997872018-02-19 13:58:22 +0000111FIXTURE_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 +0000112{
113 // Validate output
114 validate(CLAccessor(_target), _reference, tolerance_f32);
115}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000116FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
117 DataType::F32))),
Michalis Spyroue74b2012018-04-18 09:49:16 +0100118 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100119{
120 // Validate output
121 validate(CLAccessor(_target), _reference, tolerance_f32);
122}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000123FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
124 framework::dataset::make("DataType",
125 DataType::F32))),
Michalis Spyroue74b2012018-04-18 09:49:16 +0100126 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance_f32);
130}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000131TEST_SUITE_END() // FP32
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100132
133TEST_SUITE(FP16)
Michalis Spyrou57dac842018-03-01 16:03:50 +0000134FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP,
135 framework::dataset::make("DataType", DataType::F16))),
Michalis Spyroue74b2012018-04-18 09:49:16 +0100136 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100137{
138 // Validate output
139 validate(CLAccessor(_target), _reference, tolerance_f16);
140}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000141FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
142 framework::dataset::make("DataType", DataType::F16))),
Michalis Spyroue74b2012018-04-18 09:49:16 +0100143 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100144{
145 // Validate output
146 validate(CLAccessor(_target), _reference, tolerance_f16);
147}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000148TEST_SUITE_END() // FP16
149TEST_SUITE_END() // Float
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100150
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000151TEST_SUITE(Quantized)
152
153template <typename T>
154using CLPoolingLayerQuantizedFixture = PoolingLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPoolingLayer, T>;
155
156TEST_SUITE(QASYMM8)
Michalis Spyrou57dac842018-03-01 16:03:50 +0000157FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQASYMM8,
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000158 framework::dataset::make("DataType", DataType::QASYMM8))),
Michalis Spyrou57dac842018-03-01 16:03:50 +0000159 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127),
160 QuantizationInfo(7.f / 255, 123)
161 })),
Michalis Spyroue74b2012018-04-18 09:49:16 +0100162 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000163{
164 // Validate output
165 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
166}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000167FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQASYMM8,
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000168 framework::dataset::make("DataType", DataType::QASYMM8))),
Michalis Spyrou57dac842018-03-01 16:03:50 +0000169 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) })),
Michalis Spyroue74b2012018-04-18 09:49:16 +0100170 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000171{
172 // Validate output
173 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
174}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000175TEST_SUITE_END() // QASYMM8
176TEST_SUITE_END() // Quantized
Michalis Spyrou57dac842018-03-01 16:03:50 +0000177TEST_SUITE_END() // PoolingLayer
178TEST_SUITE_END() // CL
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100179} // namespace validation
180} // namespace test
181} // namespace arm_compute