blob: 035e492ea19e90c02b55be2b4a62c4622a697ec4 [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001/*
2 * Copyright (c) 2017 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 "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/LargeConvolutionLayerDataset.h"
31#include "tests/datasets/SmallConvolutionLayerDataset.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 */
Anthony Barbier8140e1e2017-12-14 23:48:46 +000048constexpr 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 */
Kaizen8938bd32017-09-28 14:38:23 +010050constexpr 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,
Anthony Barbier8140e1e2017-12-14 23:48:46 +000059 DataType::QASYMM8,
Kaizen8938bd32017-09-28 14:38:23 +010060});
61} // namespace
62
63TEST_SUITE(CL)
64TEST_SUITE(ConvolutionLayer)
65
66DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
67 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
68{
69 // Set fixed point position data type allowed
70 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
71
Anthony Barbier8140e1e2017-12-14 23:48:46 +000072 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
73
Kaizen8938bd32017-09-28 14:38:23 +010074 // Create tensors
Anthony Barbier8140e1e2017-12-14 23:48:46 +000075 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
76 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
77 CLTensor bias = create_tensor<CLTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
78 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 +010079
80 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
83 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
84
Anthony Barbier8140e1e2017-12-14 23:48:46 +000085 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
86 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
87
Kaizen8938bd32017-09-28 14:38:23 +010088 // Create and configure function
89 CLConvolutionLayer conv;
90 conv.configure(&src, &weights, &bias, &dst, info);
91
92 // Validate valid region
93 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
94 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
95 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
96 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
97
98 validate(src.info()->valid_region(), src_valid_region);
99 validate(weights.info()->valid_region(), weights_valid_region);
100 validate(bias.info()->valid_region(), bias_valid_region);
101 validate(dst.info()->valid_region(), dst_valid_region);
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000102
103 // Validate QuantizationInfo
104 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
105 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
Kaizen8938bd32017-09-28 14:38:23 +0100106}
107
108template <typename T>
109using CLConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
110
111TEST_SUITE(Float)
112TEST_SUITE(FP16)
113FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
114 framework::dataset::make("ReshapeWeights", { true, false })),
115 framework::dataset::make("DataType",
116 DataType::F16)))
117{
118 // Validate output
119 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
120}
121FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
122 framework::dataset::make("ReshapeWeights", { true, false })),
123 framework::dataset::make("DataType",
124 DataType::F16)))
125{
126 // Validate output
127 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
128}
129TEST_SUITE_END()
130
131TEST_SUITE(FP32)
132FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
133 framework::dataset::make("ReshapeWeights", { true, false })),
134 framework::dataset::make("DataType",
135 DataType::F32)))
136{
137 // Validate output
138 validate(CLAccessor(_target), _reference, tolerance_f32);
139}
140FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
141 framework::dataset::make("ReshapeWeights", { true, false })),
142 framework::dataset::make("DataType",
143 DataType::F32)))
144{
145 // Validate output
146 validate(CLAccessor(_target), _reference, tolerance_f32);
147}
148TEST_SUITE_END()
149TEST_SUITE_END()
150
151template <typename T>
152using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
153
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000154TEST_SUITE(FixedPoint)
Kaizen8938bd32017-09-28 14:38:23 +0100155TEST_SUITE(QS8)
156// We test for fixed point precision [4,6]
157FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
158 framework::dataset::make("ReshapeWeights", { true, false })),
159 framework::dataset::make("DataType",
160 DataType::QS8)),
161 framework::dataset::make("FractionalBits", 4, 7)))
162{
163 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000164 validate(CLAccessor(_target), _reference, tolerance_fixed);
Kaizen8938bd32017-09-28 14:38:23 +0100165}
166FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
167 framework::dataset::make("ReshapeWeights", { true, false })),
168 framework::dataset::make("DataType",
169 DataType::QS8)),
170 framework::dataset::make("FractionalBits", 4, 7)))
171{
172 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000173 validate(CLAccessor(_target), _reference, tolerance_fixed);
Kaizen8938bd32017-09-28 14:38:23 +0100174}
175TEST_SUITE_END()
176
177TEST_SUITE(QS16)
178// Testing for fixed point position [1,14)
179FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
180 framework::dataset::make("ReshapeWeights", { true, false })),
181 framework::dataset::make("DataType",
182 DataType::QS16)),
183 framework::dataset::make("FractionalBits", 1, 14)))
184{
185 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000186 validate(CLAccessor(_target), _reference, tolerance_fixed);
Kaizen8938bd32017-09-28 14:38:23 +0100187}
188FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
189 framework::dataset::make("ReshapeWeights", { true, false })),
190 framework::dataset::make("DataType",
191 DataType::QS16)),
192 framework::dataset::make("FractionalBits", 1, 14)))
193{
194 // Validate output
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000195 validate(CLAccessor(_target), _reference, tolerance_fixed);
196}
197TEST_SUITE_END()
198TEST_SUITE_END()
199
200template <typename T>
201using CLConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
202
203TEST_SUITE(Quantized)
204TEST_SUITE(QASYMM8)
205FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
206 framework::dataset::make("ReshapeWeights", { true })),
207 framework::dataset::make("DataType", DataType::QASYMM8)),
208 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
209{
210 // Validate output
211 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
212}
213FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
214 framework::dataset::make("ReshapeWeights", { true })),
215 framework::dataset::make("DataType", DataType::QASYMM8)),
216 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })))
217{
218 // Validate output
219 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
Kaizen8938bd32017-09-28 14:38:23 +0100220}
221TEST_SUITE_END()
222TEST_SUITE_END()
223
224TEST_SUITE_END()
225TEST_SUITE_END()
226} // namespace validation
227} // namespace test
228} // namespace arm_compute