blob: 9e4ca50547352de6e43b2b1249341841881a176e [file] [log] [blame]
Giorgio Arena945ae9e2021-10-13 11:13:04 +01001/*
2 * Copyright (c) 2021 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
33namespace arm_compute
34{
35namespace test
36{
37namespace validation
38{
39namespace
40{
Giorgio Arena51847d52021-10-19 15:45:57 +010041RelativeTolerance<half> tolerance_fp16(half(0.2)); /**< Tolerance for floating point tests */
42RelativeTolerance<float> tolerance_fp32(0.05f); /**< Tolerance for floating point tests */
43constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance for quantized tests */
44constexpr float abs_tolerance_f32(0.0001f); /**< Absolute tolerance for FP32 tests*/
45constexpr float tolerance_num = 0.07f; /**< Tolerance number */
Giorgio Arena945ae9e2021-10-13 11:13:04 +010046} // namespace
47
48TEST_SUITE(CL)
49TEST_SUITE(DirectConvolution3D)
50
51// *INDENT-OFF*
52// clang-format off
53DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(zip(
54 framework::dataset::make("InputShape", { TensorShape(27U, 13U, 5U, 3U), // Unsupported data layout
55 TensorShape(27U, 13U, 5U, 3U), // Unsupported activation enabled
56 TensorShape(27U, 13U, 5U, 3U), // Mismatching data type
57 TensorShape(27U, 13U, 5U, 3U), // Unsupported data type
58 TensorShape(27U, 13U, 5U, 3U), // Mismatching input feature maps
59 TensorShape(27U, 13U, 5U, 3U), // Mismatching output feature maps
60 TensorShape(27U, 13U, 5U, 3U), // Mismatching bias shape
61 TensorShape(27U, 13U, 5U, 3U), // Unsupported number of weights dimensions
62 TensorShape(27U, 13U, 5U, 3U), // Unsupported number of biases dimensions
63 TensorShape(27U, 13U, 5U, 3U), // Mismatching output shape
64 TensorShape(27U, 13U, 5U, 3U)
65 }),
66 framework::dataset::make("WeightsShape", { TensorShape(4U, 27U, 3U, 3U, 3U),
67 TensorShape(4U, 27U, 3U, 3U, 3U),
68 TensorShape(4U, 27U, 3U, 3U, 3U),
69 TensorShape(4U, 27U, 3U, 3U, 3U),
70 TensorShape(4U, 32U, 3U, 3U, 3U),
71 TensorShape(8U, 27U, 3U, 3U, 3U),
72 TensorShape(4U, 27U, 3U, 3U, 3U),
73 TensorShape(4U, 27U, 3U, 3U, 3U, 2U),
74 TensorShape(4U, 27U, 3U, 3U, 3U),
75 TensorShape(4U, 27U, 3U, 3U, 3U),
76 TensorShape(4U, 27U, 3U, 3U, 3U)
77 })),
78 framework::dataset::make("BiasesShape", { TensorShape(4U),
79 TensorShape(4U),
80 TensorShape(4U),
81 TensorShape(4U),
82 TensorShape(4U),
83 TensorShape(4U),
84 TensorShape(8U),
85 TensorShape(4U),
86 TensorShape(4U),
87 TensorShape(4U),
88 TensorShape(4U)
89 })),
90 framework::dataset::make("OutputShape", { TensorShape(4U, 13U, 5U, 3U),
91 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, 2U),
99 TensorShape(4U, 11U, 5U, 3U),
100 TensorShape(4U, 13U, 5U, 3U)
101 })),
102 framework::dataset::make("Conv3dInfo", { Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
103 Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false),
104 Conv3dInfo(Size3D(1U, 1U, 1U), Padding3D(1U, 1U, 1U), ActivationLayerInfo(), 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 })),
114 framework::dataset::make("SrcDataType", { DataType::F32,
115 DataType::F32,
116 DataType::F32,
Freddie Liardet69df64f2021-10-26 14:06:47 +0100117 DataType::U32,
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100118 DataType::F32,
119 DataType::F32,
120 DataType::F32,
121 DataType::F32,
122 DataType::F32,
123 DataType::F32,
124 DataType::F32
125 })),
126 framework::dataset::make("WeightsDataType", { DataType::F32,
127 DataType::F32,
128 DataType::F16,
Freddie Liardet69df64f2021-10-26 14:06:47 +0100129 DataType::U32,
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100130 DataType::F32,
131 DataType::F32,
132 DataType::F32,
133 DataType::F32,
134 DataType::F32,
135 DataType::F32,
136 DataType::F32
137 })),
138 framework::dataset::make("DataLayout", { DataLayout::NCDHW,
139 DataLayout::NDHWC,
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 })),
150 framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, false, true })),
151 input_shape, weights_shape, biases_shape, output_shape, conv3d_info, src_data_type, weights_data_type, data_layout, expected)
152{
153 TensorInfo input_info = TensorInfo(input_shape, 1, src_data_type);
154 TensorInfo weights_info = TensorInfo(weights_shape, 1, weights_data_type);
155 TensorInfo biases_info = TensorInfo(biases_shape, 1, src_data_type);
156 TensorInfo output_info = TensorInfo(output_shape, 1, src_data_type);
157
158 input_info.set_data_layout(data_layout);
159 weights_info.set_data_layout(data_layout);
160 biases_info.set_data_layout(data_layout);
161 output_info.set_data_layout(data_layout);
162
163 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));
164 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
165}
166
167template <typename T>
168using CLDirectConvolution3DFixture = DirectConvolution3DValidationFixture<CLTensor, CLAccessor, CLConv3D, T>;
Giorgio Arena51847d52021-10-19 15:45:57 +0100169template <typename T>
170using CLDirectConvolution3DQuantizedFixture = DirectConvolution3DValidationQuantizedFixture<CLTensor, CLAccessor, CLConv3D, T>;
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100171
172TEST_SUITE(NDHWC)
173TEST_SUITE(FP16)
174FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DFixture<half>, framework::DatasetMode::PRECOMMIT,
175 combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
176 framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
177 TensorShape(15U, 7U, 11U, 7U),
178 TensorShape(19U, 5U, 16U, 4U),
179 TensorShape(13U, 5U, 17U, 2U)
180 }),
181 framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
182 framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
183 framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
184 framework::dataset::make("PadX", { 0, 2, 1, 0 })),
185 framework::dataset::make("PadY", { 1, 0, 2, 0 })),
186 framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
187 framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
188 framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
189 framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
190 framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
191 framework::dataset::make("HasBias", { true, true, true, false })),
192 framework::dataset::make("Activation", ActivationLayerInfo())),
193 framework::dataset::make("DataType", DataType::F16)),
194 framework::dataset::make("DataLayout", DataLayout::NDHWC)))
195{
196 validate(CLAccessor(_target), _reference, tolerance_fp16, tolerance_num);
197}
198
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100199TEST_SUITE_END() // FP16
200
201TEST_SUITE(FP32)
202FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DFixture<float>, framework::DatasetMode::PRECOMMIT,
203 combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
204 framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
205 TensorShape(15U, 7U, 11U, 7U),
206 TensorShape(19U, 5U, 16U, 4U),
207 TensorShape(13U, 5U, 17U, 2U)
208 }),
209 framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
210 framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
211 framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
212 framework::dataset::make("PadX", { 0, 2, 1, 0 })),
213 framework::dataset::make("PadY", { 1, 0, 2, 0 })),
214 framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
215 framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
216 framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
217 framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
218 framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
219 framework::dataset::make("HasBias", { true, true, true, false })),
220 framework::dataset::make("Activation", ActivationLayerInfo())),
221 framework::dataset::make("DataType", DataType::F32)),
222 framework::dataset::make("DataLayout", DataLayout::NDHWC)))
223{
224 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.0, abs_tolerance_f32);
225}
226
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100227// clang-format on
228// *INDENT-ON*
229TEST_SUITE_END() // FP32
Giorgio Arena51847d52021-10-19 15:45:57 +0100230
231TEST_SUITE(QASYMM8)
232FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
233 combine(combine(combine(combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
234 framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
235 TensorShape(15U, 7U, 11U, 7U),
236 TensorShape(19U, 5U, 16U, 4U),
237 TensorShape(13U, 5U, 17U, 2U)
238 }),
239 framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
240 framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
241 framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
242 framework::dataset::make("PadX", { 0, 2, 1, 0 })),
243 framework::dataset::make("PadY", { 1, 0, 2, 0 })),
244 framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
245 framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
246 framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
247 framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
248 framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
249 framework::dataset::make("HasBias", { true, true, true, false })),
250 framework::dataset::make("Activation", ActivationLayerInfo())),
251 framework::dataset::make("DataType", DataType::QASYMM8)),
252 framework::dataset::make("DataLayout", DataLayout::NDHWC)),
253 framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
254 framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
255 framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
256{
257 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
258}
259
Giorgio Arena51847d52021-10-19 15:45:57 +0100260TEST_SUITE_END() // QASYMM8
261
262TEST_SUITE(QASYMM8_SIGNED)
263FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
264 combine(combine(combine(combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
265 framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
266 TensorShape(15U, 7U, 11U, 7U),
267 TensorShape(19U, 5U, 16U, 4U),
268 TensorShape(13U, 5U, 17U, 2U)
269 }),
270 framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
271 framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
272 framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
273 framework::dataset::make("PadX", { 0, 2, 1, 0 })),
274 framework::dataset::make("PadY", { 1, 0, 2, 0 })),
275 framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
276 framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
277 framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
278 framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
279 framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
280 framework::dataset::make("HasBias", { true, true, true, false })),
281 framework::dataset::make("Activation", ActivationLayerInfo())),
282 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
283 framework::dataset::make("DataLayout", DataLayout::NDHWC)),
284 framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
285 framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
286 framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
287{
288 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
289}
290
Giorgio Arena51847d52021-10-19 15:45:57 +0100291TEST_SUITE_END() // QASYMM8_SIGNED
292
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100293TEST_SUITE_END() // NDHWC
294TEST_SUITE_END() // DirectConvolution3D
295TEST_SUITE_END() // CL
296
297} // namespace validation
298} // namespace test
299} // namespace arm_compute