blob: ac4ed0b3ca8e0a2c087357a7de0c1bf9c3fb6c98 [file] [log] [blame]
Gian Marco Iodice9285adb2019-09-05 16:10:27 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 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"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46using namespace arm_compute::misc::shape_calculator;
47
48// Create function for CLDepthwiseConvolutionLayerNativeKernel
49using CLDepthwiseConvolutionLayerNative = CLSynthetizeFunction<CLDepthwiseConvolutionLayerNativeKernel>;
50
51// Fixture for CLDepthwiseConvolutionLayerNative
52template <typename T>
53using CLDepthwiseConvolutionLayerNativeFixture = DepthwiseConvolutionLayerNativeConfigurableValidationFixture<CLTensor, CLAccessor, CLDepthwiseConvolutionLayerNative, T>;
54
55namespace
56{
57// *INDENT-OFF*
58// clang-format off
59RelativeTolerance<float> rel_tolerance_f32(0.001f);
60constexpr float abs_tolerance_f32(0.0001f);
61
Giorgio Arenadac622a2019-12-23 15:01:17 +000062RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.01f));
Michele Di Giorgio7d7c4202020-02-25 20:13:36 +000063constexpr float abs_tolerance_f16(0.03f);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010064
65/** Width values to test - Precommit */
Giorgio Arena15bc8482020-12-08 14:34:00 +000066const auto width_values_precommit = framework::dataset::make("width", { 1U, 17U, 32U } );
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010067
68/** Width values to test - Nightly */
69const auto width_values_nightly = framework::dataset::make("width", { 53U, 47U } );
70
71/** Height values to test - Precommit */
72const auto height_values_precommit = framework::dataset::make("height", { 19U } );
73
74/** Height values to test - Nightly */
75const auto height_values_nightly = framework::dataset::make("height", { 39U, 43U } );
76
77/** Channel values to test - Precommit */
78const auto channel_values_precommit = framework::dataset::make("channels", { 15U });
79
80/** Channel values to test - Nightly */
81const auto channel_values_nightly = framework::dataset::make("channels", { 33U, 19U });
82
83/** Batch values to test - Precommit */
84const auto batch_values_precommit = framework::dataset::make("batch", { 1U, 2U });
85
86/** Batch values to test - Nightly */
87const auto batch_values_nightly = framework::dataset::make("batch", { 1U, 3U });
88
89/** Kernel size values to test - Precommit */
90const auto kernel_sz_values_precommit = framework::dataset::make("kernel_size", { Size2D(1U, 1U), Size2D(1U, 3U), Size2D(5U, 5U) });
91
92/** Kernel size values to test - Nightly */
93const auto kernel_sz_values_nightly = framework::dataset::make("kernel_size", { Size2D(3U, 5U), Size2D(5U, 1U), Size2D(1U, 7U), Size2D(9U, 7U) });
94
95/** Depth multiplier values to test - All */
96const auto depth_multiplier_values = framework::dataset::make("depth_multiplier", {3U});
97
98/** Dilation values to test - All */
99const auto dilation_values = framework::dataset::make("dilation", { Size2D(1U, 1U), Size2D(3U, 3U) });
100
101/** Stride values to test - All */
102const auto stride_values = framework::dataset::make("stride", { Size2D(1U, 1U), Size2D(3U, 2U) });
103
104/** Padding values to test - All */
105const auto padding_valid_values = framework::dataset::make("padding_valid", { true, false });
106
107/** Data type values to test - All */
108const auto data_type_values = framework::dataset::make("data_type", { DataType::F32, DataType::F16 });
109
110/** Data layout values to test - All */
111const auto data_layout_values = framework::dataset::make("data_layout", { DataLayout::NHWC });
112
113/** N0 values to test - Precommit */
114const auto n0_values_precommit = framework::dataset::make("N0", {2, 4});
115
116/** N0 values to test - Nightly */
117const auto n0_values_nightly = framework::dataset::make("N0", {3, 8});
118
119/** Activation values to test */
120const auto act_values = framework::dataset::make("Activation",
121{
122 ActivationLayerInfo(),
123 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
124});
125
126} // namespace
127
128TEST_SUITE(CL)
129TEST_SUITE(DepthwiseConvolutionLayerNative)
130TEST_SUITE(Float)
131TEST_SUITE(FP32)
132FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::ALL,
133 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
134 width_values_precommit,
135 height_values_precommit),
136 channel_values_precommit),
137 batch_values_precommit),
138 kernel_sz_values_precommit),
139 framework::dataset::make("depth_multiplier", 1)),
140 dilation_values),
141 stride_values),
142 padding_valid_values),
143 framework::dataset::make("DataType", DataType::F32)),
144 data_layout_values),
145 act_values),
146 n0_values_precommit))
147{
148 // Validate output
149 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
150}
151
152FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::NIGHTLY,
153 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
154 width_values_nightly,
155 height_values_nightly),
156 channel_values_nightly),
157 batch_values_nightly),
158 kernel_sz_values_nightly),
159 framework::dataset::make("depth_multiplier", 1)),
160 dilation_values),
161 stride_values),
162 padding_valid_values),
163 framework::dataset::make("DataType", DataType::F32)),
164 data_layout_values),
165 act_values),
166 n0_values_nightly))
167{
168 // Validate output
169 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
170}
171TEST_SUITE_END() // FP32
172
173TEST_SUITE(FP16)
174FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::ALL,
175 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
176 width_values_precommit,
177 height_values_precommit),
178 channel_values_precommit),
179 batch_values_precommit),
180 kernel_sz_values_precommit),
181 framework::dataset::make("depth_multiplier", 1)),
182 dilation_values),
183 stride_values),
184 padding_valid_values),
185 framework::dataset::make("DataType", DataType::F16)),
186 data_layout_values),
187 act_values),
188 n0_values_precommit))
189{
190 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000191 validate(CLAccessor(_target), _reference, rel_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100192}
193
194FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::NIGHTLY,
195 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
196 width_values_nightly,
197 height_values_nightly),
198 channel_values_nightly),
199 batch_values_nightly),
200 kernel_sz_values_nightly),
201 framework::dataset::make("depth_multiplier", 1)),
202 dilation_values),
203 stride_values),
204 padding_valid_values),
205 framework::dataset::make("DataType", DataType::F16)),
206 data_layout_values),
207 act_values),
208 n0_values_nightly))
209{
210 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000211 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100212}
213TEST_SUITE_END() // FP16
214TEST_SUITE_END() // Float
215TEST_SUITE(DepthMultiplier)
216TEST_SUITE(Float)
217TEST_SUITE(FP32)
218FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::ALL,
219 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
220 width_values_precommit,
221 height_values_precommit),
222 channel_values_precommit),
223 batch_values_precommit),
224 kernel_sz_values_precommit),
225 depth_multiplier_values),
226 dilation_values),
227 stride_values),
228 padding_valid_values),
229 framework::dataset::make("DataType", DataType::F32)),
230 data_layout_values),
231 act_values),
232 framework::dataset::make("N0", 1)))
233{
234 // Validate output
235 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
236}
237
238FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::NIGHTLY,
239 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
240 width_values_nightly,
241 height_values_nightly),
242 channel_values_nightly),
243 batch_values_nightly),
244 kernel_sz_values_nightly),
245 depth_multiplier_values),
246 dilation_values),
247 stride_values),
248 padding_valid_values),
249 framework::dataset::make("DataType", DataType::F32)),
250 data_layout_values),
251 act_values),
252 framework::dataset::make("N0", 1)))
253{
254 // Validate output
255 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
256}
257TEST_SUITE_END() // FP32
258
259TEST_SUITE(FP16)
260FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::ALL,
261 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
262 width_values_precommit,
263 height_values_precommit),
264 channel_values_precommit),
265 batch_values_precommit),
266 kernel_sz_values_precommit),
267 depth_multiplier_values),
268 dilation_values),
269 stride_values),
270 padding_valid_values),
271 framework::dataset::make("DataType", DataType::F16)),
272 data_layout_values),
273 act_values),
274 framework::dataset::make("N0", 1)))
275{
276 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000277 validate(CLAccessor(_target), _reference, rel_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100278}
279
280FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthwiseConvolutionLayerNativeFixture<half>, framework::DatasetMode::NIGHTLY,
281 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
282 width_values_nightly,
283 height_values_nightly),
284 channel_values_nightly),
285 batch_values_nightly),
286 kernel_sz_values_nightly),
287 depth_multiplier_values),
288 dilation_values),
289 stride_values),
290 padding_valid_values),
291 framework::dataset::make("DataType", DataType::F16)),
292 data_layout_values),
293 act_values),
294 framework::dataset::make("N0", 1)))
295{
296 // Validate output
Giorgio Arenadac622a2019-12-23 15:01:17 +0000297 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100298}
299TEST_SUITE_END() // FP16
300TEST_SUITE_END() // Float
301TEST_SUITE_END() // DepthMultiplier
302TEST_SUITE_END() // DepthwiseConvolutionLayerNative
303TEST_SUITE_END() // CL
304} // namespace validation
305} // namespace test
306} // namespace arm_compute