blob: fe7bba365a76b8cad6279d1d2360582c8bbb9c8e [file] [log] [blame]
Anthony Barbier8140e1e2017-12-14 23:48:46 +00001/*
Anthony Barbierf45d5a92018-01-24 16:23:15 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier8140e1e2017-12-14 23:48:46 +00003 *
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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
Jenkinsb3a371b2018-05-23 11:36:53 +010025#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Anthony Barbier8140e1e2017-12-14 23:48:46 +000026#include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/DepthwiseConvolutionLayerDataset.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
Jenkinsb3a371b2018-05-23 11:36:53 +010044using namespace arm_compute::misc::shape_calculator;
45
Anthony Barbier8140e1e2017-12-14 23:48:46 +000046namespace
47{
Anthony Barbierf45d5a92018-01-24 16:23:15 +000048constexpr RelativeTolerance<float> tolerance_f32(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
49constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for DataType::QASYMM8 */
Jenkinsb3a371b2018-05-23 11:36:53 +010050
51const auto depth_multipliers = framework::dataset::make("DepthMultiplier", { 1, 2, 3 });
Anthony Barbier8140e1e2017-12-14 23:48:46 +000052} // namespace
53
54TEST_SUITE(NEON)
Anthony Barbierf45d5a92018-01-24 16:23:15 +000055TEST_SUITE(DepthwiseConvLayer)
Anthony Barbier8140e1e2017-12-14 23:48:46 +000056
Jenkins52ba29e2018-08-29 15:32:11 +000057// *INDENT-OFF*
58// clang-format off
59DATA_TEST_CASE(Validate3x3, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
60 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32), // Mismatching data type input/weights
61 TensorInfo(TensorShape(32U, 18U, 3U), 1, DataType::F32), // Mismatching input feature maps
62 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32), // Unsupported weights dimensions
63 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32), // Mismatching depth multiplier
64 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::QASYMM8), // Invalid stride
65 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32), // Invalid biases size
66 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32), // Invalid biases dimensions
67 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32), // Invalid output size
68 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
69 }),
70 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16),
71 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(5U, 5U, 2U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::QASYMM8),
75 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F32),
77 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F32),
79 })),
80 framework::dataset::make("BiasesInfo", { TensorInfo(TensorShape(2U), 1, DataType::F32),
81 TensorInfo(TensorShape(2U), 1, DataType::F32),
82 TensorInfo(TensorShape(2U), 1, DataType::F32),
83 TensorInfo(TensorShape(2U), 1, DataType::F32),
84 TensorInfo(TensorShape(2U), 1, DataType::S32),
85 TensorInfo(TensorShape(4U), 1, DataType::F32),
86 TensorInfo(TensorShape(2U, 2U), 1, DataType::F32),
87 TensorInfo(TensorShape(2U), 1, DataType::F32),
88 TensorInfo(TensorShape(2U), 1, DataType::F32),
89 })),
90 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::F32),
91 TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::F32),
92 TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::F32),
93 TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::F32),
94 TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::QASYMM8),
95 TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::F32),
96 TensorInfo(TensorShape(30U, 16U, 2U), 1, DataType::F32),
97 TensorInfo(TensorShape(32U, 18U, 2U), 1, DataType::F32),
98 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
99 })),
100 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0),
101 PadStrideInfo(1, 1, 0, 0),
102 PadStrideInfo(1, 1, 0, 0),
103 PadStrideInfo(1, 1, 0, 0),
104 PadStrideInfo(4, 1, 0, 0),
105 PadStrideInfo(1, 1, 0, 0),
106 PadStrideInfo(1, 1, 0, 0),
107 PadStrideInfo(1, 1, 0, 0),
108 PadStrideInfo(1, 1, 0, 0),
109 })),
110 framework::dataset::make("DepthMultiplier", { 1,
111 1,
112 1,
113 3,
114 1,
115 1,
116 1,
117 1,
118 1,
119 })),
120 framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, true })),
121 input_info, weights_info, biases_info, output_info, conv_info, depth_multiplier, expected)
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000122{
Jenkins52ba29e2018-08-29 15:32:11 +0000123 bool is_valid = bool(NEDepthwiseConvolutionLayer3x3::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), conv_info, depth_multiplier));
124 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000125}
126
Jenkins52ba29e2018-08-29 15:32:11 +0000127DATA_TEST_CASE(ValidateGeneric, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
128 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/weights
129 TensorInfo(TensorShape(27U, 13U, 3U), 1, DataType::F32), // Mismatching input feature maps
130 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching depth multiplier
131 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid biases size
132 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid biases dimensions
133 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid output size
134 TensorInfo(TensorShape(27U, 13U, 8U), 1, DataType::F32),
135 TensorInfo(TensorShape(32U, 13U, 8U), 1, DataType::QASYMM8),
136 }),
137 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U), 1, DataType::F16),
138 TensorInfo(TensorShape(3U, 3U, 2U), 1, DataType::F32),
139 TensorInfo(TensorShape(3U, 3U, 2U), 1, DataType::F32),
140 TensorInfo(TensorShape(3U, 3U, 2U), 1, DataType::F32),
141 TensorInfo(TensorShape(3U, 3U, 2U), 1, DataType::F32),
142 TensorInfo(TensorShape(3U, 3U, 2U), 1, DataType::F32),
143 TensorInfo(TensorShape(3U, 3U, 16U), 1, DataType::F32),
144 TensorInfo(TensorShape(3U, 3U, 24U), 1, DataType::QASYMM8),
145 })),
146 framework::dataset::make("BiasesInfo", { TensorInfo(TensorShape(2U), 1, DataType::F32),
147 TensorInfo(TensorShape(2U), 1, DataType::F32),
148 TensorInfo(TensorShape(2U), 1, DataType::F32),
149 TensorInfo(TensorShape(4U), 1, DataType::F32),
150 TensorInfo(TensorShape(2U, 2U), 1, DataType::F32),
151 TensorInfo(TensorShape(2U), 1, DataType::F32),
152 TensorInfo(TensorShape(16U), 1, DataType::F32),
153 TensorInfo(TensorShape(24U), 1, DataType::S32),
154 })),
155 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
156 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
157 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
158 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
159 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
160 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
161 TensorInfo(TensorShape(25U, 11U, 16U), 1, DataType::F32),
162 TensorInfo(TensorShape(32U, 11U, 24U), 1, DataType::QASYMM8),
163 })),
164 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0),
165 PadStrideInfo(1, 1, 0, 0),
166 PadStrideInfo(1, 1, 0, 0),
167 PadStrideInfo(1, 1, 0, 0),
168 PadStrideInfo(1, 1, 0, 0),
169 PadStrideInfo(1, 1, 0, 0),
170 PadStrideInfo(1, 1, 0, 0),
171 PadStrideInfo(1, 1, 1, 0),
172 })),
173 framework::dataset::make("DepthMultiplier", { 1,
174 1,
175 3,
176 1,
177 1,
178 1,
179 2,
180 3,
181 })),
182 framework::dataset::make("Expected", { false, false, false, false, false, false, true, true })),
183 input_info, weights_info, biases_info, output_info, conv_info, depth_multiplier, expected)
184{
185 bool is_valid = bool(NEDepthwiseConvolutionLayer::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), conv_info, depth_multiplier));
186 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
187}
188// clang-format on
189// *INDENT-ON*
190
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000191TEST_SUITE(Float)
192TEST_SUITE(F32)
193TEST_SUITE(Generic)
194template <typename T>
195using NEDepthwiseConvolutionLayerFixture = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
Jenkinsb3a371b2018-05-23 11:36:53 +0100196FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
197 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000198 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100199 DataType::F32)),
Jenkins52ba29e2018-08-29 15:32:11 +0000200 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000201{
202 validate(Accessor(_target), _reference, tolerance_f32);
203}
Jenkinsb3a371b2018-05-23 11:36:53 +0100204FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset(),
205 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000206 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100207 DataType::F32)),
Jenkins52ba29e2018-08-29 15:32:11 +0000208 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000209{
210 validate(Accessor(_target), _reference, tolerance_f32);
211}
212TEST_SUITE_END()
213
214TEST_SUITE(W3x3)
215template <typename T>
216using NEDepthwiseConvolutionLayerFixture3x3 = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
Jenkinsb3a371b2018-05-23 11:36:53 +0100217FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
218 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000219 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100220 DataType::F32)),
Jenkins52ba29e2018-08-29 15:32:11 +0000221 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000222{
223 validate(Accessor(_target), _reference, tolerance_f32);
224}
Jenkinsb3a371b2018-05-23 11:36:53 +0100225FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
226 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000227 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100228 DataType::F32)),
Jenkins52ba29e2018-08-29 15:32:11 +0000229 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000230{
231 validate(Accessor(_target), _reference, tolerance_f32);
232}
Jenkinsb3a371b2018-05-23 11:36:53 +0100233FIXTURE_DATA_TEST_CASE(RunOptimized, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::OptimizedDepthwiseConvolutionLayerDataset3x3(),
234 framework::dataset::make("DepthMultiplier", 1)),
Anthony Barbier06ea0482018-02-22 15:45:35 +0000235 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100236 DataType::F32)),
237 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier06ea0482018-02-22 15:45:35 +0000238{
239 validate(Accessor(_target), _reference, tolerance_f32);
240}
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000241TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000242TEST_SUITE_END()
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000243
244TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000245
246template <typename T>
247using NEDepthwiseConvolutionLayerQuantizedFixture3x3 = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
Anthony Barbier06ea0482018-02-22 15:45:35 +0000248template <typename T>
249using NEDepthwiseConvolutionLayerQuantizedFixture = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000250
251TEST_SUITE(Quantized)
252TEST_SUITE(QASYMM8)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000253TEST_SUITE(Generic)
Jenkinsb3a371b2018-05-23 11:36:53 +0100254FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
255 combine(combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
256 depth_multipliers),
257 framework::dataset::make("DataType", DataType::QASYMM8)),
258 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
Jenkins52ba29e2018-08-29 15:32:11 +0000259 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier06ea0482018-02-22 15:45:35 +0000260{
261 validate(Accessor(_target), _reference, tolerance_qasymm8);
262}
263TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000264TEST_SUITE(W3x3)
Jenkinsb3a371b2018-05-23 11:36:53 +0100265FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::PRECOMMIT,
266 combine(combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), depth_multipliers),
267 framework::dataset::make("DataType", DataType::QASYMM8)),
268 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
Jenkins52ba29e2018-08-29 15:32:11 +0000269 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000270{
271 validate(Accessor(_target), _reference, tolerance_qasymm8);
272}
Jenkinsb3a371b2018-05-23 11:36:53 +0100273FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::NIGHTLY,
274 combine(combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
275 depth_multipliers),
276 framework::dataset::make("DataType", DataType::QASYMM8)),
277 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
Jenkins52ba29e2018-08-29 15:32:11 +0000278 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000279{
280 validate(Accessor(_target), _reference, tolerance_qasymm8);
281}
282TEST_SUITE_END()
283TEST_SUITE_END()
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000284TEST_SUITE_END()
285
286TEST_SUITE_END()
287TEST_SUITE_END()
288} // namespace validation
289} // namespace test
290} // namespace arm_compute