blob: 413250f75597433e10dd88504b8ba1e8163327d8 [file] [log] [blame]
Moritz Pflanzer69d33412017-08-09 11:45:15 +01001/*
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +01002 * Copyright (c) 2017-2021 Arm Limited.
Moritz Pflanzer69d33412017-08-09 11:45:15 +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/NEFullyConnectedLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +010028#include "src/core/helpers/MemoryHelpers.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/cpu/operators/CpuFullyConnected.h"
Moritz Pflanzer69d33412017-08-09 11:45:15 +010030#include "tests/NEON/Accessor.h"
31#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010032#include "tests/datasets/FullyConnectedLayerDataset.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/FullyConnectedLayerFixture.h"
Moritz Pflanzer69d33412017-08-09 11:45:15 +010038
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47/** Tolerance for float operations */
Michele Di Giorgio419f33a2018-08-27 14:25:24 +010048constexpr RelativeTolerance<float> rel_tolerance_f32(0.01f); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F32 */
49constexpr AbsoluteTolerance<float> abs_tolerance_f32(0.001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F32 */
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000050#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Gian Marco Iodice35aea372018-08-24 14:30:36 +010051const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
52const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F16 */
53constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
54#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC*/
Moritz Pflanzer69d33412017-08-09 11:45:15 +010055
Giorgio Arenaa855af12018-07-16 17:20:38 +010056/** Tolerance for quantized asymmetric operations */
57constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
Michele Di Giorgio9c700372020-01-08 11:33:44 +000058constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1);
Giorgio Arenaa855af12018-07-16 17:20:38 +010059
Moritz Pflanzer69d33412017-08-09 11:45:15 +010060/** CNN data types */
61const auto CNNDataTypes = framework::dataset::make("DataType",
62{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000063#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer69d33412017-08-09 11:45:15 +010064 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000065#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer69d33412017-08-09 11:45:15 +010066 DataType::F32,
Moritz Pflanzer69d33412017-08-09 11:45:15 +010067});
68
69const auto FullyConnectedParameters = combine(framework::dataset::make("TransposeWeights", { false, true }), framework::dataset::make("ReshapeWeights", { false, true }));
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000070
71const auto QuantizationData = framework::dataset::make("QuantizationInfo",
72{
73 QuantizationInfo(1.f / 256.f, 10),
74 QuantizationInfo(1.1f, 10),
75});
SiCongLi2e5fd632020-03-02 15:39:15 +000076const auto EmptyActivationFunctionDataset = framework::dataset::make("ActivationInfo",
77{
78 ActivationLayerInfo(),
79});
80const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
81{
82 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
83 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f),
84 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f),
85 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH),
86});
Giorgio Arena1856ff72020-02-07 13:46:45 +000087
SiCongLi2e5fd632020-03-02 15:39:15 +000088const auto ActivationFunctionsQuantizedDataset = framework::dataset::make("ActivationInfo",
89{
90 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
91 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f),
92 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f),
93});
Moritz Pflanzer69d33412017-08-09 11:45:15 +010094} // namespace
95
96TEST_SUITE(NEON)
97TEST_SUITE(FullyConnectedLayer)
98
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +010099/** Test case for memory injection in @ref cpu::CpuFullyConnected.
100 *
101 * Configure the operator once and inject memory at run-time in multiple executions.
102 *
103 * Checks performed in order:
104 * - Both runs compute the same output
105 */
106TEST_CASE(MemoryInjection, framework::DatasetMode::ALL)
107{
108 auto fc = std::make_unique<cpu::CpuFullyConnected>();
109 const auto src_info = TensorInfo(TensorShape(8U), 1, DataType::F32, DataLayout::NHWC);
110 const auto weight_info = TensorInfo(TensorShape(8U, 4U), 1, DataType::F32, DataLayout::NHWC);
111 const auto bias_info = TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC);
112 auto dst_info = TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC);
113 const auto fc_info = FullyConnectedLayerInfo{};
114 fc->configure(&src_info, &weight_info, &bias_info, &dst_info, fc_info);
115
116 // telhs are newly created every call of this lambda function
117 auto src = create_tensor<Tensor>(src_info);
118 auto weight = create_tensor<Tensor>(weight_info);
119 auto bias = create_tensor<Tensor>(bias_info);
120 src.allocator()->allocate();
121 weight.allocator()->allocate();
122 bias.allocator()->allocate();
123
124 ITensorPack run_pack{ { TensorType::ACL_SRC_0, &src }, { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } };
125 ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } };
126
127 auto mg = MemoryGroup{};
128 auto ws = manage_workspace<Tensor>(fc->workspace(), mg, run_pack, prep_pack);
129
130 auto run_conv = [&]() -> Tensor
131 {
132 auto dst = create_tensor<Tensor>(dst_info);
133 dst.allocator()->allocate();
134 run_pack.add_tensor(TensorType::ACL_DST, &dst);
135
136 library->fill_tensor_value(Accessor(src), 1.f);
137 library->fill_tensor_value(Accessor(weight), 2.f);
138 library->fill_tensor_value(Accessor(bias), 3.f);
139 // This operator is configured once and captured by this lambda.
140 fc->prepare(prep_pack);
141 fc->run(run_pack);
142 return dst;
143 };
144 auto result_0 = run_conv();
145 auto result_1 = run_conv();
146 for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i)
147 {
148 ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS);
149 }
150}
151
152/** Test case for memory injection in @ref NEFullyConnectedLayer.
153 *
154 * Make sure @ref NEFullyConnectedLayer still works through injecting the memory at configure time using the old API.
155 *
156 * Checks performed in order:
157 * - Both runs compute the same output
158 */
159TEST_CASE(MultipleExecutionWithConfigure, framework::DatasetMode::ALL)
160{
161 auto fc = std::make_unique<NEFullyConnectedLayer>();
162 const auto src_info = TensorInfo(TensorShape(8U), 1, DataType::F32, DataLayout::NHWC);
163 const auto weight_info = TensorInfo(TensorShape(8U, 4U), 1, DataType::F32, DataLayout::NHWC);
164 const auto bias_info = TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC);
165 auto dst_info = TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC);
166 const auto fc_info = FullyConnectedLayerInfo{};
167 auto run_conv = [&]()
168 {
169 auto src = create_tensor<Tensor>(src_info);
170 auto weight = create_tensor<Tensor>(weight_info);
171 auto bias = create_tensor<Tensor>(bias_info);
172 auto dst = create_tensor<Tensor>(dst_info);
173 fc->configure(&src, &weight, &bias, &dst, fc_info);
174 src.allocator()->allocate();
175 weight.allocator()->allocate();
176 bias.allocator()->allocate();
177 dst.allocator()->allocate();
178 library->fill_tensor_value(Accessor(src), 1.f);
179 library->fill_tensor_value(Accessor(weight), 2.f);
180 library->fill_tensor_value(Accessor(bias), 3.f);
181 fc->run();
182 return dst;
183 };
184 auto result_0 = run_conv();
185 auto result_1 = run_conv();
186 for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i)
187 {
188 ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS);
189 }
190}
191
192/** Unit test for @ref cpu::CpuFullyConnected with quantized multipler > 1
193 *
194 * Tests output correctness.
195 */
196TEST_CASE(Quant8_Signed_Mult_gt_1, framework::DatasetMode::ALL)
197{
198 auto fc = std::make_unique<cpu::CpuFullyConnected>();
199 const auto src_info = TensorInfo(TensorShape(1U, 3U), 1, DataType::QASYMM8_SIGNED, QuantizationInfo(0.5f, -1));
200 const auto weight_info = TensorInfo(TensorShape(1U), 1, DataType::QASYMM8_SIGNED, QuantizationInfo(0.5, -8));
201 const auto bias_info = TensorInfo(TensorShape(1U), 1, DataType::S32);
202 auto dst_info = TensorInfo(TensorShape(1U, 3U), 1, DataType::QASYMM8_SIGNED, QuantizationInfo(0.1f, 0));
203 const auto fc_info = FullyConnectedLayerInfo{};
204 fc->configure(&src_info, &weight_info, &bias_info, &dst_info, fc_info);
205
206 // telhs are newly created every call of this lambda function
207 auto src = create_tensor<Tensor>(src_info);
208 auto weight = create_tensor<Tensor>(weight_info);
209 auto bias = create_tensor<Tensor>(bias_info);
210 auto dst = create_tensor<Tensor>(dst_info);
211 src.allocator()->allocate();
212 weight.allocator()->allocate();
213 bias.allocator()->allocate();
214 dst.allocator()->allocate();
215
216 ITensorPack run_pack{ { TensorType::ACL_SRC_0, &src }, { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias }, { TensorType::ACL_DST, &dst } };
217 ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &weight }, { TensorType::ACL_SRC_2, &bias } };
218
219 auto mg = MemoryGroup{};
220 auto ws = manage_workspace<Tensor>(fc->workspace(), mg, run_pack, prep_pack);
221
222 // Initialize input values
223 const std::vector<int8_t> src_values = { 3, 63, 31 };
224 const std::vector<int8_t> weight_values = { -4 };
225 const std::vector<int32_t> bias_values = { 16 };
226 const std::vector<int32_t> expected = { 80, 127, 127 };
227 library->fill_static_values(Accessor(src), src_values);
228 library->fill_static_values(Accessor(weight), weight_values);
229 library->fill_static_values(Accessor(bias), bias_values);
230
231 // Run FC layer
232 fc->prepare(prep_pack);
233 fc->run(run_pack);
234
235 auto dst_ptr = reinterpret_cast<int8_t *>(dst.buffer());
236 for(size_t i = 0; i < dst.info()->tensor_shape().total_size(); ++i)
237 {
238 ARM_COMPUTE_EXPECT(dst_ptr[i] == expected[i], framework::LogLevel::ERRORS);
239 }
240}
241
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000242// *INDENT-OFF*
243// clang-format off
244DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
245 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F32), // Mismatching data types
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000246 TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32),
247 TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32),
248 TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F32), // Invalid weights dimensions
249 TensorInfo(TensorShape(9U, 5U, 7U, 3U), 1, DataType::F32), // Wrongly reshaped weights
250 TensorInfo(TensorShape(8U, 4U, 6U, 4U), 1, DataType::F32),
251 }),
252 framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(315U, 271U), 1, DataType::F16),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000253 TensorInfo(TensorShape(192U, 192U), 1, DataType::F32),
254 TensorInfo(TensorShape(192U, 192U), 1, DataType::F32),
255 TensorInfo(TensorShape(217U, 315U), 1, DataType::F32),
256 TensorInfo(TensorShape(217U, 315U), 1, DataType::F32),
257 TensorInfo(TensorShape(192U, 192U), 1, DataType::F32),
258 })),
259 framework::dataset::make("BiasInfo",{ TensorInfo(TensorShape(271U), 1, DataType::F32),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000260 TensorInfo(TensorShape(192U), 1, DataType::F32),
261 TensorInfo(TensorShape(192U), 1, DataType::F32),
262 TensorInfo(TensorShape(271U), 1, DataType::F32),
263 TensorInfo(TensorShape(271U), 1, DataType::F32),
264 TensorInfo(TensorShape(192U), 1, DataType::F32),
265 })),
266 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(271U, 3U), 1, DataType::F32),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000267 TensorInfo(TensorShape(192U, 4U), 1, DataType::F32),
268 TensorInfo(TensorShape(192U, 4U), 1, DataType::F32),
269 TensorInfo(TensorShape(271U, 3U), 1, DataType::F32),
270 TensorInfo(TensorShape(271U, 3U), 1, DataType::F32),
271 TensorInfo(TensorShape(192U, 4U), 1, DataType::F32),
272 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +0100273 framework::dataset::make("TransposeWeights",{ true, true, false, true, true, true })),
274 framework::dataset::make("ReshapedWeights",{ false, false, false, false, false , false})),
275 framework::dataset::make("Expected", { false, true, true, false, false, true })),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000276 input_info, weights_info, bias_info, output_info, transpose_weights, reshaped_weights, expected)
277{
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +0100278 // Create Fully Connected layer info
279 FullyConnectedLayerInfo fc_info;
280 fc_info.transpose_weights = transpose_weights;
281 fc_info.are_weights_reshaped = reshaped_weights;
282
283 Status status = NEFullyConnectedLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &bias_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), fc_info);
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000284 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
285}
286// clang-format on
287// *INDENT-ON*
288
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100289template <typename T>
Giorgio Arenaa855af12018-07-16 17:20:38 +0100290using NEFullyConnectedLayerFixture = FullyConnectedLayerValidationFixture<Tensor, Accessor, NEFullyConnectedLayer, T>;
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000291template <typename T>
292using NEFullyConnectedLayerMixedDataLayoutFixture = FullyConnectedLayerValidationFixture<Tensor, Accessor, NEFullyConnectedLayer, T, true>;
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100293
294TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000295#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100296TEST_SUITE(FP16)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000297FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
Georgios Pinitas583137c2017-08-31 18:12:42 +0100298 FullyConnectedParameters),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000299 framework::dataset::make("DataType", DataType::F16)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000300 EmptyActivationFunctionDataset))
301{
302 // Validate output
303 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
304}
305FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(
306 combine(datasets::FullyConnectedLayerWithActivationDataset(),
307 FullyConnectedParameters),
308 framework::dataset::make("DataType", DataType::F16)),
309 ActivationFunctionsDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100310{
311 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100312 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100313}
Giorgio Arena1856ff72020-02-07 13:46:45 +0000314FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(),
Georgios Pinitas583137c2017-08-31 18:12:42 +0100315 FullyConnectedParameters),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000316 framework::dataset::make("DataType", DataType::F16)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000317 EmptyActivationFunctionDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100318{
319 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100320 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100321}
322TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000323#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100324
325TEST_SUITE(FP32)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000326FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), FullyConnectedParameters),
327 framework::dataset::make("DataType", DataType::F32)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000328 EmptyActivationFunctionDataset))
329{
330 // Validate output
331 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
332}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000333FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerMixedDataLayoutFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +0100334 framework::dataset::make("Input", TensorShape(9U, 5U, 7U)),
335 framework::dataset::make("Weights", TensorShape(315U, 271U))),
336 framework::dataset::make("Biases", TensorShape(271U))),
337 framework::dataset::make("Output", TensorShape(271U))),
338 FullyConnectedParameters),
339 framework::dataset::make("DataType", DataType::F32)),
340 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000341{
342 // Validate output
343 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
344}
SiCongLi2e5fd632020-03-02 15:39:15 +0000345FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(
346 combine(datasets::FullyConnectedLayerWithActivationDataset(),
347 FullyConnectedParameters),
348 framework::dataset::make("DataType", DataType::F32)),
349 ActivationFunctionsDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100350{
351 // Validate output
Michele Di Giorgio419f33a2018-08-27 14:25:24 +0100352 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100353}
Giorgio Arena1856ff72020-02-07 13:46:45 +0000354FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), FullyConnectedParameters),
355 framework::dataset::make("DataType", DataType::F32)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000356 EmptyActivationFunctionDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100357{
358 // Validate output
Michele Di Giorgio419f33a2018-08-27 14:25:24 +0100359 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100360}
361TEST_SUITE_END()
362TEST_SUITE_END()
363
Giorgio Arenaa855af12018-07-16 17:20:38 +0100364template <typename T>
365using NEFullyConnectedLayerQuantizedFixture = FullyConnectedLayerValidationQuantizedFixture<Tensor, Accessor, NEFullyConnectedLayer, T>;
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000366template <typename T>
367using NEFullyConnectedLayerQuantizedMixedDataLayoutFixture = FullyConnectedLayerValidationQuantizedFixture<Tensor, Accessor, NEFullyConnectedLayer, T, true>;
Giorgio Arenaa855af12018-07-16 17:20:38 +0100368
369TEST_SUITE(Quantized)
370TEST_SUITE(QASYMM8)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000371FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
Giorgio Arenaa855af12018-07-16 17:20:38 +0100372 combine(datasets::SmallFullyConnectedLayerDataset(),
373 FullyConnectedParameters),
374 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000375 QuantizationData),
SiCongLi2e5fd632020-03-02 15:39:15 +0000376 EmptyActivationFunctionDataset))
Giorgio Arenaa855af12018-07-16 17:20:38 +0100377{
378 // Validate output
379 validate(Accessor(_target), _reference, tolerance_qasymm8);
380}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000381FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerQuantizedMixedDataLayoutFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
382 combine(combine(combine(combine(combine(combine(combine(
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +0100383 framework::dataset::make("Input", TensorShape(9U, 5U, 7U)),
384 framework::dataset::make("Weights", TensorShape(315U, 271U))),
385 framework::dataset::make("Biases", TensorShape(271U))),
386 framework::dataset::make("Output", TensorShape(271U))),
387 FullyConnectedParameters),
388 framework::dataset::make("DataType", DataType::QASYMM8)),
389 QuantizationData),
390 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000391{
392 // Validate output
393 validate(Accessor(_target), _reference, tolerance_qasymm8);
394}
SiCongLi2e5fd632020-03-02 15:39:15 +0000395FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
396 combine(datasets::FullyConnectedLayerWithActivationDataset(),
397 FullyConnectedParameters),
398 framework::dataset::make("DataType", DataType::QASYMM8)),
399 QuantizationData),
400 ActivationFunctionsQuantizedDataset))
401{
402 // Validate output
403 validate(Accessor(_target), _reference, tolerance_qasymm8);
404}
405
Giorgio Arena1856ff72020-02-07 13:46:45 +0000406FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(
Giorgio Arenaa855af12018-07-16 17:20:38 +0100407 combine(datasets::LargeFullyConnectedLayerDataset(),
408 FullyConnectedParameters),
409 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000410 QuantizationData),
SiCongLi2e5fd632020-03-02 15:39:15 +0000411 EmptyActivationFunctionDataset))
Giorgio Arenaa855af12018-07-16 17:20:38 +0100412{
413 // Validate output
414 validate(Accessor(_target), _reference, tolerance_qasymm8);
415}
416TEST_SUITE_END()
Michele Di Giorgio9c700372020-01-08 11:33:44 +0000417TEST_SUITE(QASYMM8_SIGNED)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000418FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
Michele Di Giorgio9c700372020-01-08 11:33:44 +0000419 combine(datasets::SmallFullyConnectedLayerDataset(),
420 FullyConnectedParameters),
421 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000422 QuantizationData),
SiCongLi2e5fd632020-03-02 15:39:15 +0000423 EmptyActivationFunctionDataset))
424{
425 // Validate output
426 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
427}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000428FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerQuantizedMixedDataLayoutFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
429 combine(combine(combine(combine(combine(combine(combine(
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +0100430 framework::dataset::make("Input", TensorShape(9U, 5U, 7U)),
431 framework::dataset::make("Weights", TensorShape(315U, 271U))),
432 framework::dataset::make("Biases", TensorShape(271U))),
433 framework::dataset::make("Output", TensorShape(271U))),
434 FullyConnectedParameters),
435 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
436 QuantizationData),
437 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000438{
439 // Validate output
440 validate(Accessor(_target), _reference, tolerance_qasymm8);
441}
SiCongLi2e5fd632020-03-02 15:39:15 +0000442FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
443 combine(datasets::FullyConnectedLayerWithActivationDataset(),
444 FullyConnectedParameters),
445 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
446 QuantizationData),
447 ActivationFunctionsQuantizedDataset))
Michele Di Giorgio9c700372020-01-08 11:33:44 +0000448{
449 // Validate output
450 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
451}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000452TEST_SUITE_END() // QASYMM8_SIGNED
453TEST_SUITE_END() // Quantized
454TEST_SUITE_END() // FullyConnectedLayer
455TEST_SUITE_END() // NEON
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100456} // namespace validation
457} // namespace test
458} // namespace arm_compute