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