blob: 532d04b4312043c529fa1452b9ce5f190e3288fd [file] [log] [blame]
Alex Gilday7da29b62018-03-23 14:16:00 +00001/*
2 * Copyright (c) 2018 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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h"
28#include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/DilatedConvolutionLayerDataset.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/ConvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
48constexpr AbsoluteTolerance<float> tolerance_fixed(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
49constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
50constexpr float tolerance_num = 0.07f; /**< Tolerance number */
51
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
55 DataType::F16,
56 DataType::F32,
57 DataType::QS8,
58 DataType::QS16,
59 DataType::QASYMM8,
60});
61} // namespace
62
63TEST_SUITE(CL)
64TEST_SUITE(DilatedConvolutionLayer)
65
66DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
67 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32, 0),
68 TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32, 0),
69 TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32, 0),
70 TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32, 0),
71 TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32, 0)
72 }),
73 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32, 0),
74 TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32, 0),
75 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0),
76 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0),
77 TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16, 0)
78 })),
79 framework::dataset::make("BiasesInfo", { TensorInfo(TensorShape(19U), 1, DataType::F32, 0),
80 TensorInfo(TensorShape(19U), 1, DataType::F32, 0),
81 TensorInfo(TensorShape(21U), 1, DataType::F32, 0),
82 TensorInfo(TensorShape(21U), 1, DataType::F32, 0),
83 TensorInfo(TensorShape(16U), 1, DataType::F32, 0)
84 })),
85 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32, 0),
86 TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32, 0),
87 TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32, 0),
88 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32, 0),
89 TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32, 0)
90 })),
91 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 2, 1, 1),
92 PadStrideInfo(1, 2, 1, 1),
93 PadStrideInfo(1, 1, 0, 0),
94 PadStrideInfo(2, 1, 0, 0),
95 PadStrideInfo(3, 2, 1, 0)
96 })),
97 framework::dataset::make("GpuTarget", { GPUTarget::BIFROST,
98 GPUTarget::MIDGARD,
99 GPUTarget::G71,
100 GPUTarget::MIDGARD,
101 GPUTarget::BIFROST
102 })),
103 framework::dataset::make("Dilation", { Size2D(1U, 1U),
104 Size2D(1U, 1U),
105 Size2D(1U, 1U),
106 Size2D(2U, 2U),
107 Size2D(3U, 3U)
108 })),
109
110 framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })),
111 input_info, weights_info, biases_info, output_info, conv_info, gpu_target, dilation, expected)
112{
113 ConvolutionMethod is_valid = CLConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false),
114 &weights_info.clone()->set_is_resizable(false),
115 &biases_info.clone()->set_is_resizable(false),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000116 &output_info.clone()->set_is_resizable(false), conv_info, WeightsInfo(), ActivationLayerInfo(), gpu_target, dilation);
Alex Gilday7da29b62018-03-23 14:16:00 +0000117 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
118}
119TEST_SUITE_END()
120
121TEST_SUITE(GEMMDilatedConvolutionLayer)
122
123DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDilatedConvolutionLayerDataset(), datasets::LargeDilatedConvolutionLayerDataset()),
124 CNNDataTypes),
125 input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type)
126{
127 // Set fixed point position data type allowed
128 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
129
130 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
131
132 // Create tensors
133 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
134 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
135 CLTensor bias = create_tensor<CLTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
136 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
137
138 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
139 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
140 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
141 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
142
143 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
144 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
145
146 // Create and configure function
147 CLGEMMConvolutionLayer conv;
148 conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation);
149
150 // Validate valid region
151 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
152 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
153 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
154 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
155
156 validate(src.info()->valid_region(), src_valid_region);
157 validate(weights.info()->valid_region(), weights_valid_region);
158 validate(bias.info()->valid_region(), bias_valid_region);
159 validate(dst.info()->valid_region(), dst_valid_region);
160
161 // Validate QuantizationInfo
162 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
163 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
164
165 // Validate padding
166 //TODO(COMPMID-415) Need to validate padding?
167}
168
169template <typename T>
170using CLGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
171
172TEST_SUITE(Float)
173TEST_SUITE(FP16)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000174FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000175 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000176 framework::dataset::make("DataType", DataType::F16)),
177 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
181}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000182FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000183 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000184 framework::dataset::make("DataType", DataType::F16)),
185 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000186{
187 // Validate output
188 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
189}
190TEST_SUITE_END()
191
192TEST_SUITE(FP32)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000193FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000194 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000195 framework::dataset::make("DataType", DataType::F32)),
196 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000197{
198 // Validate output
199 validate(CLAccessor(_target), _reference, tolerance_f32);
200}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000201FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000202 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000203 framework::dataset::make("DataType", DataType::F32)),
204 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000205{
206 // Validate output
207 validate(CLAccessor(_target), _reference, tolerance_f32);
208}
209TEST_SUITE_END()
210TEST_SUITE_END()
211
212template <typename T>
213using CLGEMMDilatedConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
214
215TEST_SUITE(FixedPoint)
216TEST_SUITE(QS8)
217// We test for fixed point precision [4,6]
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000218FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMDilatedConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
219 combine(combine(combine(combine(datasets::TinyDilatedConvolutionLayerDataset(),
220 framework::dataset::make("ReshapeWeights", { true })),
221 framework::dataset::make("DataType",
222 DataType::QS8)),
223 framework::dataset::make("FractionalBits", 4, 7)),
224 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000225{
226 // Validate output
227 validate(CLAccessor(_target), _reference, tolerance_fixed);
228}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000229FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY,
230 combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
231 framework::dataset::make("ReshapeWeights", { true })),
232 framework::dataset::make("DataType",
233 DataType::QS8)),
234 framework::dataset::make("FractionalBits", 4, 7)),
235 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000236{
237 // Validate output
238 validate(CLAccessor(_target), _reference, tolerance_fixed);
239}
240TEST_SUITE_END()
241
242TEST_SUITE(QS16)
243// Testing for fixed point position [1,14)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000244FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMDilatedConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT,
245 combine(combine(combine(combine(datasets::TinyDilatedConvolutionLayerDataset(),
246 framework::dataset::make("ReshapeWeights", { true })),
247 framework::dataset::make("DataType",
248 DataType::QS16)),
249 framework::dataset::make("FractionalBits", 1, 14)),
250 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000251{
252 // Validate output
253 validate(CLAccessor(_target), _reference, tolerance_fixed);
254}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000255FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY,
256 combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
257 framework::dataset::make("ReshapeWeights", { true })),
258 framework::dataset::make("DataType",
259 DataType::QS16)),
260 framework::dataset::make("FractionalBits", 1, 14)),
261 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000262{
263 // Validate output
264 validate(CLAccessor(_target), _reference, tolerance_fixed);
265}
266TEST_SUITE_END()
267TEST_SUITE_END()
268
269template <typename T>
270using CLGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
271
272TEST_SUITE(Quantized)
273TEST_SUITE(QASYMM8)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000274FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
275 combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
276 framework::dataset::make("ReshapeWeights", { true })),
277 framework::dataset::make("DataType", DataType::QASYMM8)),
278 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
279 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000280{
281 // Validate output
282 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
283}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000284FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
285 combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
286 framework::dataset::make("ReshapeWeights", { true })),
287 framework::dataset::make("DataType", DataType::QASYMM8)),
288 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })),
289 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000290{
291 // Validate output
292 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
293}
294TEST_SUITE_END()
295TEST_SUITE_END()
296
297TEST_SUITE_END()
298TEST_SUITE_END()
299} // namespace validation
300} // namespace test
301} // namespace arm_compute