blob: b2fd22eaee0dd69bdf69da65837d58aa8636041e [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{
Georgios Pinitas583137c2017-08-31 18:12:42 +010046RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47RelativeTolerance<half> tolerance_f16(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 */
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)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100105FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
106 framework::dataset::make("ReshapeWeights", { true, false })),
107 framework::dataset::make("DataType",
108 DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100109{
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}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100113FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
114 framework::dataset::make("ReshapeWeights", { true, false })),
115 framework::dataset::make("DataType",
116 DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100117{
118 // Validate output
steniu013e05e4e2017-08-25 17:18:01 +0100119 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100120}
121TEST_SUITE_END()
122
123TEST_SUITE(FP32)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100124FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
125 framework::dataset::make("ReshapeWeights", { true, false })),
126 framework::dataset::make("DataType",
127 DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100128{
129 // Validate output
130 validate(CLAccessor(_target), _reference, tolerance_f32);
131}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100132FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
133 framework::dataset::make("ReshapeWeights", { true, false })),
134 framework::dataset::make("DataType",
135 DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100136{
137 // Validate output
138 validate(CLAccessor(_target), _reference, tolerance_f32);
139}
140TEST_SUITE_END()
141TEST_SUITE_END()
142
143template <typename T>
144using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>;
145
146TEST_SUITE(Quantized)
147TEST_SUITE(QS8)
148// We test for fixed point precision [4,6]
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100149FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
150 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100151 framework::dataset::make("DataType",
152 DataType::QS8)),
153 framework::dataset::make("FractionalBits", 4, 7)))
154{
155 // Validate output
156 validate(CLAccessor(_target), _reference, tolerance_q);
157}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100158FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
159 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100160 framework::dataset::make("DataType",
161 DataType::QS8)),
162 framework::dataset::make("FractionalBits", 4, 7)))
163{
164 // Validate output
165 validate(CLAccessor(_target), _reference, tolerance_q);
166}
167TEST_SUITE_END()
168
169TEST_SUITE(QS16)
170// Testing for fixed point position [1,14)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100171FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
172 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100173 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}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100180FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
181 framework::dataset::make("ReshapeWeights", { true, false })),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100182 framework::dataset::make("DataType",
183 DataType::QS16)),
184 framework::dataset::make("FractionalBits", 1, 14)))
185{
186 // Validate output
187 validate(CLAccessor(_target), _reference, tolerance_q);
188}
189TEST_SUITE_END()
190TEST_SUITE_END()
191
192TEST_SUITE_END()
193TEST_SUITE_END()
194} // namespace validation
195} // namespace test
196} // namespace arm_compute