blob: 9f9295c7771f6ad77ede368092dcf4641e1b5d8c [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 */
48constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
49constexpr float tolerance_num = 0.07f; /**< Tolerance number */
50
51/** CNN data types */
52const auto CNNDataTypes = framework::dataset::make("DataType",
53{
54 DataType::F16,
55 DataType::F32,
56 DataType::QS8,
57 DataType::QS16,
58});
59} // namespace
60
61TEST_SUITE(CL)
62TEST_SUITE(ConvolutionLayer)
63
64DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
65 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
66{
67 // Set fixed point position data type allowed
68 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
69
70 // Create tensors
71 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position);
72 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position);
73 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type, 1, fixed_point_position);
74 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position);
75
76 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
77 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
80
81 // Create and configure function
82 CLConvolutionLayer conv;
83 conv.configure(&src, &weights, &bias, &dst, info);
84
85 // Validate valid region
86 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
87 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
88 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
89 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
90
91 validate(src.info()->valid_region(), src_valid_region);
92 validate(weights.info()->valid_region(), weights_valid_region);
93 validate(bias.info()->valid_region(), bias_valid_region);
94 validate(dst.info()->valid_region(), dst_valid_region);
95}
96
97template <typename T>
98using CLConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
99
100TEST_SUITE(Float)
101TEST_SUITE(FP16)
102FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
103 framework::dataset::make("ReshapeWeights", { true, false })),
104 framework::dataset::make("DataType",
105 DataType::F16)))
106{
107 // Validate output
108 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
109}
110FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
111 framework::dataset::make("ReshapeWeights", { true, false })),
112 framework::dataset::make("DataType",
113 DataType::F16)))
114{
115 // Validate output
116 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
117}
118TEST_SUITE_END()
119
120TEST_SUITE(FP32)
121FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
122 framework::dataset::make("ReshapeWeights", { true, false })),
123 framework::dataset::make("DataType",
124 DataType::F32)))
125{
126 // Validate output
127 validate(CLAccessor(_target), _reference, tolerance_f32);
128}
129FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
130 framework::dataset::make("ReshapeWeights", { true, false })),
131 framework::dataset::make("DataType",
132 DataType::F32)))
133{
134 // Validate output
135 validate(CLAccessor(_target), _reference, tolerance_f32);
136}
137TEST_SUITE_END()
138TEST_SUITE_END()
139
140template <typename T>
141using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
142
143TEST_SUITE(Quantized)
144TEST_SUITE(QS8)
145// We test for fixed point precision [4,6]
146FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
147 framework::dataset::make("ReshapeWeights", { true, false })),
148 framework::dataset::make("DataType",
149 DataType::QS8)),
150 framework::dataset::make("FractionalBits", 4, 7)))
151{
152 // Validate output
153 validate(CLAccessor(_target), _reference, tolerance_q);
154}
155FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
156 framework::dataset::make("ReshapeWeights", { true, false })),
157 framework::dataset::make("DataType",
158 DataType::QS8)),
159 framework::dataset::make("FractionalBits", 4, 7)))
160{
161 // Validate output
162 validate(CLAccessor(_target), _reference, tolerance_q);
163}
164TEST_SUITE_END()
165
166TEST_SUITE(QS16)
167// Testing for fixed point position [1,14)
168FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
169 framework::dataset::make("ReshapeWeights", { true, false })),
170 framework::dataset::make("DataType",
171 DataType::QS16)),
172 framework::dataset::make("FractionalBits", 1, 14)))
173{
174 // Validate output
175 validate(CLAccessor(_target), _reference, tolerance_q);
176}
177FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
178 framework::dataset::make("ReshapeWeights", { true, false })),
179 framework::dataset::make("DataType",
180 DataType::QS16)),
181 framework::dataset::make("FractionalBits", 1, 14)))
182{
183 // Validate output
184 validate(CLAccessor(_target), _reference, tolerance_q);
185}
186TEST_SUITE_END()
187TEST_SUITE_END()
188
189TEST_SUITE_END()
190TEST_SUITE_END()
191} // namespace validation
192} // namespace test
193} // namespace arm_compute