blob: d7123842e90eb53a6b3946dbd6340e9f3867a5a9 [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"
37#include "tests/validation/half.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010038
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010047constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
48constexpr AbsoluteTolerance<float> tolerance_f16(0.1f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
49constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010050
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 // Validate padding
97 //TODO(COMPMID-415) Need to validate padding?
98}
99
100template <typename T>
101using CLConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
102
103TEST_SUITE(Float)
104TEST_SUITE(FP16)
105FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallConvolutionLayerDataset(),
106 framework::dataset::make("DataType",
107 DataType::F16)))
108{
109 // Validate output
110 validate(CLAccessor(_target), _reference, tolerance_f16);
111}
112FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeConvolutionLayerDataset(),
113 framework::dataset::make("DataType",
114 DataType::F16)))
115{
116 // Validate output
117 validate(CLAccessor(_target), _reference, tolerance_f16);
118}
119TEST_SUITE_END()
120
121TEST_SUITE(FP32)
122FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallConvolutionLayerDataset(), framework::dataset::make("DataType",
123 DataType::F32)))
124{
125 // Validate output
126 validate(CLAccessor(_target), _reference, tolerance_f32);
127}
128FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeConvolutionLayerDataset(), framework::dataset::make("DataType",
129 DataType::F32)))
130{
131 // Validate output
132 validate(CLAccessor(_target), _reference, tolerance_f32);
133}
134TEST_SUITE_END()
135TEST_SUITE_END()
136
137template <typename T>
138using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
139
140TEST_SUITE(Quantized)
141TEST_SUITE(QS8)
142// We test for fixed point precision [4,6]
143FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
144 framework::dataset::make("DataType",
145 DataType::QS8)),
146 framework::dataset::make("FractionalBits", 4, 7)))
147{
148 // Validate output
149 validate(CLAccessor(_target), _reference, tolerance_q);
150}
151FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
152 framework::dataset::make("DataType",
153 DataType::QS8)),
154 framework::dataset::make("FractionalBits", 4, 7)))
155{
156 // Validate output
157 validate(CLAccessor(_target), _reference, tolerance_q);
158}
159TEST_SUITE_END()
160
161TEST_SUITE(QS16)
162// Testing for fixed point position [1,14)
163FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
164 framework::dataset::make("DataType",
165 DataType::QS16)),
166 framework::dataset::make("FractionalBits", 1, 14)))
167{
168 // Validate output
169 validate(CLAccessor(_target), _reference, tolerance_q);
170}
171FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
172 framework::dataset::make("DataType",
173 DataType::QS16)),
174 framework::dataset::make("FractionalBits", 1, 14)))
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_q);
178}
179TEST_SUITE_END()
180TEST_SUITE_END()
181
182TEST_SUITE_END()
183TEST_SUITE_END()
184} // namespace validation
185} // namespace test
186} // namespace arm_compute