blob: 56e10f01b384b0c0699b00a364c6f3ee80197ab9 [file] [log] [blame]
Moritz Pflanzerb3d25792017-07-26 11:49:37 +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"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010028#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#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"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
steniu01f81652d2017-09-11 15:29:12 +010046RelativeTolerance<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 */
Chunosov5124be52017-11-22 20:42:13 +070048constexpr 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 */
steniu01f81652d2017-09-11 15:29:12 +010050constexpr float tolerance_num = 0.07f; /**< Tolerance number */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010051
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
55 DataType::F16,
56 DataType::F32,
57 DataType::QS8,
58 DataType::QS16,
Chunosov5124be52017-11-22 20:42:13 +070059 DataType::QASYMM8,
Moritz Pflanzerb3d25792017-07-26 11:49:37 +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
Chunosov5124be52017-11-22 20:42:13 +070072 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
73
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010074 // Create tensors
Chunosov5124be52017-11-22 20:42:13 +070075 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));
Moritz Pflanzerb3d25792017-07-26 11:49:37 +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
Chunosov5124be52017-11-22 20:42:13 +070085 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
86 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
87
Moritz Pflanzerb3d25792017-07-26 11:49:37 +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);
102
Chunosov5124be52017-11-22 20:42:13 +0700103 // 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);
106
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100107 // Validate padding
108 //TODO(COMPMID-415) Need to validate padding?
109}
110
111template <typename T>
112using CLConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
113
114TEST_SUITE(Float)
115TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100116FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
117 framework::dataset::make("ReshapeWeights", { true, false })),
118 framework::dataset::make("DataType",
119 DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100120{
121 // Validate output
steniu013e05e4e2017-08-25 17:18:01 +0100122 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100123}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100124FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
125 framework::dataset::make("ReshapeWeights", { true, false })),
126 framework::dataset::make("DataType",
127 DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100128{
129 // Validate output
steniu013e05e4e2017-08-25 17:18:01 +0100130 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100131}
132TEST_SUITE_END()
133
134TEST_SUITE(FP32)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100135FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
136 framework::dataset::make("ReshapeWeights", { true, false })),
137 framework::dataset::make("DataType",
138 DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100139{
140 // Validate output
141 validate(CLAccessor(_target), _reference, tolerance_f32);
142}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100143FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
144 framework::dataset::make("ReshapeWeights", { true, false })),
145 framework::dataset::make("DataType",
146 DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100147{
148 // Validate output
149 validate(CLAccessor(_target), _reference, tolerance_f32);
150}
151TEST_SUITE_END()
152TEST_SUITE_END()
153
154template <typename T>
155using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
156
Chunosov5124be52017-11-22 20:42:13 +0700157TEST_SUITE(FixedPoint)
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100158TEST_SUITE(QS8)
159// We test for fixed point precision [4,6]
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100160FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
161 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100162 framework::dataset::make("DataType",
163 DataType::QS8)),
164 framework::dataset::make("FractionalBits", 4, 7)))
165{
166 // Validate output
Chunosov5124be52017-11-22 20:42:13 +0700167 validate(CLAccessor(_target), _reference, tolerance_fixed);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100168}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100169FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
170 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100171 framework::dataset::make("DataType",
172 DataType::QS8)),
173 framework::dataset::make("FractionalBits", 4, 7)))
174{
175 // Validate output
Chunosov5124be52017-11-22 20:42:13 +0700176 validate(CLAccessor(_target), _reference, tolerance_fixed);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100177}
178TEST_SUITE_END()
179
180TEST_SUITE(QS16)
181// Testing for fixed point position [1,14)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100182FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
183 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100184 framework::dataset::make("DataType",
185 DataType::QS16)),
186 framework::dataset::make("FractionalBits", 1, 14)))
187{
188 // Validate output
Chunosov5124be52017-11-22 20:42:13 +0700189 validate(CLAccessor(_target), _reference, tolerance_fixed);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100190}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100191FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
192 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100193 framework::dataset::make("DataType",
194 DataType::QS16)),
195 framework::dataset::make("FractionalBits", 1, 14)))
196{
197 // Validate output
Chunosov5124be52017-11-22 20:42:13 +0700198 validate(CLAccessor(_target), _reference, tolerance_fixed);
199}
200TEST_SUITE_END()
201TEST_SUITE_END()
202
203template <typename T>
204using CLConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
205
206TEST_SUITE(Quantized)
207TEST_SUITE(QASYMM8)
208FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
209 framework::dataset::make("ReshapeWeights", { true })),
210 framework::dataset::make("DataType", DataType::QASYMM8)),
211 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
212{
213 // Validate output
214 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
215}
216FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
217 framework::dataset::make("ReshapeWeights", { true })),
218 framework::dataset::make("DataType", DataType::QASYMM8)),
219 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })))
220{
221 // Validate output
222 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100223}
224TEST_SUITE_END()
225TEST_SUITE_END()
226
227TEST_SUITE_END()
228TEST_SUITE_END()
229} // namespace validation
230} // namespace test
231} // namespace arm_compute