32 #include "tests/datasets/FullyConnectedLayerDataset.h"
37 #include "tests/validation/fixtures/FullyConnectedLayerFixture.h"
49 constexpr RelativeTolerance<float> rel_tolerance_f32(0.01f);
51 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
52 const AbsoluteTolerance<float> abs_tolerance_f16(0.3f);
53 const RelativeTolerance<half_float::half> rel_tolerance_f16(
half_float::half(0.2f));
58 constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1);
62 const auto CNNDataTypes =
make(
"DataType",
64 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
70 const auto FullyConnectedParameters =
combine(
make(
"TransposeWeights", {
false,
true }),
make(
"ReshapeWeights", {
false,
true }));
74 QuantizationInfo(1.f / 256.f, 10),
75 QuantizationInfo(1.1f, 10),
78 const auto IgnoredQuantizationData =
make(
"IgnoredQuantizationInfo",
83 const auto NoActivationFunctionDataset =
make(
"ActivationInfo",
85 ActivationLayerInfo(),
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 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH),
98 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
99 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f),
100 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f),
116 auto fc = std::make_unique<cpu::CpuFullyConnected>();
121 const auto fc_info = FullyConnectedLayerInfo{};
122 fc->configure(&
src_info, &weight_info, &bias_info, &dst_info, fc_info);
126 auto weight = create_tensor<Tensor>(weight_info);
127 auto bias = create_tensor<Tensor>(bias_info);
128 src.allocator()->allocate();
129 weight.allocator()->allocate();
130 bias.allocator()->allocate();
135 auto mg = MemoryGroup{};
136 auto ws = manage_workspace<Tensor>(fc->workspace(), mg, run_pack, prep_pack);
138 auto run_conv = [&]() -> Tensor
140 auto dst = create_tensor<Tensor>(dst_info);
141 dst.allocator()->allocate();
144 library->fill_tensor_value(Accessor(
src), 1.f);
145 library->fill_tensor_value(Accessor(weight), 2.f);
148 fc->prepare(prep_pack);
152 auto result_0 = run_conv();
153 auto result_1 = run_conv();
154 for(
size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i)
169 auto fc = std::make_unique<NEFullyConnectedLayer>();
174 const auto fc_info = FullyConnectedLayerInfo{};
175 auto run_conv = [&]()
178 auto weight = create_tensor<Tensor>(weight_info);
179 auto bias = create_tensor<Tensor>(bias_info);
180 auto dst = create_tensor<Tensor>(dst_info);
181 fc->configure(&
src, &weight, &
bias, &
dst, fc_info);
182 src.allocator()->allocate();
183 weight.allocator()->allocate();
184 bias.allocator()->allocate();
185 dst.allocator()->allocate();
186 library->fill_tensor_value(Accessor(
src), 1.f);
187 library->fill_tensor_value(Accessor(weight), 2.f);
192 auto result_0 = run_conv();
193 auto result_1 = run_conv();
194 for(
size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i)
206 auto fc = std::make_unique<cpu::CpuFullyConnected>();
212 fc->configure(&
src_info, &weight_info, &bias_info, &dst_info, fc_info);
216 auto weight = create_tensor<Tensor>(weight_info);
217 auto bias = create_tensor<Tensor>(bias_info);
218 auto dst = create_tensor<Tensor>(dst_info);
219 src.allocator()->allocate();
220 weight.allocator()->allocate();
221 bias.allocator()->allocate();
222 dst.allocator()->allocate();
228 auto ws = manage_workspace<Tensor>(fc->workspace(), mg, run_pack, prep_pack);
231 const std::vector<int8_t> src_values = { 3, 63, 31 };
232 const std::vector<int8_t> weight_values = { -4 };
233 const std::vector<int32_t> bias_values = { 16 };
234 const std::vector<int32_t>
expected = { 80, 127, 127 };
240 fc->prepare(prep_pack);
243 auto dst_ptr =
reinterpret_cast<int8_t *
>(
dst.buffer());
244 for(
size_t i = 0; i <
dst.info()->tensor_shape().total_size(); ++i)
281 make(
"TransposeWeights",{
true,
true,
false,
true,
true,
true })),
282 make(
"ReshapedWeights",{
false,
false,
false,
false, false ,
false})),
283 make(
"Expected", {
false,
true,
true,
false,
false,
true })),
287 FullyConnectedLayerInfo fc_info;
288 fc_info.transpose_weights = transpose_weights;
289 fc_info.are_weights_reshaped = reshaped_weights;
297 template <
typename T>
299 template <
typename T>
301 template <
typename T>
303 template <
typename T>
307 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
310 FullyConnectedParameters,
312 NoActivationFunctionDataset))
318 combine(datasets::FullyConnectedLayerWithActivationDataset(),
319 FullyConnectedParameters,
327 FullyConnectedParameters,
329 NoActivationFunctionDataset))
336 make(
"ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)),
337 make(
"WeightsReshaped", {
false,
true })))
346 NoActivationFunctionDataset))
356 FullyConnectedParameters,
364 FullyConnectedParameters,
373 NoActivationFunctionDataset))
381 make(
"WeightsReshaped", {
false,
true })))
387 template <typename T>
389 template <typename T>
400 FullyConnectedParameters,
409 combine(datasets::FullyConnectedLayerWithActivationDataset(),
410 FullyConnectedParameters,
421 make(
"WeightsReshaped", {
false })))
432 combine(datasets::SmallFullyConnectedLayerDataset(),
433 FullyConnectedParameters,
435 IgnoredQuantizationData,
436 NoActivationFunctionDataset))
442 datasets::LargeFullyConnectedLayerDataset(),
443 FullyConnectedParameters,
446 NoActivationFunctionDataset))
453 NoActivationFunctionDataset))
462 FullyConnectedParameters,
464 IgnoredQuantizationData,
465 NoActivationFunctionDataset))
472 NoActivationFunctionDataset,
473 make(
"WeightsReshaped", {
false })))
484 FullyConnectedParameters,
493 combine(datasets::FullyConnectedLayerWithActivationDataset(),
494 FullyConnectedParameters,
505 make(
"WeightsReshaped", {
false })))
511 datasets::SmallFullyConnectedLayerDataset(),
512 FullyConnectedParameters,
514 IgnoredQuantizationData,
515 NoActivationFunctionDataset))
526 FullyConnectedParameters,
529 NoActivationFunctionDataset))
536 NoActivationFunctionDataset,
537 make(
"WeightsReshaped", {
false })))