1 /*
2 * Copyright (c) 2023 Arm Limited.
3 *
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
25 #include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h"
26
27 #include "tests/CL/CLAccessor.h"
28 #include "tests/datasets/ShapeDatasets.h"
29 #include "tests/datasets/dynamic_fusion/PoolingLayerDataset.h"
30 #include "tests/framework/Fixture.h"
31 #include "tests/framework/Macros.h"
32 #include "tests/framework/datasets/Datasets.h"
33 #include "tests/validation/Validation.h"
34 #include "tests/validation/fixtures/dynamic_fusion/gpu/cl/Pool2dFixture.h"
35
36 namespace arm_compute
37 {
38 namespace test
39 {
40 namespace validation
41 {
42 TEST_SUITE(CL)
43 TEST_SUITE(DYNAMIC_FUSION)
44 TEST_SUITE(POOL2D)
45
46 constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
47 constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
48
49 const auto PoolingLayerDatasetFP = combine(combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })),
50 framework::dataset::make("Pad", { Padding2D() })),
51 framework::dataset::make("Stride", { Size2D(1, 1), Size2D(2, 1), Size2D(5, 7) })),
52 framework::dataset::make("ExcludePadding", { true }));
53
54 const auto pool_fp_mixed_precision_dataset = framework::dataset::make("FpMixedPrecision", { true, false });
55
56 template <typename T>
57 using DynamicFusionGpuPool2dFixture = DynamicFusionGpuPool2dValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>;
58
59 template <typename T>
60 using DFSpecialGpuPool2dFixture = DynamicFusionGpuPool2dSpecialValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>;
61
62 template <typename T>
63 using DFPoolMixedPrecisionFixture = DynamicFusionGpuPool2dMixedPrecisionValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>;
64 // *INDENT-OFF*
65 // clang-format off
66
67 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
68 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Mismatching data type
69 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid pad/size combination
70 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid pad/size combination
71 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC), // Invalid parameters, unsupported pooling
72 TensorInfo(TensorShape(5U, 15U, 13U), 1, DataType::F32, DataLayout::NHWC), // Valid Non-rectangular Global Pooling
73 TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid output Global Pooling
74 TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC), // Invalid - Quantized not supported.
75 TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::F32, DataLayout::NHWC), // Valid global pooling
76 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, DataLayout::NCHW), // Unsupported data layout
77 }),
78 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(2U, 25U, 11U), 1, DataType::F16, DataLayout::NHWC),
79 TensorInfo(TensorShape(2U, 30U, 11U), 1, DataType::F32, DataLayout::NHWC),
80 TensorInfo(TensorShape(2U, 25U, 16U), 1, DataType::F32, DataLayout::NHWC),
81 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC),
82 TensorInfo(TensorShape(5U, 1U, 1U), 1, DataType::F32, DataLayout::NHWC),
83 TensorInfo(TensorShape(5U, 2U, 2U), 1, DataType::F32, DataLayout::NHWC),
84 TensorInfo(TensorShape(5U, 12U, 12U), 1, DataType::QASYMM8, DataLayout::NHWC),
85 TensorInfo(TensorShape(5U, 1U, 1U), 1, DataType::F32, DataLayout::NHWC),
86 TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, DataLayout::NHWC),
87 })),
88 framework::dataset::make("Pool2dAttributes", {
89 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(3,3)).pad(Padding2D(0,0,0,0)).stride(Size2D(1,1)),
90 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(2,2)).pad(Padding2D(2,2,0,0)).stride(Size2D(1,1)),
91 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(2,2)).pad(Padding2D(0,0,2,2)).stride(Size2D(1,1)),
92 Pool2dAttributes().pool_type(PoolingType::L2).pool_size(Size2D(3,3)).pad(Padding2D(0,0,0,0)).stride(Size2D(1,1)),
93 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(15U, 13U)),
94 Pool2dAttributes().pool_type(PoolingType::MAX).pool_size(Size2D(13U, 13U)),
95 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(2,2)).pad(Padding2D()).stride(Size2D(1,1)),
96 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(13U,13U)),
97 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(13U,13U)),
98 })),
99 framework::dataset::make("Expected", { false, false, false, false, true, false, false, true, false })),
100 input_info, output_info, pool2d_attr, expected)
101 {
102 // Create a new workload sketch
103 auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
104 auto gpu_ctx = GpuWorkloadContext{ &cl_compile_ctx };
105 GpuWorkloadSketch sketch{ &gpu_ctx };
106
107 // Declare GpuPool2d settings
108 const GpuPool2dSettings &settings = GpuPool2dSettings().mixed_precision(false);
109
110 // Validate Pool2d Configuration
111 auto src_info = sketch.create_tensor_info(input_info);
112 auto dst_info = sketch.create_tensor_info(output_info);
113 bool res = bool(GpuPool2d::validate_op(sketch, &src_info, &dst_info, pool2d_attr, settings));
114 ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
115 }
116
117 // clang-format on
118 // *INDENT-ON*
119
120 TEST_SUITE(Float)
TEST_SUITE(FP32)121 TEST_SUITE(FP32)
122 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallNoneUnitShapes(), PoolingLayerDatasetFP),
123 framework::dataset::make("DataType", DataType::F32)))
124 {
125 // Validate output
126 validate(CLAccessor(_target), _reference, tolerance_f32);
127 }
128 FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), PoolingLayerDatasetFP),
129 framework::dataset::make("DataType", DataType::F32)))
130 {
131 // Validate output
132 validate(CLAccessor(_target), _reference, tolerance_f32);
133 }
134 FIXTURE_DATA_TEST_CASE(RunSpecial, DFSpecialGpuPool2dFixture<float>, framework::DatasetMode::ALL, combine(datasets::PoolingLayerDatasetSpecialDynamicFusion(),
135 framework::dataset::make("DataType", DataType::F32)))
136 {
137 // Validate output
138 validate(CLAccessor(_target), _reference, tolerance_f32);
139 }
140
141 TEST_SUITE(GlobalPooling)
142 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::ALL,
143 combine(combine(combine(combine(combine(combine(
144 framework::dataset::make("InputShape", { TensorShape(27U, 13U, 2U),
145 TensorShape(27U, 13U, 2U, 4U)
146 }),
147 framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })),
148 framework::dataset::make("PoolingSize", { Size2D(27, 13) })),
149 framework::dataset::make("Pad", { Padding2D() })),
150 framework::dataset::make("Stride", { Size2D(1, 1) })),
151 framework::dataset::make("ExcludePadding", true)),
152 framework::dataset::make("DataType", DataType::F32)))
153 {
154 // Validate output
155 validate(CLAccessor(_target), _reference, tolerance_f32);
156 }
157
158 FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::NIGHTLY,
159 combine(combine(combine(combine(combine(combine(
160 framework::dataset::make("InputShape", { TensorShape(79U, 37U, 11U),
161 TensorShape(79U, 37U, 11U, 4U)
162 }),
163 framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })),
164 framework::dataset::make("PoolingSize", { Size2D(79, 37) })),
165 framework::dataset::make("Pad", { Padding2D() })),
166 framework::dataset::make("Stride", { Size2D(1, 1) })),
167 framework::dataset::make("ExcludePadding", true)),
168 framework::dataset::make("DataType", DataType::F32)))
169 {
170 // Validate output
171 validate(CLAccessor(_target), _reference, tolerance_f32);
172 }
173 TEST_SUITE_END() // GlobalPooling
TEST_SUITE_END()174 TEST_SUITE_END() // FP32
175
176 TEST_SUITE(FP16)
177 FIXTURE_DATA_TEST_CASE(RunSmall, DFPoolMixedPrecisionFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallNoneUnitShapes(), PoolingLayerDatasetFP),
178 framework::dataset::make("DataType", DataType::F16)),
179 pool_fp_mixed_precision_dataset))
180 {
181 // Validate output
182 validate(CLAccessor(_target), _reference, tolerance_f16);
183 }
184 FIXTURE_DATA_TEST_CASE(RunLarge, DFPoolMixedPrecisionFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), PoolingLayerDatasetFP),
185 framework::dataset::make("DataType", DataType::F16)),
186 pool_fp_mixed_precision_dataset))
187 {
188 // Validate output
189 validate(CLAccessor(_target), _reference, tolerance_f16);
190 }
191
192 TEST_SUITE(GlobalPooling)
193 FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuPool2dFixture<half>, framework::DatasetMode::ALL,
194 combine(combine(combine(combine(combine(combine(
195 framework::dataset::make("InputShape", { TensorShape(27U, 13U, 2U),
196 TensorShape(27U, 13U, 2U, 4U)
197 }),
198 framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })),
199 framework::dataset::make("PoolingSize", { Size2D(27, 13) })),
200 framework::dataset::make("Pad", { Padding2D() })),
201 framework::dataset::make("Stride", { Size2D(1, 1) })),
202 framework::dataset::make("ExcludePadding", true)),
203 framework::dataset::make("DataType", DataType::F16)))
204 {
205 // Validate output
206 validate(CLAccessor(_target), _reference, tolerance_f16);
207 }
208
209 FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuPool2dFixture<half>, framework::DatasetMode::NIGHTLY,
210 combine(combine(combine(combine(combine(combine(
211 framework::dataset::make("InputShape", { TensorShape(79U, 37U, 11U),
212 TensorShape(79U, 37U, 11U, 4U)
213 }),
214 framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })),
215 framework::dataset::make("PoolingSize", { Size2D(79, 37) })),
216 framework::dataset::make("Pad", { Padding2D() })),
217 framework::dataset::make("Stride", { Size2D(1, 1) })),
218 framework::dataset::make("ExcludePadding", true)),
219 framework::dataset::make("DataType", DataType::F16)))
220 {
221 // Validate output
222 validate(CLAccessor(_target), _reference, tolerance_f16);
223 }
224 TEST_SUITE_END() // GlobalPooling
225 TEST_SUITE_END() // FP16
226 TEST_SUITE_END() // FLOAT
227
228 TEST_SUITE_END() // POOL2D
229 TEST_SUITE_END() // DYNAMIC_FUSION
230 TEST_SUITE_END() // CL
231 }
232 }
233 }
234