blob: bae8cbf868d8ff756eacd32dffbbfc3d23952910 [file] [log] [blame]
Ramy Elgammal73f19af2022-10-23 11:44:49 +01001/*
SiCong Li5a63d1e2023-01-06 16:28:57 +00002 * Copyright (c) 2022-2023 Arm Limited.
Ramy Elgammal73f19af2022-10-23 11:44:49 +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
Ramy Elgammal73f19af2022-10-23 11:44:49 +010025#include "tests/AssetsLibrary.h"
26#include "tests/CL/CLAccessor.h"
Ramy Elgammal73f19af2022-10-23 11:44:49 +010027#include "tests/framework/Fixture.h"
28#include "tests/framework/Macros.h"
29#include "tests/framework/datasets/Datasets.h"
30#include "tests/validation/Validation.h"
31#include "tests/validation/reference/ConvolutionLayer.h"
32
33#include "tests/datasets/SmallConvolutionLayerDataset.h"
34#include "tests/validation/fixtures/dynamic_fusion/gpu/cl/DirectConv2dFixture.h"
35
Ramy Elgammal73f19af2022-10-23 11:44:49 +010036namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
SiCong Li5a63d1e2023-01-06 16:28:57 +000042namespace
43{
SiCong Li54eafd82023-01-26 17:36:08 +000044/** Tolerances from tests/validation/CL/DirectConvolutionLayer.cpp
45 */
SiCong Li5a63d1e2023-01-06 16:28:57 +000046RelativeTolerance<float> tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
48constexpr float abs_tolerance_f32(0.0001f); /**< Absolute tolerance for FP32 tests*/
SiCong Li54eafd82023-01-26 17:36:08 +000049constexpr float tolerance_num = 0.07f; /**< Tolerance number */
SiCong Li5a63d1e2023-01-06 16:28:57 +000050} // namespace
51
Ramy Elgammal73f19af2022-10-23 11:44:49 +010052TEST_SUITE(CL)
53TEST_SUITE(DYNAMIC_FUSION)
SiCong Li54eafd82023-01-26 17:36:08 +000054/** Synced with tests/validation/CL/ConvolutionLayer.cpp
55 *
56 * Difference | Why the difference
57 * f32 tolerance here is smaller | To use the same tolerance as that of DirectConv2d; lowering tolerance is safe
58 * No quantized tests | Not supported yet
59 * No grouped CNN tests | Not supported yet
60 * No mixed layout tests | Not needed; only NHWC is supported
Jakub Sujak0d27b2e2023-08-24 14:01:20 +010061 * No activation | Not needed in fusion
SiCong Li54eafd82023-01-26 17:36:08 +000062 * No ValidateConvolutionMethod | Only a single method (direct conv2d) is supported
63 * No ReshapeWeights = true tests | Not applicable yet. This parameter only concerns gemm-based conv2d
64 * No RunSmallWithPadding tests | Padding is removed
65 *
66 */
Ramy Elgammal404462a2022-11-08 02:14:46 +000067TEST_SUITE(CONV2D)
Ramy Elgammal73f19af2022-10-23 11:44:49 +010068
Ramy Elgammal73f19af2022-10-23 11:44:49 +010069template <typename T>
70using DynamicFusionGpuConv2dFixture = DynamicFusionGpuConv2dValidationFixture<CLTensor, CLAccessor, GpuConv2d, T>;
71TEST_SUITE(FP32)
72FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuConv2dFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
Jakub Sujak0d27b2e2023-08-24 14:01:20 +010073 framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("DataLayout", { DataLayout::NHWC })), framework::dataset::make("QuantizationInfo", QuantizationInfo())))
Ramy Elgammal73f19af2022-10-23 11:44:49 +010074{
75 // Validate output
76 validate(CLAccessor(_target), _reference, tolerance_f32);
77}
78TEST_SUITE_END() // FP32
79
Ramy Elgammal73f19af2022-10-23 11:44:49 +010080TEST_SUITE(FP16)
81FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuConv2dFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
Jakub Sujak0d27b2e2023-08-24 14:01:20 +010082 framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("DataLayout", { DataLayout::NHWC })), framework::dataset::make("QuantizationInfo", QuantizationInfo())))
Ramy Elgammal73f19af2022-10-23 11:44:49 +010083{
84 // Validate output
85 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
86}
87TEST_SUITE_END() // FP16
Ramy Elgammal73f19af2022-10-23 11:44:49 +010088
SiCong Li5a63d1e2023-01-06 16:28:57 +000089// Tests for specific conv2d methods
SiCong Li54eafd82023-01-26 17:36:08 +000090/** Synced with tests/validation/CL/DirectConvolutionLayer.cpp
91 *
92 * Difference | Why the difference
93 * No quantized tests | Not supported yet
94 * No Invalid output size test | Not applicable. Output is removed from the interface
95 * No mixed layout/NCHW tests | Not needed; only NHWC is supported
96 * No activation tests | Not needed in fusion
97 */
SiCong Li5a63d1e2023-01-06 16:28:57 +000098TEST_SUITE(DIRECT_CONV2D)
99
100// *INDENT-OFF*
101// clang-format off
102DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
103 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid: Mismatching data type input/weights
104 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid: Mismatching input feature maps
105 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid weights dimensions
106 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Unsupported biases size
107 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Unsupported biases dimensions
108 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, DataLayout::NCHW), // Unsupported data layout: NCHW
109 TensorInfo(TensorShape(2U, 32U, 16U), 1, DataType::QASYMM8, DataLayout::NHWC), // Unsupported data type: quantized
110 TensorInfo(TensorShape(2U, 32U, 16U), 1, DataType::F32, DataLayout::NHWC),
111 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Arbitrary weight sizes for NHWC are supported
112 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Non-rectangular weights dimensions for NHWC are supported
113 TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Strides > 2 for any kernel sizes for NHWC are supported
114 }),
115 framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F16, DataLayout::NHWC),
116 TensorInfo(TensorShape(3U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC),
117 TensorInfo(TensorShape(2U, 3U, 3U, 4U, 3U), 1, DataType::F32, DataLayout::NHWC),
118 TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC),
119 TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC),
120 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, DataLayout::NCHW),
121 TensorInfo(TensorShape(2U, 1U, 1U, 4U), 1, DataType::QASYMM8, DataLayout::NHWC),
122 TensorInfo(TensorShape(2U, 1U, 1U, 4U), 1, DataType::F32, DataLayout::NHWC),
123 TensorInfo(TensorShape(2U, 13U, 13U, 4U), 1, DataType::F32, DataLayout::NHWC),
124 TensorInfo(TensorShape(2U, 5U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC),
125 TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC),
126 })),
127 framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
128 TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
129 TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
130 TensorInfo(TensorShape(3U), 1, DataType::F32, DataLayout::NHWC),
131 TensorInfo(TensorShape(4U, 2U), 1, DataType::F32, DataLayout::NHWC),
132 TensorInfo(TensorShape(25U), 1, DataType::F32, DataLayout::NCHW),
133 TensorInfo(TensorShape(4U), 1, DataType::QASYMM8, DataLayout::NHWC),
134 TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
135 TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
136 TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
137 TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC),
138 })),
139 framework::dataset::make("Conv2dAttributes", {
140 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
141 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
142 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
143 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
144 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
145 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
146 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
147 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
148 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
149 Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}),
150 Conv2dAttributes().stride({3, 3}).pad({0, 0, 0, 0}),
151 })),
152 framework::dataset::make("Expected", { false, false, false, false, false, false, false, true, true, true, true })),
153 input_info, weights_info, biases_info, conv2d_attrs, expected)
154{
155 auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context();
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +0100156 auto context = GpuWorkloadContext{ &cl_compile_ctx };
157 GpuWorkloadSketch sketch{ &context };
SiCong Li5a63d1e2023-01-06 16:28:57 +0000158
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +0100159 const TensorInfo sketch_input_info = context.create_tensor_info(input_info);
160 const TensorInfo sketch_weights_info = context.create_tensor_info(weights_info);
161 const TensorInfo sketch_biases_info = context.create_tensor_info(biases_info);
SiCong Li5a63d1e2023-01-06 16:28:57 +0000162 bool is_valid = bool(GpuConv2d::validate_op(sketch, &sketch_input_info, &sketch_weights_info, &sketch_biases_info, conv2d_attrs));
163 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
164}
165template <typename T>
166using DynamicFusionGpuDirectConv2dFixture = DynamicFusionDirectConv2dValidationFixture<CLTensor, CLAccessor, GpuConv2d, T>;
167
168TEST_SUITE(FP16)
169FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuDirectConv2dFixture<half>, framework::DatasetMode::PRECOMMIT,
170 combine(combine(combine(zip(zip(zip(zip(zip(
171 framework::dataset::make("InputShape", { TensorShape(27U, 13U, 23U),
172 TensorShape(19U, 5U, 16U, 4U),
173 TensorShape(13U, 5U, 17U, 2U),
174 TensorShape(32U, 37U, 13U) } ),
175 framework::dataset::make("StrideX", { 1, 3, 1, 1 })),
176 framework::dataset::make("StrideY", { 1, 3, 2, 1 })),
177 framework::dataset::make("PadX", { 1, 3, 0, 4 })),
178 framework::dataset::make("PadY", { 1, 3, 0, 4 })),
179 framework::dataset::make("KernelSize", { 3, 8, 1, 9 })),
180 framework::dataset::make("NumKernels", { 17, 3, 1, 19 })),
181 framework::dataset::make("DataType", DataType::F16)),
182 framework::dataset::make("DataLayout", DataLayout::NHWC)))
183{
184 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
185}
186
187FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuDirectConv2dFixture<half>, framework::DatasetMode::NIGHTLY,
188 combine(combine(combine(zip(zip(zip(zip(zip(
189 framework::dataset::make("InputShape", { TensorShape(800U, 800U, 3U) } ),
190 framework::dataset::make("StrideX", { 1 })),
191 framework::dataset::make("StrideY", { 1 })),
192 framework::dataset::make("PadX", { 1 })),
193 framework::dataset::make("PadY", { 1 })),
194 framework::dataset::make("KernelSize", { 9 })),
195 framework::dataset::make("NumKernels", { 3 })),
196 framework::dataset::make("DataType", DataType::F16)),
197 framework::dataset::make("DataLayout", DataLayout::NHWC)))
198{
199 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
200}
201
202TEST_SUITE_END() // FP16
203
204TEST_SUITE(FP32)
205FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuDirectConv2dFixture<float>, framework::DatasetMode::PRECOMMIT,
206 combine(combine(combine(zip(zip(zip(zip(zip(
207 framework::dataset::make("InputShape", { TensorShape(27U, 13U, 23U),
208 TensorShape(19U, 5U, 16U, 4U),
209 TensorShape(13U, 5U, 17U, 2U),
210 TensorShape(32U, 37U, 13U) } ),
211 framework::dataset::make("StrideX", { 1, 3, 1, 1 })),
212 framework::dataset::make("StrideY", { 1, 3, 2, 1 })),
213 framework::dataset::make("PadX", { 1, 3, 0, 4 })),
214 framework::dataset::make("PadY", { 1, 3, 0, 4 })),
215 framework::dataset::make("KernelSize", { 3, 8, 1, 9 })),
216 framework::dataset::make("NumKernels", { 17, 3, 1, 19 })),
217 framework::dataset::make("DataType", DataType::F32)),
218 framework::dataset::make("DataLayout", DataLayout::NHWC)))
219{
220 validate(CLAccessor(_target), _reference, tolerance_f32, 0.0, abs_tolerance_f32);
221}
222
223FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuDirectConv2dFixture<float>, framework::DatasetMode::NIGHTLY,
224 combine(combine(combine(zip(zip(zip(zip(zip(
225 framework::dataset::make("InputShape", { TensorShape(800U, 800U, 3U) } ),
226 framework::dataset::make("StrideX", { 1 })),
227 framework::dataset::make("StrideY", { 1 })),
228 framework::dataset::make("PadX", { 1 })),
229 framework::dataset::make("PadY", { 1 })),
230 framework::dataset::make("KernelSize", { 9 })),
231 framework::dataset::make("NumKernels", { 3 })),
232 framework::dataset::make("DataType", DataType::F32)),
233 framework::dataset::make("DataLayout", DataLayout::NHWC)))
234{
235 validate(CLAccessor(_target), _reference, tolerance_f32, 0.0, abs_tolerance_f32);
236}
237// clang-format on
238// *INDENT-ON*
239
240TEST_SUITE_END() // FP32
241TEST_SUITE_END() // DIRECT_CONV2D
Ramy Elgammal404462a2022-11-08 02:14:46 +0000242TEST_SUITE_END() // CONV2D
Ramy Elgammal73f19af2022-10-23 11:44:49 +0100243TEST_SUITE_END() // DYNAMIC_FUSION
244TEST_SUITE_END() // CL
245} // namespace validation
246} // namespace test
247} // namespace arm_compute