blob: b6f9f62ff0bfe6b3f78b10451ffea39a6d00efcf [file] [log] [blame]
Moritz Pflanzerb3d25792017-07-26 11:49:37 +01001/*
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzerb3d25792017-07-26 11:49:37 +01003 *
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/NEDirectConvolutionLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010028#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/datasets/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/DirectConvolutionLayerFixture.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010045constexpr AbsoluteTolerance<float> tolerance_qs(1.f); /**< Tolerance for fixed point tests */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000046#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010047constexpr AbsoluteTolerance<float> tolerance_fp16(0.01f); /**< Tolerance for half precision floating point tests */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000048#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010049constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010050
51/** Direct convolution data set. */
Georgios Pinitas15997872018-02-19 13:58:22 +000052const auto data_pad_f32 = concat(concat(combine(framework::dataset::make("PadX", 0, 1),
53 combine(framework::dataset::make("PadY", 0, 1),
Pablo Tello06da39d2017-08-10 15:10:40 +010054 framework::dataset::make("KernelSize", 1))),
55 combine(framework::dataset::make("PadX", 0, 2),
56 combine(framework::dataset::make("PadY", 0, 2),
57 framework::dataset::make("KernelSize", 3)))),
58 combine(framework::dataset::make("PadX", 0, 3),
59 combine(framework::dataset::make("PadY", 0, 3),
60 framework::dataset::make("KernelSize", 5))));
61
62const auto data_pad_qs8 = concat(combine(framework::dataset::make("PadX", 0),
63 combine(framework::dataset::make("PadY", 0),
64 framework::dataset::make("KernelSize", 1))),
65 combine(framework::dataset::make("PadX", 0, 2),
66 combine(framework::dataset::make("PadY", 0, 2),
67 framework::dataset::make("KernelSize", 3))));
68
69const auto data_f32 = combine(datasets::SmallDirectConvolutionShapes(),
70 combine(framework::dataset::make("StrideX", 1, 3),
71 combine(framework::dataset::make("StrideY", 1, 3),
72 combine(data_pad_f32,
73 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
74
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000075const auto data_qs8 = combine(datasets::TinyDirectConvolutionShapes(),
Pablo Tello06da39d2017-08-10 15:10:40 +010076 combine(framework::dataset::make("StrideX", 1, 3),
77 combine(framework::dataset::make("StrideY", 1, 3),
78 combine(data_pad_qs8,
79 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010080
81/** Direct convolution QS16 data set. */
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000082const auto data_qs16 = combine(datasets::TinyDirectConvolutionShapes(),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010083 combine(framework::dataset::make("StrideX", 1, 3),
84 combine(framework::dataset::make("StrideY", 1, 3),
85 combine(framework::dataset::make("PadX", 0),
86 combine(framework::dataset::make("PadY", 0),
87 combine(framework::dataset::make("KernelSize", 1),
88 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))))));
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000089/** Activation function Dataset*/
90const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
91{
92 ActivationLayerInfo(),
93 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
94 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f),
95 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f)
96});
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010097} // namespace
98
99TEST_SUITE(NEON)
100TEST_SUITE(DirectConvolutionLayer)
101
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000102// *INDENT-OFF*
103// clang-format off
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000104DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000105 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type input/weights
106 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching input feature maps
107 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Unsupported kernel width
108 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Non-rectangular weights dimensions
109 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid weights dimensions
110 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid stride
111 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid biases size
112 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid biases dimensions
113 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid output size
114 }),
115 framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F16, 0),
116 TensorInfo(TensorShape(3U, 3U, 3U, 4U), 1, DataType::F32, 0),
117 TensorInfo(TensorShape(9U, 9U, 2U, 4U), 1, DataType::F32, 0),
118 TensorInfo(TensorShape(5U, 3U, 2U, 4U), 1, DataType::F32, 0),
119 TensorInfo(TensorShape(3U, 3U, 2U, 4U, 3U), 1, DataType::F32, 0),
120 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0),
121 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0),
122 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0),
123 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0),
124 })),
125 framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
126 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
127 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
128 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
129 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
130 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
131 TensorInfo(TensorShape(3U), 1, DataType::F32, 0),
132 TensorInfo(TensorShape(4U, 2U), 1, DataType::F32, 0),
133 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
134 })),
135 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
136 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
137 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
138 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
139 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
140 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
141 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
142 TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0),
143 TensorInfo(TensorShape(26U, 11U, 4U), 1, DataType::F32, 0),
144 })),
145 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0),
146 PadStrideInfo(1, 1, 0, 0),
147 PadStrideInfo(1, 1, 0, 0),
148 PadStrideInfo(1, 1, 0, 0),
149 PadStrideInfo(1, 1, 0, 0),
150 PadStrideInfo(3, 3, 0, 0),
151 PadStrideInfo(1, 1, 0, 0),
152 PadStrideInfo(1, 1, 0, 0),
153 PadStrideInfo(1, 1, 0, 0),
154 })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000155 framework::dataset::make("ActivationInfo",
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000156{
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000157 ActivationLayerInfo(),
158 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)
159})),
160 framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false })),
161 input_info, weights_info, biases_info, output_info, conv_info, act_info, expected)
162{
163 bool is_valid = bool(NEDirectConvolutionLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &biases_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), conv_info, act_info));
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000164 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
165}
166// clang-format on
167// *INDENT-ON*
168
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100169//TODO(COMPMID-415): Configuration tests?
170
171template <typename T>
172using NEDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>;
173
174TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000175#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100176TEST_SUITE(FP16)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000177FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(data_f32, framework::dataset::make("DataType", DataType::F16)),
178 ActivationFunctionsDataset))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100179{
180 // Validate output
181 validate(Accessor(_target), _reference, tolerance_fp16);
182}
183TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000184#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100185
186TEST_SUITE(FP32)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000187FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(data_f32, framework::dataset::make("DataType", DataType::F32)),
188 ActivationFunctionsDataset))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100189{
190 // Validate output
191 validate(Accessor(_target), _reference, tolerance_fp32);
192}
193TEST_SUITE_END()
194TEST_SUITE_END()
195
196template <typename T>
197using NEDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>;
198
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000199const auto QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
200{
201 ActivationLayerInfo(),
202 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
203 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f)
204});
205
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100206TEST_SUITE(Quantized)
207TEST_SUITE(QS8)
208// We test for fixed point precision [4,6]
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000209FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(data_qs8, framework::dataset::make("DataType", DataType::QS8)),
210 framework::dataset::make("FractionalBits", 4, 7)),
211 QuantizedActivationFunctionsDataset))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100212{
213 // Validate output
214 validate(Accessor(_target), _reference, tolerance_qs);
215}
216TEST_SUITE_END()
217
218TEST_SUITE(QS16)
219// We test for fixed point precision [4,13]
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000220FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(data_qs16, framework::dataset::make("DataType", DataType::QS16)),
221 framework::dataset::make("FractionalBits", 4, 14)),
222 QuantizedActivationFunctionsDataset))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100223{
224 // Validate output
225 validate(Accessor(_target), _reference, tolerance_qs);
226}
227TEST_SUITE_END()
228TEST_SUITE_END()
229
230TEST_SUITE_END()
231TEST_SUITE_END()
232} // namespace validation
233} // namespace test
234} // namespace arm_compute