xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/Convolution3D.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2021, 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 #include "arm_compute/runtime/CL/CLTensor.h"
25 #include "arm_compute/runtime/CL/functions/CLConv3D.h"
26 #include "arm_compute/runtime/FunctionDescriptors.h"
27 #include "tests/CL/CLAccessor.h"
28 #include "tests/framework/Macros.h"
29 #include "tests/framework/datasets/Datasets.h"
30 #include "tests/validation/Validation.h"
31 #include "tests/validation/fixtures/DirectConvolution3DFixture.h"
32 
33 namespace arm_compute
34 {
35 namespace test
36 {
37 namespace validation
38 {
39 namespace
40 {
41 const RelativeTolerance<half>        rel_tolerance_fp16(half(0.2)); /**< Relative tolerance for FP16 tests */
42 constexpr float                      abs_tolerance_fp16(0.02f);     /**< Absolute tolerance for FP16 tests */
43 constexpr RelativeTolerance<float>   rel_tolerance_fp32(0.05f);     /**< Relative tolerance for FP32 tests */
44 constexpr float                      abs_tolerance_fp32(0.0001f);   /**< Absolute tolerance for FP32 tests*/
45 constexpr AbsoluteTolerance<uint8_t> abs_tolerance_qasymm8(1);      /**< Absolute tolerance for quantized tests */
46 constexpr float                      tolerance_num = 0.07f;         /**< Tolerance number */
47 } // namespace
48 
49 TEST_SUITE(CL)
TEST_SUITE(DirectConvolution3D)50 TEST_SUITE(DirectConvolution3D)
51 
52 // *INDENT-OFF*
53 // clang-format off
54 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(zip(
55                framework::dataset::make("InputShape", { TensorShape(27U, 13U, 5U, 3U), // Unsupported data layout
56                                                         TensorShape(27U, 13U, 5U, 3U), // Unsupported activation enabled
57                                                         TensorShape(27U, 13U, 5U, 3U), // Mismatching data type
58                                                         TensorShape(27U, 13U, 5U, 3U), // Unsupported data type
59                                                         TensorShape(27U, 13U, 5U, 3U), // Mismatching input feature maps
60                                                         TensorShape(27U, 13U, 5U, 3U), // Mismatching output feature maps
61                                                         TensorShape(27U, 13U, 5U, 3U), // Mismatching bias shape
62                                                         TensorShape(27U, 13U, 5U, 3U), // Unsupported number of weights dimensions
63                                                         TensorShape(27U, 13U, 5U, 3U), // Unsupported number of biases dimensions
64                                                         TensorShape(27U, 13U, 5U, 3U), // Mismatching output shape
65                                                         TensorShape(27U, 13U, 5U, 3U)
66                                                      }),
67                framework::dataset::make("WeightsShape", { TensorShape(4U, 27U, 3U, 3U, 3U),
68                                                           TensorShape(4U, 27U, 3U, 3U, 3U),
69                                                           TensorShape(4U, 27U, 3U, 3U, 3U),
70                                                           TensorShape(4U, 27U, 3U, 3U, 3U),
71                                                           TensorShape(4U, 32U, 3U, 3U, 3U),
72                                                           TensorShape(8U, 27U, 3U, 3U, 3U),
73                                                           TensorShape(4U, 27U, 3U, 3U, 3U),
74                                                           TensorShape(4U, 27U, 3U, 3U, 3U, 2U),
75                                                           TensorShape(4U, 27U, 3U, 3U, 3U),
76                                                           TensorShape(4U, 27U, 3U, 3U, 3U),
77                                                           TensorShape(4U, 27U, 3U, 3U, 3U)
78                                                      })),
79                framework::dataset::make("BiasesShape", { TensorShape(4U),
80                                                          TensorShape(4U),
81                                                          TensorShape(4U),
82                                                          TensorShape(4U),
83                                                          TensorShape(4U),
84                                                          TensorShape(4U),
85                                                          TensorShape(8U),
86                                                          TensorShape(4U),
87                                                          TensorShape(4U),
88                                                          TensorShape(4U),
89                                                          TensorShape(4U)
90                                                      })),
91                framework::dataset::make("OutputShape", { TensorShape(4U, 13U, 5U, 3U),
92                                                          TensorShape(4U, 13U, 5U, 3U),
93                                                          TensorShape(4U, 13U, 5U, 3U),
94                                                          TensorShape(4U, 13U, 5U, 3U),
95                                                          TensorShape(4U, 13U, 5U, 3U),
96                                                          TensorShape(4U, 13U, 5U, 3U),
97                                                          TensorShape(4U, 13U, 5U, 3U),
98                                                          TensorShape(4U, 13U, 5U, 3U),
99                                                          TensorShape(4U, 13U, 5U, 3U, 2U),
100                                                          TensorShape(4U, 11U, 5U, 3U),
101                                                          TensorShape(4U, 13U, 5U, 3U)
102                                                      })),
103                framework::dataset::make("Conv3dInfo",  { Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
104                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
105                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
106                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
107                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
108                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
109                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
110                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
111                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
112                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
113                                                          Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false)
114                                                       })),
115                 framework::dataset::make("SrcDataType", { DataType::F32,
116                                                           DataType::F32,
117                                                           DataType::F32,
118                                                           DataType::U32,
119                                                           DataType::F32,
120                                                           DataType::F32,
121                                                           DataType::F32,
122                                                           DataType::F32,
123                                                           DataType::F32,
124                                                           DataType::F32,
125                                                           DataType::F32
126                                                       })),
127                 framework::dataset::make("WeightsDataType", { DataType::F32,
128                                                               DataType::F32,
129                                                               DataType::F16,
130                                                               DataType::U32,
131                                                               DataType::F32,
132                                                               DataType::F32,
133                                                               DataType::F32,
134                                                               DataType::F32,
135                                                               DataType::F32,
136                                                               DataType::F32,
137                                                               DataType::F32
138                                                       })),
139                 framework::dataset::make("DataLayout", { DataLayout::NCDHW,
140                                                          DataLayout::NDHWC,
141                                                          DataLayout::NDHWC,
142                                                          DataLayout::NDHWC,
143                                                          DataLayout::NDHWC,
144                                                          DataLayout::NDHWC,
145                                                          DataLayout::NDHWC,
146                                                          DataLayout::NDHWC,
147                                                          DataLayout::NDHWC,
148                                                          DataLayout::NDHWC,
149                                                          DataLayout::NDHWC
150                                                       })),
151                framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, false, true })),
152                input_shape, weights_shape, biases_shape, output_shape, conv3d_info, src_data_type, weights_data_type, data_layout, expected)
153 {
154     TensorInfo input_info   = TensorInfo(input_shape, 1, src_data_type);
155     TensorInfo weights_info = TensorInfo(weights_shape, 1, weights_data_type);
156     TensorInfo biases_info  = TensorInfo(biases_shape, 1, src_data_type);
157     TensorInfo output_info  = TensorInfo(output_shape, 1, src_data_type);
158 
159     input_info.set_data_layout(data_layout);
160     weights_info.set_data_layout(data_layout);
161     biases_info.set_data_layout(data_layout);
162     output_info.set_data_layout(data_layout);
163 
164     bool is_valid = bool(CLConv3D::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &biases_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), conv3d_info));
165     ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
166 }
167 
168 template <typename T>
169 using CLDirectConvolution3DFixture = DirectConvolution3DValidationFixture<CLTensor, CLAccessor, CLConv3D, T>;
170 template <typename T>
171 using CLDirectConvolution3DQuantizedFixture = DirectConvolution3DValidationQuantizedFixture<CLTensor, CLAccessor, CLConv3D, T>;
172 
173 TEST_SUITE(NDHWC)
TEST_SUITE(FP16)174 TEST_SUITE(FP16)
175 FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DFixture<half>, framework::DatasetMode::PRECOMMIT,
176                        combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
177                        framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
178                                                                 TensorShape(15U, 7U, 11U, 7U),
179                                                                 TensorShape(19U, 5U, 16U, 4U),
180                                                                 TensorShape(13U, 5U, 17U, 2U)
181                                                               }),
182                        framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
183                        framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
184                        framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
185                        framework::dataset::make("PadX", { 0, 2, 1, 0 })),
186                        framework::dataset::make("PadY", { 1, 0, 2, 0 })),
187                        framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
188                        framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
189                        framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
190                        framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
191                        framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
192                        framework::dataset::make("HasBias", { true, true, true, false })),
193                        framework::dataset::make("Activation", ActivationLayerInfo())),
194                        framework::dataset::make("DataType", DataType::F16)),
195                        framework::dataset::make("DataLayout", DataLayout::NDHWC)))
196 {
197     validate(CLAccessor(_target), _reference, rel_tolerance_fp16, tolerance_num, abs_tolerance_fp16);
198 }
199 
200 TEST_SUITE_END() // FP16
201 
TEST_SUITE(FP32)202 TEST_SUITE(FP32)
203 FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DFixture<float>, framework::DatasetMode::PRECOMMIT,
204                        combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
205                        framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
206                                                                 TensorShape(15U, 7U, 11U, 7U),
207                                                                 TensorShape(19U, 5U, 16U, 4U),
208                                                                 TensorShape(13U, 5U, 17U, 2U)
209                                                               }),
210                        framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
211                        framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
212                        framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
213                        framework::dataset::make("PadX", { 0, 2, 1, 0 })),
214                        framework::dataset::make("PadY", { 1, 0, 2, 0 })),
215                        framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
216                        framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
217                        framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
218                        framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
219                        framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
220                        framework::dataset::make("HasBias", { true, true, true, false })),
221                        framework::dataset::make("Activation", ActivationLayerInfo())),
222                        framework::dataset::make("DataType", DataType::F32)),
223                        framework::dataset::make("DataLayout", DataLayout::NDHWC)))
224 {
225     validate(CLAccessor(_target), _reference, rel_tolerance_fp32, 0.0, abs_tolerance_fp32);
226 }
227 
228 // clang-format on
229 // *INDENT-ON*
230 TEST_SUITE_END() // FP32
231 
TEST_SUITE(QASYMM8)232 TEST_SUITE(QASYMM8)
233 FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
234                        combine(combine(combine(combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
235                                                                                                                    framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
236                                                                                                                            TensorShape(15U, 7U, 11U, 7U),
237                                                                                                                            TensorShape(19U, 5U, 16U, 4U),
238                                                                                                                            TensorShape(13U, 5U, 17U, 2U)
239                                                                                                                                                           }),
240                                                                                                                    framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
241                                                                                                                framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
242                                                                                                            framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
243                                                                                                        framework::dataset::make("PadX", { 0, 2, 1, 0 })),
244                                                                                                    framework::dataset::make("PadY", { 1, 0, 2, 0 })),
245                                                                                                framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
246                                                                                            framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
247                                                                                        framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
248                                                                                    framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
249                                                                                framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
250                                                                            framework::dataset::make("HasBias", { true, true, true, false })),
251                                                                        framework::dataset::make("Activation", ActivationLayerInfo())),
252                                                                framework::dataset::make("DataType", DataType::QASYMM8)),
253                                                        framework::dataset::make("DataLayout", DataLayout::NDHWC)),
254                                                framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
255                                        framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
256                                framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
257 {
258     validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8);
259 }
260 
261 TEST_SUITE_END() // QASYMM8
262 
TEST_SUITE(QASYMM8_SIGNED)263 TEST_SUITE(QASYMM8_SIGNED)
264 FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
265                        combine(combine(combine(combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
266                                                                                                                    framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
267                                                                                                                            TensorShape(15U, 7U, 11U, 7U),
268                                                                                                                            TensorShape(19U, 5U, 16U, 4U),
269                                                                                                                            TensorShape(13U, 5U, 17U, 2U)
270                                                                                                                                                           }),
271                                                                                                                    framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
272                                                                                                                framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
273                                                                                                            framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
274                                                                                                        framework::dataset::make("PadX", { 0, 2, 1, 0 })),
275                                                                                                    framework::dataset::make("PadY", { 1, 0, 2, 0 })),
276                                                                                                framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
277                                                                                            framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
278                                                                                        framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
279                                                                                    framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
280                                                                                framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
281                                                                            framework::dataset::make("HasBias", { true, true, true, false })),
282                                                                        framework::dataset::make("Activation", ActivationLayerInfo())),
283                                                                framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
284                                                        framework::dataset::make("DataLayout", DataLayout::NDHWC)),
285                                                framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
286                                        framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
287                                framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
288 {
289     validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8);
290 }
291 
292 TEST_SUITE_END() // QASYMM8_SIGNED
293 
294 TEST_SUITE_END() // NDHWC
295 TEST_SUITE_END() // DirectConvolution3D
296 TEST_SUITE_END() // CL
297 
298 } // namespace validation
299 } // namespace test
300 } // namespace arm_compute
301