blob: be816b32b3e8238d5ffc86ba1a752d50fe49dd58 [file] [log] [blame]
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +00001/*
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +00002 * Copyright (c) 2023-2024 Arm Limited.
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +00003 *
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 */
Gunes Bayir0ee13af2024-02-07 15:34:45 +000024
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000025#include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h"
26
27#include "tests/CL/CLAccessor.h"
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000028#include "tests/datasets/dynamic_fusion/PoolingLayerDataset.h"
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000029#include "tests/datasets/ShapeDatasets.h"
30#include "tests/framework/datasets/Datasets.h"
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000031#include "tests/framework/Fixture.h"
32#include "tests/framework/Macros.h"
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000033#include "tests/validation/fixtures/dynamic_fusion/gpu/cl/Pool2dFixture.h"
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000034#include "tests/validation/Validation.h"
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000035
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42TEST_SUITE(CL)
43TEST_SUITE(DYNAMIC_FUSION)
44TEST_SUITE(POOL2D)
45
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000046constexpr AbsoluteTolerance<float> tolerance_f32(
47 0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */
48constexpr AbsoluteTolerance<float> tolerance_f16(
49 0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000050
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000051const auto PoolingLayerDatasetFP =
52 combine(combine(combine(combine(framework::dataset::make("PoolingType", {PoolingType::MAX, PoolingType::AVG}),
53 framework::dataset::make("PoolingSize", {Size2D(2, 2), Size2D(3, 3)})),
54 framework::dataset::make("Pad", {Padding2D()})),
55 framework::dataset::make("Stride", {Size2D(1, 1), Size2D(2, 1), Size2D(5, 7)})),
56 framework::dataset::make("ExcludePadding", {true}));
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000057
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000058template <typename T>
59using DynamicFusionGpuPool2dFixture = DynamicFusionGpuPool2dValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>;
60
61template <typename T>
62using DFSpecialGpuPool2dFixture = DynamicFusionGpuPool2dSpecialValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>;
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000063// *INDENT-OFF*
64// clang-format off
65
Jakub Sujake57eea32023-09-04 16:53:37 +010066DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
67 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC), // Invalid parameters, unsupported pooling
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000068 TensorInfo(TensorShape(5U, 15U, 13U), 1, DataType::F32, DataLayout::NHWC), // Valid Non-rectangular Global Pooling
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000069 TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC), // Invalid - Quantized not supported.
70 TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::F32, DataLayout::NHWC), // Valid global pooling
71 TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, DataLayout::NCHW), // Unsupported data layout
72 }),
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000073 framework::dataset::make("Pool2dAttributes", {
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000074 Pool2dAttributes().pool_type(PoolingType::L2).pool_size(Size2D(3,3)).pad(Padding2D(0,0,0,0)).stride(Size2D(1,1)),
75 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(15U, 13U)),
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000076 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(2,2)).pad(Padding2D()).stride(Size2D(1,1)),
77 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(13U,13U)),
78 Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(13U,13U)),
79 })),
Jakub Sujake57eea32023-09-04 16:53:37 +010080 framework::dataset::make("Expected", { false, true, false, true, false })),
81 input_info, pool2d_attr, expected)
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000082{
83 // Create a new workload sketch
84 auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010085 auto context = GpuWorkloadContext{ &cl_compile_ctx };
86 GpuWorkloadSketch sketch{ &context };
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000087
88 // Declare GpuPool2d settings
Gunes Bayir2b9fa592024-01-17 16:07:03 +000089 const GpuPool2dSettings &settings = GpuPool2dSettings();
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000090
91 // Validate Pool2d Configuration
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010092 auto src_info = context.create_tensor_info(input_info);
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000093 bool res = bool(GpuPool2d::validate_op(sketch, src_info, pool2d_attr, settings));
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +000094 ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS);
95}
96
97// clang-format on
98// *INDENT-ON*
99
100TEST_SUITE(Float)
101TEST_SUITE(FP32)
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000102FIXTURE_DATA_TEST_CASE(RunSmall,
103 DynamicFusionGpuPool2dFixture<float>,
104 framework::DatasetMode::PRECOMMIT,
105 combine(combine(datasets::SmallNoneUnitShapes(), PoolingLayerDatasetFP),
106 framework::dataset::make("DataType", DataType::F32)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000107{
108 // Validate output
109 validate(CLAccessor(_target), _reference, tolerance_f32);
110}
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000111FIXTURE_DATA_TEST_CASE(RunLarge,
112 DynamicFusionGpuPool2dFixture<float>,
113 framework::DatasetMode::NIGHTLY,
114 combine(combine(datasets::LargeShapes(), PoolingLayerDatasetFP),
115 framework::dataset::make("DataType", DataType::F32)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance_f32);
119}
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000120FIXTURE_DATA_TEST_CASE(RunSpecial,
121 DFSpecialGpuPool2dFixture<float>,
122 framework::DatasetMode::ALL,
123 combine(datasets::PoolingLayerDatasetSpecialDynamicFusion(),
124 framework::dataset::make("DataType", DataType::F32)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000125{
126 // Validate output
127 validate(CLAccessor(_target), _reference, tolerance_f32);
128}
129
130TEST_SUITE(GlobalPooling)
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000131FIXTURE_DATA_TEST_CASE(
132 RunSmall,
133 DynamicFusionGpuPool2dFixture<float>,
134 framework::DatasetMode::ALL,
135 combine(combine(combine(combine(combine(combine(framework::dataset::make("InputShape",
136 {TensorShape(27U, 13U, 2U),
137 TensorShape(27U, 13U, 2U, 4U)}),
138 framework::dataset::make("PoolingType",
139 {PoolingType::AVG, PoolingType::MAX})),
140 framework::dataset::make("PoolingSize", {Size2D(27, 13)})),
141 framework::dataset::make("Pad", {Padding2D()})),
142 framework::dataset::make("Stride", {Size2D(1, 1)})),
143 framework::dataset::make("ExcludePadding", true)),
144 framework::dataset::make("DataType", DataType::F32)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000145{
146 // Validate output
147 validate(CLAccessor(_target), _reference, tolerance_f32);
148}
149
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000150FIXTURE_DATA_TEST_CASE(
151 RunLarge,
152 DynamicFusionGpuPool2dFixture<float>,
153 framework::DatasetMode::NIGHTLY,
154 combine(combine(combine(combine(combine(combine(framework::dataset::make("InputShape",
155 {TensorShape(79U, 37U, 11U),
156 TensorShape(79U, 37U, 11U, 4U)}),
157 framework::dataset::make("PoolingType",
158 {PoolingType::AVG, PoolingType::MAX})),
159 framework::dataset::make("PoolingSize", {Size2D(79, 37)})),
160 framework::dataset::make("Pad", {Padding2D()})),
161 framework::dataset::make("Stride", {Size2D(1, 1)})),
162 framework::dataset::make("ExcludePadding", true)),
163 framework::dataset::make("DataType", DataType::F32)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000164{
165 // Validate output
166 validate(CLAccessor(_target), _reference, tolerance_f32);
167}
168TEST_SUITE_END() // GlobalPooling
169TEST_SUITE_END() // FP32
170
171TEST_SUITE(FP16)
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000172TEST_SUITE(GlobalPooling)
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000173FIXTURE_DATA_TEST_CASE(
174 RunSmall,
175 DynamicFusionGpuPool2dFixture<half>,
176 framework::DatasetMode::ALL,
177 combine(combine(combine(combine(combine(combine(framework::dataset::make("InputShape",
178 {TensorShape(27U, 13U, 2U),
179 TensorShape(27U, 13U, 2U, 4U)}),
180 framework::dataset::make("PoolingType",
181 {PoolingType::AVG, PoolingType::MAX})),
182 framework::dataset::make("PoolingSize", {Size2D(27, 13)})),
183 framework::dataset::make("Pad", {Padding2D()})),
184 framework::dataset::make("Stride", {Size2D(1, 1)})),
185 framework::dataset::make("ExcludePadding", true)),
186 framework::dataset::make("DataType", DataType::F16)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000187{
188 // Validate output
189 validate(CLAccessor(_target), _reference, tolerance_f16);
190}
191
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000192FIXTURE_DATA_TEST_CASE(
193 RunLarge,
194 DynamicFusionGpuPool2dFixture<half>,
195 framework::DatasetMode::NIGHTLY,
196 combine(combine(combine(combine(combine(combine(framework::dataset::make("InputShape",
197 {TensorShape(79U, 37U, 11U),
198 TensorShape(79U, 37U, 11U, 4U)}),
199 framework::dataset::make("PoolingType",
200 {PoolingType::AVG, PoolingType::MAX})),
201 framework::dataset::make("PoolingSize", {Size2D(79, 37)})),
202 framework::dataset::make("Pad", {Padding2D()})),
203 framework::dataset::make("Stride", {Size2D(1, 1)})),
204 framework::dataset::make("ExcludePadding", true)),
205 framework::dataset::make("DataType", DataType::F16)))
Mohammed Suhail Munshia18d85c2023-01-03 10:16:16 +0000206{
207 // Validate output
208 validate(CLAccessor(_target), _reference, tolerance_f16);
209}
210TEST_SUITE_END() // GlobalPooling
211TEST_SUITE_END() // FP16
212TEST_SUITE_END() // FLOAT
213
214TEST_SUITE_END() // POOL2D
215TEST_SUITE_END() // DYNAMIC_FUSION
216TEST_SUITE_END() // CL
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000217} // namespace validation
218} // namespace test
219} // namespace arm_compute