blob: f5652557191240eb86cdd95814b7e1155bc51972 [file] [log] [blame]
Gian Marco Iodice9285adb2019-09-05 16:10:27 +01001/*
Giorgio Arena68e29da2021-02-08 16:31:10 +00002 * Copyright (c) 2019-2021 Arm Limited.
Gian Marco Iodice9285adb2019-09-05 16:10:27 +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 */
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010024#include "arm_compute/core/KernelDescriptors.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/core/utils/misc/ShapeCalculator.h"
27#include "arm_compute/runtime/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/CLTensorAllocator.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010029#include "src/core/CL/kernels/CLDepthwiseConvolutionLayerNativeKernel.h"
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010030#include "tests/CL/CLAccessor.h"
31#include "tests/CL/Helper.h"
32#include "tests/PaddingCalculator.h"
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010033#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45using namespace arm_compute::misc::shape_calculator;
46
47// Create function for CLDepthwiseConvolutionLayerNativeKernel
48using CLDepthwiseConvolutionLayerNative = CLSynthetizeFunction<CLDepthwiseConvolutionLayerNativeKernel>;
49
50// Fixture for CLDepthwiseConvolutionLayerNative
51template <typename T>
52using CLDepthwiseConvolutionLayerNativeFixture = DepthwiseConvolutionLayerNativeConfigurableValidationFixture<CLTensor, CLAccessor, CLDepthwiseConvolutionLayerNative, T>;
53
54namespace
55{
56// *INDENT-OFF*
57// clang-format off
58RelativeTolerance<float> rel_tolerance_f32(0.001f);
59constexpr float abs_tolerance_f32(0.0001f);
60
Giorgio Arenadac622a2019-12-23 15:01:17 +000061RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.01f));
Michele Di Giorgio7d7c4202020-02-25 20:13:36 +000062constexpr float abs_tolerance_f16(0.03f);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010063
64/** Width values to test - Precommit */
Gian Marco Iodice8155c022021-04-16 15:08:59 +010065const auto width_values_precommit = framework::dataset::make("width", { 1U, 33U } );
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010066
67/** Width values to test - Nightly */
68const auto width_values_nightly = framework::dataset::make("width", { 53U, 47U } );
69
70/** Height values to test - Precommit */
71const auto height_values_precommit = framework::dataset::make("height", { 19U } );
72
73/** Height values to test - Nightly */
74const auto height_values_nightly = framework::dataset::make("height", { 39U, 43U } );
75
76/** Channel values to test - Precommit */
77const auto channel_values_precommit = framework::dataset::make("channels", { 15U });
78
79/** Channel values to test - Nightly */
80const auto channel_values_nightly = framework::dataset::make("channels", { 33U, 19U });
81
Gian Marco Iodice8155c022021-04-16 15:08:59 +010082/** Channel values to test with cl_image support - Precommit */
83const auto channel_values_export_to_cl_image_precommit = framework::dataset::make("channels", { 16U });
84
85/** Channel values to test with cl_image support - Nightly */
86const auto channel_values_export_to_cl_image_nightly = framework::dataset::make("channels", { 32U });
87
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010088/** Batch values to test - Precommit */
89const auto batch_values_precommit = framework::dataset::make("batch", { 1U, 2U });
90
91/** Batch values to test - Nightly */
92const auto batch_values_nightly = framework::dataset::make("batch", { 1U, 3U });
93
94/** Kernel size values to test - Precommit */
95const auto kernel_sz_values_precommit = framework::dataset::make("kernel_size", { Size2D(1U, 1U), Size2D(1U, 3U), Size2D(5U, 5U) });
96
97/** Kernel size values to test - Nightly */
98const auto kernel_sz_values_nightly = framework::dataset::make("kernel_size", { Size2D(3U, 5U), Size2D(5U, 1U), Size2D(1U, 7U), Size2D(9U, 7U) });
99
100/** Depth multiplier values to test - All */
101const auto depth_multiplier_values = framework::dataset::make("depth_multiplier", {3U});
102
103/** Dilation values to test - All */
104const auto dilation_values = framework::dataset::make("dilation", { Size2D(1U, 1U), Size2D(3U, 3U) });
105
106/** Stride values to test - All */
107const auto stride_values = framework::dataset::make("stride", { Size2D(1U, 1U), Size2D(3U, 2U) });
108
109/** Padding values to test - All */
110const auto padding_valid_values = framework::dataset::make("padding_valid", { true, false });
111
112/** Data type values to test - All */
113const auto data_type_values = framework::dataset::make("data_type", { DataType::F32, DataType::F16 });
114
115/** Data layout values to test - All */
116const auto data_layout_values = framework::dataset::make("data_layout", { DataLayout::NHWC });
117
118/** N0 values to test - Precommit */
119const auto n0_values_precommit = framework::dataset::make("N0", {2, 4});
120
121/** N0 values to test - Nightly */
122const auto n0_values_nightly = framework::dataset::make("N0", {3, 8});
123
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100124/** N0 values to test with cl_image support - Precommit */
125const auto n0_values_export_to_cl_image_precommit = framework::dataset::make("N0", {4});
126
127/** N0 values to test with cl_image support - Nightly */
128const auto n0_values_export_to_cl_image_nightly = framework::dataset::make("N0", {8});
129
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100130/** Activation values to test */
131const auto act_values = framework::dataset::make("Activation",
132{
133 ActivationLayerInfo(),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100134 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.0f, 0.5f),
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100135});
136
137} // namespace
138
139TEST_SUITE(CL)
140TEST_SUITE(DepthwiseConvolutionLayerNative)
141TEST_SUITE(Float)
142TEST_SUITE(FP32)
Giorgio Arena68e29da2021-02-08 16:31:10 +0000143FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100144 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100145 width_values_precommit,
146 height_values_precommit),
147 channel_values_precommit),
148 batch_values_precommit),
149 kernel_sz_values_precommit),
150 framework::dataset::make("depth_multiplier", 1)),
151 dilation_values),
152 stride_values),
153 padding_valid_values),
154 framework::dataset::make("DataType", DataType::F32)),
155 data_layout_values),
156 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100157 n0_values_precommit),
158 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100159{
160 // Validate output
161 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
162}
163
Giorgio Arena68e29da2021-02-08 16:31:10 +0000164FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100165 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100166 width_values_nightly,
167 height_values_nightly),
168 channel_values_nightly),
169 batch_values_nightly),
170 kernel_sz_values_nightly),
171 framework::dataset::make("depth_multiplier", 1)),
172 dilation_values),
173 stride_values),
174 padding_valid_values),
175 framework::dataset::make("DataType", DataType::F32)),
176 data_layout_values),
177 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100178 n0_values_nightly),
179 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100180{
181 // Validate output
182 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
183}
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100184
185TEST_SUITE(ExportWeightsToCLImage)
186FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::ALL,
187 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
188 width_values_precommit,
189 height_values_precommit),
190 channel_values_export_to_cl_image_precommit),
191 batch_values_precommit),
192 kernel_sz_values_precommit),
193 framework::dataset::make("depth_multiplier", 1)),
194 dilation_values),
195 stride_values),
196 padding_valid_values),
197 framework::dataset::make("DataType", DataType::F32)),
198 data_layout_values),
199 act_values),
200 n0_values_export_to_cl_image_precommit),
201 framework::dataset::make("ExportToCLImage", true)))
202{
203 // Validate output
204 if(_validate_output)
205 {
206 // Validate output
207 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
208 }
209 else
210 {
211 ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
212 framework::ARM_COMPUTE_PRINT_INFO();
213 }
214}
215
216FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::NIGHTLY,
217 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
218 width_values_nightly,
219 height_values_nightly),
220 channel_values_export_to_cl_image_nightly),
221 batch_values_nightly),
222 kernel_sz_values_nightly),
223 framework::dataset::make("depth_multiplier", 1)),
224 dilation_values),
225 stride_values),
226 padding_valid_values),
227 framework::dataset::make("DataType", DataType::F32)),
228 data_layout_values),
229 act_values),
230 n0_values_export_to_cl_image_nightly),
231 framework::dataset::make("ExportToCLImage", true)))
232{
233 // Validate output
234 if(_validate_output)
235 {
236 // Validate output
237 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
238 }
239 else
240 {
241 ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
242 framework::ARM_COMPUTE_PRINT_INFO();
243 }
244}
245TEST_SUITE_END() // ExportWeightsToCLImage
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100246TEST_SUITE_END() // FP32
247
248TEST_SUITE(FP16)
Giorgio Arena68e29da2021-02-08 16:31:10 +0000249FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::ALL,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100250 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100251 width_values_precommit,
252 height_values_precommit),
253 channel_values_precommit),
254 batch_values_precommit),
255 kernel_sz_values_precommit),
256 framework::dataset::make("depth_multiplier", 1)),
257 dilation_values),
258 stride_values),
259 padding_valid_values),
260 framework::dataset::make("DataType", DataType::F16)),
261 data_layout_values),
262 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100263 n0_values_precommit),
264 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100265{
266 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000267 validate(CLAccessor(_target), _reference, rel_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100268}
269
Giorgio Arena68e29da2021-02-08 16:31:10 +0000270FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100271 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100272 width_values_nightly,
273 height_values_nightly),
274 channel_values_nightly),
275 batch_values_nightly),
276 kernel_sz_values_nightly),
277 framework::dataset::make("depth_multiplier", 1)),
278 dilation_values),
279 stride_values),
280 padding_valid_values),
281 framework::dataset::make("DataType", DataType::F16)),
282 data_layout_values),
283 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100284 n0_values_nightly),
285 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100286{
287 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000288 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100289}
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100290TEST_SUITE(ExportWeightsToCLImage)
291FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::ALL,
292 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
293 width_values_precommit,
294 height_values_precommit),
295 channel_values_export_to_cl_image_precommit),
296 batch_values_precommit),
297 kernel_sz_values_precommit),
298 framework::dataset::make("depth_multiplier", 1)),
299 dilation_values),
300 stride_values),
301 padding_valid_values),
302 framework::dataset::make("DataType", DataType::F16)),
303 data_layout_values),
304 act_values),
305 n0_values_export_to_cl_image_precommit),
306 framework::dataset::make("ExportToCLImage", true)))
307{
308 // Validate output
309 if(_validate_output)
310 {
311 // Validate output
312 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
313 }
314 else
315 {
316 ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
317 framework::ARM_COMPUTE_PRINT_INFO();
318 }
319}
320
321FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::NIGHTLY,
322 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
323 width_values_nightly,
324 height_values_nightly),
325 channel_values_export_to_cl_image_nightly),
326 batch_values_nightly),
327 kernel_sz_values_nightly),
328 framework::dataset::make("depth_multiplier", 1)),
329 dilation_values),
330 stride_values),
331 padding_valid_values),
332 framework::dataset::make("DataType", DataType::F16)),
333 data_layout_values),
334 act_values),
335 n0_values_export_to_cl_image_nightly),
336 framework::dataset::make("ExportToCLImage", true)))
337{
338 // Validate output
339 if(_validate_output)
340 {
341 // Validate output
342 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
343 }
344 else
345 {
346 ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
347 framework::ARM_COMPUTE_PRINT_INFO();
348 }
349}
350TEST_SUITE_END() // ExportWeightsToCLImage
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100351TEST_SUITE_END() // FP16
352TEST_SUITE_END() // Float
353TEST_SUITE(DepthMultiplier)
354TEST_SUITE(Float)
355TEST_SUITE(FP32)
Giorgio Arena68e29da2021-02-08 16:31:10 +0000356FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100357 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100358 width_values_precommit,
359 height_values_precommit),
360 channel_values_precommit),
361 batch_values_precommit),
362 kernel_sz_values_precommit),
363 depth_multiplier_values),
364 dilation_values),
365 stride_values),
366 padding_valid_values),
367 framework::dataset::make("DataType", DataType::F32)),
368 data_layout_values),
369 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100370 framework::dataset::make("N0", 1)),
371 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100372{
373 // Validate output
374 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
375}
376
Giorgio Arena68e29da2021-02-08 16:31:10 +0000377FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100378 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100379 width_values_nightly,
380 height_values_nightly),
381 channel_values_nightly),
382 batch_values_nightly),
383 kernel_sz_values_nightly),
384 depth_multiplier_values),
385 dilation_values),
386 stride_values),
387 padding_valid_values),
388 framework::dataset::make("DataType", DataType::F32)),
389 data_layout_values),
390 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100391 framework::dataset::make("N0", 1)),
392 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100393{
394 // Validate output
395 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
396}
397TEST_SUITE_END() // FP32
398
399TEST_SUITE(FP16)
Giorgio Arena68e29da2021-02-08 16:31:10 +0000400FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::ALL,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100401 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100402 width_values_precommit,
403 height_values_precommit),
404 channel_values_precommit),
405 batch_values_precommit),
406 kernel_sz_values_precommit),
407 depth_multiplier_values),
408 dilation_values),
409 stride_values),
410 padding_valid_values),
411 framework::dataset::make("DataType", DataType::F16)),
412 data_layout_values),
413 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100414 framework::dataset::make("N0", 1)),
415 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100416{
417 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000418 validate(CLAccessor(_target), _reference, rel_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100419}
420
Giorgio Arena68e29da2021-02-08 16:31:10 +0000421FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100422 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100423 width_values_nightly,
424 height_values_nightly),
425 channel_values_nightly),
426 batch_values_nightly),
427 kernel_sz_values_nightly),
428 depth_multiplier_values),
429 dilation_values),
430 stride_values),
431 padding_valid_values),
432 framework::dataset::make("DataType", DataType::F16)),
433 data_layout_values),
434 act_values),
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100435 framework::dataset::make("N0", 1)),
436 framework::dataset::make("ExportToCLImage", false)))
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100437{
438 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000439 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100440}
441TEST_SUITE_END() // FP16
442TEST_SUITE_END() // Float
443TEST_SUITE_END() // DepthMultiplier
444TEST_SUITE_END() // DepthwiseConvolutionLayerNative
445TEST_SUITE_END() // CL
446} // namespace validation
447} // namespace test
448} // namespace arm_compute