blob: 04889a9dba7ce40eb4e0bb538053bc06f0be2b73 [file] [log] [blame]
Moritz Pflanzer69d33412017-08-09 11:45:15 +01001/*
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +00002 * Copyright (c) 2017-2021, 2023 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>;
Giorgio Arena63e0beb2021-09-24 14:04:27 +0100293template <typename T>
294using NEFullyConnectedLayerDynamicWeightsFixture = FullyConnectedWithDynamicWeightsFixture<Tensor, Accessor, NEFullyConnectedLayer, T>;
295template <typename T>
296using NEFullyConnectedLayerDynamicBiasFixture = FullyConnectedWithDynamicBiasFixture<Tensor, Accessor, NEFullyConnectedLayer, T>;
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100297
298TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000299#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100300TEST_SUITE(FP16)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000301FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
Georgios Pinitas583137c2017-08-31 18:12:42 +0100302 FullyConnectedParameters),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000303 framework::dataset::make("DataType", DataType::F16)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000304 EmptyActivationFunctionDataset))
305{
306 // Validate output
307 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
308}
309FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(
310 combine(datasets::FullyConnectedLayerWithActivationDataset(),
311 FullyConnectedParameters),
312 framework::dataset::make("DataType", DataType::F16)),
313 ActivationFunctionsDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100314{
315 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100316 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100317}
Giorgio Arena1856ff72020-02-07 13:46:45 +0000318FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(),
Georgios Pinitas583137c2017-08-31 18:12:42 +0100319 FullyConnectedParameters),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000320 framework::dataset::make("DataType", DataType::F16)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000321 EmptyActivationFunctionDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100322{
323 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100324 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100325}
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000326FIXTURE_DATA_TEST_CASE(RunDynamicWeights, NEFullyConnectedLayerDynamicWeightsFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
327 framework::dataset::make("DataType", DataType::F16)),
328 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))),
329 framework::dataset::make("WeightsReshaped", { false, true })))
330{
331}
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100332TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000333#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100334
335TEST_SUITE(FP32)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000336FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), FullyConnectedParameters),
337 framework::dataset::make("DataType", DataType::F32)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000338 EmptyActivationFunctionDataset))
339{
340 // Validate output
341 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
342}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000343FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerMixedDataLayoutFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +0100344 framework::dataset::make("Input", TensorShape(9U, 5U, 7U)),
345 framework::dataset::make("Weights", TensorShape(315U, 271U))),
346 framework::dataset::make("Biases", TensorShape(271U))),
347 framework::dataset::make("Output", TensorShape(271U))),
348 FullyConnectedParameters),
349 framework::dataset::make("DataType", DataType::F32)),
350 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000351{
352 // Validate output
353 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
354}
SiCongLi2e5fd632020-03-02 15:39:15 +0000355FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(
356 combine(datasets::FullyConnectedLayerWithActivationDataset(),
357 FullyConnectedParameters),
358 framework::dataset::make("DataType", DataType::F32)),
359 ActivationFunctionsDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100360{
361 // Validate output
Michele Di Giorgio419f33a2018-08-27 14:25:24 +0100362 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100363}
Giorgio Arena1856ff72020-02-07 13:46:45 +0000364FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), FullyConnectedParameters),
365 framework::dataset::make("DataType", DataType::F32)),
SiCongLi2e5fd632020-03-02 15:39:15 +0000366 EmptyActivationFunctionDataset))
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100367{
368 // Validate output
Michele Di Giorgio419f33a2018-08-27 14:25:24 +0100369 validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100370}
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000371FIXTURE_DATA_TEST_CASE(RunDynamicWeights, NEFullyConnectedLayerDynamicWeightsFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
Giorgio Arena63e0beb2021-09-24 14:04:27 +0100372 framework::dataset::make("DataType", DataType::F32)),
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000373 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))),
374 framework::dataset::make("WeightsReshaped", { false, true })))
Giorgio Arena63e0beb2021-09-24 14:04:27 +0100375{
376}
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100377TEST_SUITE_END()
378TEST_SUITE_END()
379
Giorgio Arenaa855af12018-07-16 17:20:38 +0100380template <typename T>
381using NEFullyConnectedLayerQuantizedFixture = FullyConnectedLayerValidationQuantizedFixture<Tensor, Accessor, NEFullyConnectedLayer, T>;
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000382template <typename T>
383using NEFullyConnectedLayerQuantizedMixedDataLayoutFixture = FullyConnectedLayerValidationQuantizedFixture<Tensor, Accessor, NEFullyConnectedLayer, T, true>;
Giorgio Arenaa855af12018-07-16 17:20:38 +0100384
385TEST_SUITE(Quantized)
386TEST_SUITE(QASYMM8)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000387FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
Giorgio Arenaa855af12018-07-16 17:20:38 +0100388 combine(datasets::SmallFullyConnectedLayerDataset(),
389 FullyConnectedParameters),
390 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000391 QuantizationData),
SiCongLi2e5fd632020-03-02 15:39:15 +0000392 EmptyActivationFunctionDataset))
Giorgio Arenaa855af12018-07-16 17:20:38 +0100393{
394 // Validate output
395 validate(Accessor(_target), _reference, tolerance_qasymm8);
396}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000397FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerQuantizedMixedDataLayoutFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
398 combine(combine(combine(combine(combine(combine(combine(
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +0100399 framework::dataset::make("Input", TensorShape(9U, 5U, 7U)),
400 framework::dataset::make("Weights", TensorShape(315U, 271U))),
401 framework::dataset::make("Biases", TensorShape(271U))),
402 framework::dataset::make("Output", TensorShape(271U))),
403 FullyConnectedParameters),
404 framework::dataset::make("DataType", DataType::QASYMM8)),
405 QuantizationData),
406 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000407{
408 // Validate output
409 validate(Accessor(_target), _reference, tolerance_qasymm8);
410}
SiCongLi2e5fd632020-03-02 15:39:15 +0000411FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
412 combine(datasets::FullyConnectedLayerWithActivationDataset(),
413 FullyConnectedParameters),
414 framework::dataset::make("DataType", DataType::QASYMM8)),
415 QuantizationData),
416 ActivationFunctionsQuantizedDataset))
417{
418 // Validate output
419 validate(Accessor(_target), _reference, tolerance_qasymm8);
420}
421
Giorgio Arena1856ff72020-02-07 13:46:45 +0000422FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(
Giorgio Arenaa855af12018-07-16 17:20:38 +0100423 combine(datasets::LargeFullyConnectedLayerDataset(),
424 FullyConnectedParameters),
425 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000426 QuantizationData),
SiCongLi2e5fd632020-03-02 15:39:15 +0000427 EmptyActivationFunctionDataset))
Giorgio Arenaa855af12018-07-16 17:20:38 +0100428{
429 // Validate output
430 validate(Accessor(_target), _reference, tolerance_qasymm8);
431}
Giorgio Arena63e0beb2021-09-24 14:04:27 +0100432
433FIXTURE_DATA_TEST_CASE(RunDynamicBias, NEFullyConnectedLayerDynamicBiasFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallFullyConnectedLayerDataset(),
434 framework::dataset::make("DataType", DataType::QASYMM8)),
435 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
436{
437}
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000438FIXTURE_DATA_TEST_CASE(RunDynamicWeights, NEFullyConnectedLayerDynamicWeightsFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
439 framework::dataset::make("DataType", DataType::QASYMM8)),
440 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))),
Viet-Hoa Do9b0a6b42023-04-03 16:27:25 +0100441 framework::dataset::make("WeightsReshaped", { false })))
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000442{
443}
Giorgio Arenaa855af12018-07-16 17:20:38 +0100444TEST_SUITE_END()
Michele Di Giorgio9c700372020-01-08 11:33:44 +0000445TEST_SUITE(QASYMM8_SIGNED)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000446FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
Michele Di Giorgio9c700372020-01-08 11:33:44 +0000447 combine(datasets::SmallFullyConnectedLayerDataset(),
448 FullyConnectedParameters),
449 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000450 QuantizationData),
SiCongLi2e5fd632020-03-02 15:39:15 +0000451 EmptyActivationFunctionDataset))
452{
453 // Validate output
454 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
455}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000456FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerQuantizedMixedDataLayoutFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
457 combine(combine(combine(combine(combine(combine(combine(
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +0100458 framework::dataset::make("Input", TensorShape(9U, 5U, 7U)),
459 framework::dataset::make("Weights", TensorShape(315U, 271U))),
460 framework::dataset::make("Biases", TensorShape(271U))),
461 framework::dataset::make("Output", TensorShape(271U))),
462 FullyConnectedParameters),
463 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
464 QuantizationData),
465 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))))
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000466{
467 // Validate output
468 validate(Accessor(_target), _reference, tolerance_qasymm8);
469}
SiCongLi2e5fd632020-03-02 15:39:15 +0000470FIXTURE_DATA_TEST_CASE(RunWithActivation, NEFullyConnectedLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
471 combine(datasets::FullyConnectedLayerWithActivationDataset(),
472 FullyConnectedParameters),
473 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
474 QuantizationData),
475 ActivationFunctionsQuantizedDataset))
Michele Di Giorgio9c700372020-01-08 11:33:44 +0000476{
477 // Validate output
478 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
479}
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000480FIXTURE_DATA_TEST_CASE(RunDynamicWeights, NEFullyConnectedLayerDynamicWeightsFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
481 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
482 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))),
Viet-Hoa Do9b0a6b42023-04-03 16:27:25 +0100483 framework::dataset::make("WeightsReshaped", { false })))
Viet-Hoa Doa3e57c22023-03-13 16:20:04 +0000484{
485}
Manuel Bottinica62c6f2021-03-23 11:50:34 +0000486TEST_SUITE_END() // QASYMM8_SIGNED
487TEST_SUITE_END() // Quantized
488TEST_SUITE_END() // FullyConnectedLayer
489TEST_SUITE_END() // NEON
Moritz Pflanzer69d33412017-08-09 11:45:15 +0100490} // namespace validation
491} // namespace test
492} // namespace arm_compute