Compute Library
 22.11
DepthwiseConvolutionLayerNative.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2022 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  */
25 #include "arm_compute/core/Types.h"
30 #include "tests/CL/CLAccessor.h"
31 #include "tests/CL/Helper.h"
34 #include "tests/framework/Macros.h"
37 #include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
38 
39 namespace arm_compute
40 {
41 namespace test
42 {
43 namespace validation
44 {
46 
47 // Create function for CLDepthwiseConvolutionLayerNativeKernel
49 
50 // Fixture for CLDepthwiseConvolutionLayerNative
51 template <typename T>
52 using CLDepthwiseConvolutionLayerNativeFixture = DepthwiseConvolutionLayerNativeConfigurableValidationFixture<CLTensor, CLAccessor, CLDepthwiseConvolutionLayerNative, T>;
53 
54 namespace
55 {
56 // *INDENT-OFF*
57 // clang-format off
58 RelativeTolerance<float> rel_tolerance_f32(0.001f);
59 constexpr float abs_tolerance_f32(0.0001f);
60 
62 constexpr float abs_tolerance_f16(0.03f);
63 
64 /** Width values to test - Precommit */
65 const auto width_values_precommit = framework::dataset::make("width", { 1U, 33U } );
66 
67 /** Width values to test - Nightly */
68 const auto width_values_nightly = framework::dataset::make("width", { 53U, 47U } );
69 
70 /** Height values to test - Precommit */
71 const auto height_values_precommit = framework::dataset::make("height", { 19U } );
72 
73 /** Height values to test - Nightly */
74 const auto height_values_nightly = framework::dataset::make("height", { 39U, 43U } );
75 
76 /** Channel values to test - Precommit */
77 const auto channel_values_precommit = framework::dataset::make("channels", { 15U });
78 
79 /** Channel values to test - Nightly */
80 const auto channel_values_nightly = framework::dataset::make("channels", { 33U, 19U });
81 
82 /** Channel values to test with cl_image support - Precommit */
83 const auto channel_values_export_to_cl_image_precommit = framework::dataset::make("channels", { 16U });
84 
85 /** Channel values to test with cl_image support - Nightly */
86 const auto channel_values_export_to_cl_image_nightly = framework::dataset::make("channels", { 32U });
87 
88 /** Batch values to test - Precommit */
89 const auto batch_values_precommit = framework::dataset::make("batch", { 1U, 2U });
90 
91 /** Batch values to test - Nightly */
92 const auto batch_values_nightly = framework::dataset::make("batch", { 1U, 3U });
93 
94 /** Kernel size values to test - Precommit */
95 const 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 */
98 const 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 */
101 const auto depth_multiplier_values = framework::dataset::make("depth_multiplier", {3U});
102 
103 /** Dilation values to test - All */
104 const auto dilation_values = framework::dataset::make("dilation", { Size2D(1U, 1U), Size2D(3U, 3U) });
105 
106 /** Stride values to test - All */
107 const auto stride_values = framework::dataset::make("stride", { Size2D(1U, 1U), Size2D(3U, 2U) });
108 
109 /** Padding values to test - All */
110 const auto padding_valid_values = framework::dataset::make("padding_valid", { true, false });
111 
112 /** Data type values to test - All */
113 const auto data_type_values = framework::dataset::make("data_type", { DataType::F32, DataType::F16 });
114 
115 /** Data layout values to test - All */
116 const auto data_layout_values = framework::dataset::make("data_layout", { DataLayout::NHWC });
117 
118 /** N0 values to test - Precommit */
119 const auto n0_values_precommit = framework::dataset::make("N0", {2, 4});
120 
121 /** N0 values to test - Nightly */
122 const auto n0_values_nightly = framework::dataset::make("N0", {3, 8});
123 
124 /** N0 values to test with cl_image support - Precommit */
125 const auto n0_values_export_to_cl_image_precommit = framework::dataset::make("N0", {4});
126 
127 /** N0 values to test with cl_image support - Nightly */
128 const auto n0_values_export_to_cl_image_nightly = framework::dataset::make("N0", {8});
129 
130 /** Activation values to test */
131 const auto act_values = framework::dataset::make("Activation",
132 {
135 });
136 
137 } // namespace
138 
139 TEST_SUITE(CL)
140 TEST_SUITE(DepthwiseConvolutionLayerNative)
141 TEST_SUITE(Float)
142 TEST_SUITE(FP32)
145  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)),
156  act_values),
157  n0_values_precommit),
158  framework::dataset::make("ExportToCLImage", false)))
159 {
160  // Validate output
161  validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
162 }
163 
166  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),
177  act_values),
178  n0_values_nightly),
179  framework::dataset::make("ExportToCLImage", false)))
180 {
181  // Validate output
182  validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
183 }
184 
185 TEST_SUITE(ExportWeightsToCLImage)
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)),
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");
213  }
214 }
215 
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),
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");
243  }
244 }
245 
246 TEST_SUITE_END() // ExportWeightsToCLImage
247 TEST_SUITE_END() // FP32
248 
249 TEST_SUITE(FP16)
252  width_values_precommit,
253  height_values_precommit),
254  channel_values_precommit),
255  batch_values_precommit),
256  kernel_sz_values_precommit),
257  framework::dataset::make("depth_multiplier", 1)),
258  dilation_values),
259  stride_values),
260  padding_valid_values),
261  framework::dataset::make("DataType", DataType::F16)),
263  act_values),
264  n0_values_precommit),
265  framework::dataset::make("ExportToCLImage", false)))
266 {
267  // Validate output
268  validate(CLAccessor(_target), _reference, rel_tolerance_f16);
269 }
270 
273  width_values_nightly,
274  height_values_nightly),
275  channel_values_nightly),
276  batch_values_nightly),
277  kernel_sz_values_nightly),
278  framework::dataset::make("depth_multiplier", 1)),
279  dilation_values),
280  stride_values),
281  padding_valid_values),
284  act_values),
285  n0_values_nightly),
286  framework::dataset::make("ExportToCLImage", false)))
287 {
288  // Validate output
289  validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
290 }
291 
292 TEST_SUITE(ExportWeightsToCLImage)
295  width_values_precommit,
296  height_values_precommit),
297  channel_values_export_to_cl_image_precommit),
298  batch_values_precommit),
299  kernel_sz_values_precommit),
300  framework::dataset::make("depth_multiplier", 1)),
301  dilation_values),
302  stride_values),
303  padding_valid_values),
304  framework::dataset::make("DataType", DataType::F16)),
306  act_values),
307  n0_values_export_to_cl_image_precommit),
308  framework::dataset::make("ExportToCLImage", true)))
309 {
310  // Validate output
311  if(_validate_output)
312  {
313  // Validate output
314  validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
315  }
316  else
317  {
318  ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
320  }
321 }
322 
325  width_values_nightly,
326  height_values_nightly),
327  channel_values_export_to_cl_image_nightly),
328  batch_values_nightly),
329  kernel_sz_values_nightly),
330  framework::dataset::make("depth_multiplier", 1)),
331  dilation_values),
332  stride_values),
333  padding_valid_values),
336  act_values),
337  n0_values_export_to_cl_image_nightly),
338  framework::dataset::make("ExportToCLImage", true)))
339 {
340  // Validate output
341  if(_validate_output)
342  {
343  // Validate output
344  validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
345  }
346  else
347  {
348  ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
350  }
351 }
352 
353 TEST_SUITE_END() // ExportWeightsToCLImage
354 TEST_SUITE_END() // FP16
355 TEST_SUITE_END() // Float
356 TEST_SUITE(DepthMultiplier)
357 TEST_SUITE(Float)
358 TEST_SUITE(FP32)
361  framework::dataset::make("width", { 33U } ),
362  height_values_precommit),
363  channel_values_precommit),
364  batch_values_precommit),
365  kernel_sz_values_precommit),
366  depth_multiplier_values),
367  dilation_values),
368  stride_values),
369  padding_valid_values),
372  act_values),
373  framework::dataset::make("N0", 1)),
374  framework::dataset::make("ExportToCLImage", false)))
375 {
376  // Validate output
377  validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
378 }
379 
382  framework::dataset::make("width", { 53U } ),
383  height_values_nightly),
384  channel_values_nightly),
385  batch_values_nightly),
386  kernel_sz_values_nightly),
387  depth_multiplier_values),
388  dilation_values),
389  stride_values),
390  padding_valid_values),
393  act_values),
394  framework::dataset::make("N0", 1)),
395  framework::dataset::make("ExportToCLImage", false)))
396 {
397  // Validate output
398  validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
399 }
400 
401 TEST_SUITE(DepthMultiplierMultipleOfOutputChannels)
404  framework::dataset::make("width", { 33U } ),
405  height_values_precommit),
406  channel_values_precommit),
407  batch_values_precommit),
408  kernel_sz_values_precommit),
409  framework::dataset::make("depth_multiplier", 2)),
410  dilation_values),
411  stride_values),
412  padding_valid_values),
415  act_values),
416  framework::dataset::make("N0", {2})),
417  framework::dataset::make("ExportToCLImage", false)))
418 {
419  // Validate output
420  validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
421 }
422 
423 TEST_SUITE(ExportWeightsToCLImage)
426  framework::dataset::make("width", { 33U } ),
427  height_values_precommit),
428  channel_values_precommit),
429  batch_values_precommit),
430  kernel_sz_values_precommit),
431  framework::dataset::make("depth_multiplier", 4)),
432  dilation_values),
433  stride_values),
434  padding_valid_values),
437  act_values),
438  framework::dataset::make("N0", {4})),
439  framework::dataset::make("ExportToCLImage", true)))
440 {
441  // Validate output
442  if(_validate_output)
443  {
444  // Validate output
445  validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
446  }
447  else
448  {
449  ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
451  }
452 }
453 TEST_SUITE_END() // ExportWeightsToCLImage
454 TEST_SUITE_END() // DepthMultiplierMultipleOfOutputChannels
455 TEST_SUITE_END() // FP32
456 
457 TEST_SUITE(FP16)
460  framework::dataset::make("width", { 33U } ),
461  height_values_precommit),
462  channel_values_precommit),
463  batch_values_precommit),
464  kernel_sz_values_precommit),
465  depth_multiplier_values),
466  dilation_values),
467  stride_values),
468  padding_valid_values),
471  act_values),
472  framework::dataset::make("N0", 1)),
473  framework::dataset::make("ExportToCLImage", false)))
474 {
475  // Validate output
476  validate(CLAccessor(_target), _reference, rel_tolerance_f16);
477 }
478 
481  framework::dataset::make("width", { 53U } ),
482  height_values_nightly),
483  channel_values_nightly),
484  batch_values_nightly),
485  kernel_sz_values_nightly),
486  depth_multiplier_values),
487  dilation_values),
488  stride_values),
489  padding_valid_values),
492  act_values),
493  framework::dataset::make("N0", 1)),
494  framework::dataset::make("ExportToCLImage", false)))
495 {
496  // Validate output
497  validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
498 }
499 
500 TEST_SUITE(DepthMultiplierMultipleOfOutputChannels)
503  framework::dataset::make("width", { 33U } ),
504  height_values_precommit),
505  channel_values_precommit),
506  batch_values_precommit),
507  kernel_sz_values_precommit),
508  framework::dataset::make("depth_multiplier", 2)),
509  dilation_values),
510  stride_values),
511  padding_valid_values),
514  act_values),
515  framework::dataset::make("N0", {2})),
516  framework::dataset::make("ExportToCLImage", false)))
517 {
518  // Validate output
519  validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
520 }
521 
522 TEST_SUITE(ExportWeightsToCLImage)
525  framework::dataset::make("width", { 33U } ),
526  height_values_precommit),
527  channel_values_precommit),
528  batch_values_precommit),
529  kernel_sz_values_precommit),
530  framework::dataset::make("depth_multiplier", 4)),
531  dilation_values),
532  stride_values),
533  padding_valid_values),
536  act_values),
537  framework::dataset::make("N0", {4})),
538  framework::dataset::make("ExportToCLImage", true)))
539 {
540  // Validate output
541  if(_validate_output)
542  {
543  // Validate output
544  validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
545  }
546  else
547  {
548  ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped");
550  }
551 }
552 TEST_SUITE_END() // ExportWeightsToCLImage
553 TEST_SUITE_END() // DepthMultiplierMultipleOfOutputChannels
554 TEST_SUITE_END() // FP16
555 TEST_SUITE_END() // Float
556 TEST_SUITE_END() // DepthMultiplier
557 TEST_SUITE_END() // DepthwiseConvolutionLayerNative
558 TEST_SUITE_END() // CL
559 } // namespace validation
560 } // namespace test
561 } // namespace arm_compute
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Activation Layer Information class.
Definition: Types.h:1639
DepthwiseConvolutionLayerNativeConfigurableValidationFixture< CLTensor, CLAccessor, CLDepthwiseConvolutionLayerNative, T > CLDepthwiseConvolutionLayerNativeFixture
#define ARM_COMPUTE_TEST_INFO(INFO)
Definition: Asserts.h:72
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
Accessor implementation for CLTensor objects.
Definition: CLAccessor.h:36
validate(CLAccessor(output_state), expected_output)
Class reprensenting a relative tolerance value.
Definition: Validation.h:97
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Num samples, height, width, channels.
This template synthetizes an ICLSimpleFunction which runs the given kernel K.
Definition: Helper.h:126
const auto data_layout_values
Data layout to test.
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
constexpr float abs_tolerance_f32(0.0001f)
F32 Absolute tolerance value for comparing reference&#39;s output against implementation&#39;s output for flo...
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CLDepthwiseConvolutionLayerFixture< half >, framework::DatasetMode::ALL, combine(combine(combine(combine(framework::dataset::concat(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), datasets::SmallDepthwiseConvolutionLayerDataset3x3NCHW()), depth_multipliers), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("DataLayout", DataLayout::NCHW)), ActivationFunctionsDataset))