blob: 9b857c81aa318bd72384f9e4eabc24db61a109b7 [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001/*
Anthony Barbierf45d5a92018-01-24 16:23:15 +00002 * Copyright (c) 2017-2018 ARM Limited.
Kaizen8938bd32017-09-28 14:38:23 +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 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"
Anthony Barbier06ea0482018-02-22 15:45:35 +000028#include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h"
Kaizen8938bd32017-09-28 14:38:23 +010029#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/LargeConvolutionLayerDataset.h"
32#include "tests/datasets/SmallConvolutionLayerDataset.h"
Anthony Barbier06ea0482018-02-22 15:45:35 +000033#include "tests/datasets/TinyConvolutionLayerDataset.h"
Kaizen8938bd32017-09-28 14:38:23 +010034#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/ConvolutionLayerFixture.h"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46namespace
47{
48RelativeTolerance<float> tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
49RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
Anthony Barbier8140e1e2017-12-14 23:48:46 +000050constexpr AbsoluteTolerance<float> tolerance_fixed(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
51constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
Kaizen8938bd32017-09-28 14:38:23 +010052constexpr float tolerance_num = 0.07f; /**< Tolerance number */
53
54/** CNN data types */
55const auto CNNDataTypes = framework::dataset::make("DataType",
56{
57 DataType::F16,
58 DataType::F32,
59 DataType::QS8,
60 DataType::QS16,
Anthony Barbier8140e1e2017-12-14 23:48:46 +000061 DataType::QASYMM8,
Kaizen8938bd32017-09-28 14:38:23 +010062});
63} // namespace
64
65TEST_SUITE(CL)
66TEST_SUITE(ConvolutionLayer)
67
Anthony Barbier06ea0482018-02-22 15:45:35 +000068DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
69 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32, 0),
70 TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32, 0),
71 TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32, 0),
72 TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32, 0),
73 TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32, 0)
74 }),
75 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32, 0),
76 TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32, 0),
77 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0),
78 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0),
79 TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16, 0)
80 })),
81 framework::dataset::make("BiasesInfo", { TensorInfo(TensorShape(19U), 1, DataType::F32, 0),
82 TensorInfo(TensorShape(19U), 1, DataType::F32, 0),
83 TensorInfo(TensorShape(21U), 1, DataType::F32, 0),
84 TensorInfo(TensorShape(21U), 1, DataType::F32, 0),
85 TensorInfo(TensorShape(16U), 1, DataType::F32, 0)
86 })),
87 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32, 0),
88 TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32, 0),
89 TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32, 0),
90 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32, 0),
91 TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32, 0)
92 })),
93 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 2, 1, 1),
94 PadStrideInfo(1, 2, 1, 1),
95 PadStrideInfo(1, 1, 0, 0),
96 PadStrideInfo(2, 1, 0, 0),
97 PadStrideInfo(3, 2, 1, 0)
98 })),
99 framework::dataset::make("GpuTarget", { GPUTarget::BIFROST,
100 GPUTarget::MIDGARD,
101 GPUTarget::G70,
102 GPUTarget::MIDGARD,
103 GPUTarget::BIFROST
104 })),
105
106 framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })),
107 input_info, weights_info, biases_info, output_info, conv_info, gpu_target, expected)
108{
109 ConvolutionMethod is_valid = CLConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false),
110 &weights_info.clone()->set_is_resizable(false),
111 &biases_info.clone()->set_is_resizable(false),
112 &output_info.clone()->set_is_resizable(false), conv_info, WeightsInfo(), gpu_target);
113 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
114}
115TEST_SUITE_END()
116
117TEST_SUITE(GEMMConvolutionLayer)
118
Kaizen8938bd32017-09-28 14:38:23 +0100119DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
120 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
121{
122 // Set fixed point position data type allowed
123 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
124
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000125 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
126
Kaizen8938bd32017-09-28 14:38:23 +0100127 // Create tensors
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000128 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
129 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
130 CLTensor bias = create_tensor<CLTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
131 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
Kaizen8938bd32017-09-28 14:38:23 +0100132
133 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
134 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
135 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
136 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
137
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000138 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
139 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
140
Kaizen8938bd32017-09-28 14:38:23 +0100141 // Create and configure function
Anthony Barbier06ea0482018-02-22 15:45:35 +0000142 CLGEMMConvolutionLayer conv;
Kaizen8938bd32017-09-28 14:38:23 +0100143 conv.configure(&src, &weights, &bias, &dst, info);
144
145 // Validate valid region
146 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
147 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
148 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
149 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
150
151 validate(src.info()->valid_region(), src_valid_region);
152 validate(weights.info()->valid_region(), weights_valid_region);
153 validate(bias.info()->valid_region(), bias_valid_region);
154 validate(dst.info()->valid_region(), dst_valid_region);
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000155
156 // Validate QuantizationInfo
157 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
158 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
Kaizen8938bd32017-09-28 14:38:23 +0100159}
160
161template <typename T>
Anthony Barbier06ea0482018-02-22 15:45:35 +0000162using CLGEMMConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
Kaizen8938bd32017-09-28 14:38:23 +0100163
164TEST_SUITE(Float)
165TEST_SUITE(FP16)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000166FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
167 framework::dataset::make("ReshapeWeights", { true })),
168 framework::dataset::make("DataType",
169 DataType::F16)))
Kaizen8938bd32017-09-28 14:38:23 +0100170{
171 // Validate output
172 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
173}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000174FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
175 framework::dataset::make("ReshapeWeights", { true })),
176 framework::dataset::make("DataType",
177 DataType::F16)))
Kaizen8938bd32017-09-28 14:38:23 +0100178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
181}
182TEST_SUITE_END()
183
184TEST_SUITE(FP32)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000185FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
186 framework::dataset::make("ReshapeWeights", { true })),
187 framework::dataset::make("DataType",
188 DataType::F32)))
Kaizen8938bd32017-09-28 14:38:23 +0100189{
190 // Validate output
191 validate(CLAccessor(_target), _reference, tolerance_f32);
192}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000193FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
194 framework::dataset::make("ReshapeWeights", { true })),
195 framework::dataset::make("DataType",
196 DataType::F32)))
Kaizen8938bd32017-09-28 14:38:23 +0100197{
198 // Validate output
199 validate(CLAccessor(_target), _reference, tolerance_f32);
200}
201TEST_SUITE_END()
202TEST_SUITE_END()
203
204template <typename T>
Anthony Barbier06ea0482018-02-22 15:45:35 +0000205using CLGEMMConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
Kaizen8938bd32017-09-28 14:38:23 +0100206
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000207TEST_SUITE(FixedPoint)
Kaizen8938bd32017-09-28 14:38:23 +0100208TEST_SUITE(QS8)
209// We test for fixed point precision [4,6]
Anthony Barbier06ea0482018-02-22 15:45:35 +0000210FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::TinyConvolutionLayerDataset(),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000211 framework::dataset::make("ReshapeWeights", { true })),
Kaizen8938bd32017-09-28 14:38:23 +0100212 framework::dataset::make("DataType",
213 DataType::QS8)),
214 framework::dataset::make("FractionalBits", 4, 7)))
215{
216 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000217 validate(CLAccessor(_target), _reference, tolerance_fixed);
Kaizen8938bd32017-09-28 14:38:23 +0100218}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000219FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
220 framework::dataset::make("ReshapeWeights", { true })),
221 framework::dataset::make("DataType",
222 DataType::QS8)),
223 framework::dataset::make("FractionalBits", 4, 7)))
Kaizen8938bd32017-09-28 14:38:23 +0100224{
225 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000226 validate(CLAccessor(_target), _reference, tolerance_fixed);
Kaizen8938bd32017-09-28 14:38:23 +0100227}
228TEST_SUITE_END()
229
230TEST_SUITE(QS16)
231// Testing for fixed point position [1,14)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000232FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::TinyConvolutionLayerDataset(),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000233 framework::dataset::make("ReshapeWeights", { true })),
Kaizen8938bd32017-09-28 14:38:23 +0100234 framework::dataset::make("DataType",
235 DataType::QS16)),
236 framework::dataset::make("FractionalBits", 1, 14)))
237{
238 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000239 validate(CLAccessor(_target), _reference, tolerance_fixed);
Kaizen8938bd32017-09-28 14:38:23 +0100240}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000241FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
242 framework::dataset::make("ReshapeWeights", { true })),
243 framework::dataset::make("DataType",
244 DataType::QS16)),
245 framework::dataset::make("FractionalBits", 1, 14)))
Kaizen8938bd32017-09-28 14:38:23 +0100246{
247 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000248 validate(CLAccessor(_target), _reference, tolerance_fixed);
249}
250TEST_SUITE_END()
251TEST_SUITE_END()
252
253template <typename T>
Anthony Barbier06ea0482018-02-22 15:45:35 +0000254using CLGEMMConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000255
256TEST_SUITE(Quantized)
257TEST_SUITE(QASYMM8)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000258FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000259 framework::dataset::make("ReshapeWeights", { true })),
260 framework::dataset::make("DataType", DataType::QASYMM8)),
261 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
262{
263 // Validate output
264 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
265}
Anthony Barbier06ea0482018-02-22 15:45:35 +0000266FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
267 framework::dataset::make("ReshapeWeights", { true })),
268 framework::dataset::make("DataType", DataType::QASYMM8)),
269 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000270{
271 // Validate output
272 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
Kaizen8938bd32017-09-28 14:38:23 +0100273}
274TEST_SUITE_END()
275TEST_SUITE_END()
276
277TEST_SUITE_END()
278TEST_SUITE_END()
279} // namespace validation
280} // namespace test
281} // namespace arm_compute