blob: 7679007a82f9deb14b49c590c74d692c1fa7a13c [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Isabella Gottardi6e464c32018-01-26 12:32:45 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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 */
Anthony Barbier7068f992017-10-26 15:23:08 +010024#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h"
26#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h"
27#include "arm_compute/runtime/GLES_COMPUTE/functions/GCPoolingLayer.h"
28#include "tests/GLES_COMPUTE/GCAccessor.h"
29#include "tests/PaddingCalculator.h"
30#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"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080046/** Input data set for floating-point data types */
Isabella Gottardi6e464c32018-01-26 12:32:45 +000047const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3), Size2D(4, 4), Size2D(7, 7), Size2D(9, 9) })),
Anthony Barbier7068f992017-10-26 15:23:08 +010048 framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })),
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080049 framework::dataset::make("ExcludePadding", { true, false }));
Anthony Barbier7068f992017-10-26 15:23:08 +010050
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080051constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
52constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
Anthony Barbier7068f992017-10-26 15:23:08 +010053} // namespace
54
55TEST_SUITE(GC)
56TEST_SUITE(PoolingLayer)
57
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080058//clang-format off
59DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
60 framework::dataset::make("InputInfo",
61{
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010062 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
63 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
64 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
65 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid pad/size combination
66 TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32), // Non-rectangular Global Pooling
67 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32), // Invalid output Global Pooling
68 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32),
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080069}),
70framework::dataset::make("OutputInfo",
71{
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010072 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16), TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32), TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32), TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32), TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32),
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080073})),
74framework::dataset::make("PoolInfo",
75{
76 PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)), PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)), PoolingLayerInfo(PoolingType::L2, 3, PadStrideInfo(1, 1, 0, 0)), PoolingLayerInfo(PoolingType::AVG), PoolingLayerInfo(PoolingType::MAX), PoolingLayerInfo(PoolingType::AVG),
77})),
78framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, true })),
79input_info, output_info, pool_info, expected)
80{
81 ARM_COMPUTE_EXPECT(bool(GCPoolingLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info)) == expected, framework::LogLevel::ERRORS);
82}
83//clang-format on
84
Anthony Barbier7068f992017-10-26 15:23:08 +010085template <typename T>
86using GCPoolingLayerFixture = PoolingLayerValidationFixture<GCTensor, GCAccessor, GCPoolingLayer, T>;
87
88TEST_SUITE(Float)
89TEST_SUITE(FP32)
Michalis Spyrou57dac842018-03-01 16:03:50 +000090FIXTURE_DATA_TEST_CASE(RunSmall, GCPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType",
91 DataType::F32))),
92 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier7068f992017-10-26 15:23:08 +010093{
Anthony Barbier7068f992017-10-26 15:23:08 +010094 // Validate output
Xinghang Zhou53a6ec52017-11-14 15:14:25 +080095 validate(GCAccessor(_target), _reference, tolerance_f32);
Anthony Barbier7068f992017-10-26 15:23:08 +010096}
Michalis Spyrou57dac842018-03-01 16:03:50 +000097FIXTURE_DATA_TEST_CASE(RunLarge, GCPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
98 framework::dataset::make("DataType",
99 DataType::F32))),
100 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier7068f992017-10-26 15:23:08 +0100101{
Anthony Barbier7068f992017-10-26 15:23:08 +0100102 // Validate output
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800103 validate(GCAccessor(_target), _reference, tolerance_f32);
Anthony Barbier7068f992017-10-26 15:23:08 +0100104}
105TEST_SUITE_END()
106
107TEST_SUITE(FP16)
Michalis Spyrou57dac842018-03-01 16:03:50 +0000108FIXTURE_DATA_TEST_CASE(RunSmall, GCPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP,
109 framework::dataset::make("DataType", DataType::F16))),
110 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier7068f992017-10-26 15:23:08 +0100111{
Anthony Barbier7068f992017-10-26 15:23:08 +0100112 // Validate output
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800113 validate(GCAccessor(_target), _reference, tolerance_f16);
Anthony Barbier7068f992017-10-26 15:23:08 +0100114}
Michalis Spyrou57dac842018-03-01 16:03:50 +0000115FIXTURE_DATA_TEST_CASE(RunLarge, GCPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP,
116 framework::dataset::make("DataType", DataType::F16))),
117 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier7068f992017-10-26 15:23:08 +0100118{
Anthony Barbier7068f992017-10-26 15:23:08 +0100119 // Validate output
Xinghang Zhou53a6ec52017-11-14 15:14:25 +0800120 validate(GCAccessor(_target), _reference, tolerance_f16);
Anthony Barbier7068f992017-10-26 15:23:08 +0100121}
122TEST_SUITE_END()
123TEST_SUITE_END()
124
125TEST_SUITE_END()
126TEST_SUITE_END()
127} // namespace validation
128} // namespace test
129} // namespace arm_compute