blob: 575ffe17a993977f78ff46e856cfd349c5e79b17 [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 CONNECTION 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/NEON/functions/NEConvolutionLayer.h"
Pablo Tello89519332017-11-17 11:52:36 +000026#include "arm_compute/runtime/NEON/functions/NEWinogradLayer.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010027#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010029#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/LargeConvolutionLayerDataset.h"
32#include "tests/datasets/SmallConvolutionLayerDataset.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/ConvolutionLayerFixture.h"
Pablo Tello89519332017-11-17 11:52:36 +000038#include "tests/validation/fixtures/WinogradLayerFixture.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010039
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46namespace
47{
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010048const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000049#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010050const AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000051#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010052const 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 +010053
54/** CNN data types */
55const auto CNNDataTypes = framework::dataset::make("DataType",
56{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000057#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010058 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000059#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010060 DataType::F32,
61 DataType::QS8,
62 DataType::QS16,
63});
64} // namespace
65
66TEST_SUITE(NEON)
Pablo Tello89519332017-11-17 11:52:36 +000067
68#if defined(__aarch64__)
69TEST_SUITE(WinogradLayer)
70template <typename T>
71using NEWinogradLayerFixture = WinogradLayerValidationFixture<Tensor, Accessor, NEWinogradLayer, T>;
72
73TEST_SUITE(FP32)
74FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradLayerFixture<float>, framework::DatasetMode::PRECOMMIT, datasets::SmallWinogradLayerDataset())
75{
76 // Validate output
77 validate(Accessor(_target), _reference, tolerance_f32);
78}
79
80TEST_SUITE_END()
81TEST_SUITE_END()
82#endif /* __aarch64__ */
83
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010084TEST_SUITE(ConvolutionLayer)
85
86DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
87 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
88{
89 // Set fixed point position data type allowed
90 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
91
92 // Create tensors
93 Tensor src = create_tensor<Tensor>(input_shape, data_type, 1, fixed_point_position);
94 Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1, fixed_point_position);
95 Tensor bias = create_tensor<Tensor>(bias_shape, data_type, 1, fixed_point_position);
96 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position);
97
98 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
99 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
100 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
101 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
102
103 // Create and configure function
104 NEConvolutionLayer conv;
105 conv.configure(&src, &weights, &bias, &dst, info);
106
107 // Validate valid region
108 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
109 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
110 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
111 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
112
113 validate(src.info()->valid_region(), src_valid_region);
114 validate(weights.info()->valid_region(), weights_valid_region);
115 validate(bias.info()->valid_region(), bias_valid_region);
116 validate(dst.info()->valid_region(), dst_valid_region);
117
118 // Validate padding
119 //TODO(COMPMID-415) Need to validate padding?
120}
121
122template <typename T>
123using NEConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
124
125TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000126#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100127TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100128FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
129 framework::dataset::make("ReshapeWeights", { true, false })),
130 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100131{
132 // Validate output
133 validate(Accessor(_target), _reference, tolerance_f16);
134}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100135FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
136 framework::dataset::make("ReshapeWeights", { true, false })),
137 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100138{
139 // Validate output
140 validate(Accessor(_target), _reference, tolerance_f16);
141}
142TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000143#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100144
145TEST_SUITE(FP32)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100146FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
147 framework::dataset::make("ReshapeWeights", { true, false })),
148 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100149{
150 // Validate output
151 validate(Accessor(_target), _reference, tolerance_f32);
152}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100153FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
154 framework::dataset::make("ReshapeWeights", { true, false })),
155 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100156{
157 // Validate output
158 validate(Accessor(_target), _reference, tolerance_f32);
159}
160TEST_SUITE_END()
161TEST_SUITE_END()
162
163template <typename T>
164using NEConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<Tensor, Accessor, NEConvolutionLayer, T>;
165
166TEST_SUITE(Quantized)
167TEST_SUITE(QS8)
168// We test for fixed point precision [4,6]
Georgios Pinitasce54b562017-09-14 17:21:51 +0100169FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
170 framework::dataset::make("ReshapeWeights", { true, false })),
171 framework::dataset::make("DataType", DataType::QS8)),
172 framework::dataset::make("FractionalBits", 4, 7)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100173{
174 // Validate output
175 validate(Accessor(_target), _reference, tolerance_q);
176}
Georgios Pinitasce54b562017-09-14 17:21:51 +0100177FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
178 framework::dataset::make("ReshapeWeights", { true, false })),
179 framework::dataset::make("DataType", DataType::QS8)),
180 framework::dataset::make("FractionalBits", 4, 7)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100181{
182 // Validate output
183 validate(Accessor(_target), _reference, tolerance_q);
184}
185TEST_SUITE_END()
186
187TEST_SUITE(QS16)
188// Testing for fixed point position [1,14)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100189FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
190 framework::dataset::make("ReshapeWeights", { true, false })),
191 framework::dataset::make("DataType", DataType::QS16)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100192 framework::dataset::make("FractionalBits", 1, 14)))
193{
194 // Validate output
195 validate(Accessor(_target), _reference, tolerance_q);
196}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100197FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
198 framework::dataset::make("ReshapeWeights", { true, false })),
199 framework::dataset::make("DataType", DataType::QS16)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100200 framework::dataset::make("FractionalBits", 1, 14)))
201{
202 // Validate output
203 validate(Accessor(_target), _reference, tolerance_q);
204}
205TEST_SUITE_END()
206TEST_SUITE_END()
207
208TEST_SUITE_END()
209TEST_SUITE_END()
210} // namespace validation
211} // namespace test
212} // namespace arm_compute