Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | a3e57c2 | 2023-03-13 16:20:04 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, 2023 Arm Limited. |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 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/NEFullyConnectedLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 28 | #include "src/core/helpers/MemoryHelpers.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 29 | #include "src/cpu/operators/CpuFullyConnected.h" |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 30 | #include "tests/NEON/Accessor.h" |
| 31 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 32 | #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 Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | /** Tolerance for float operations */ |
Michele Di Giorgio | 419f33a | 2018-08-27 14:25:24 +0100 | [diff] [blame] | 48 | constexpr RelativeTolerance<float> rel_tolerance_f32(0.01f); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 49 | constexpr AbsoluteTolerance<float> abs_tolerance_f32(0.001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 50 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Gian Marco Iodice | 35aea37 | 2018-08-24 14:30:36 +0100 | [diff] [blame] | 51 | const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 52 | const 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 */ |
| 53 | constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */ |
| 54 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC*/ |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 55 | |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 56 | /** Tolerance for quantized asymmetric operations */ |
| 57 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 58 | constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1); |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 59 | |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 60 | /** CNN data types */ |
| 61 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 62 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 63 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 64 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 65 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 66 | DataType::F32, |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 67 | }); |
| 68 | |
| 69 | const auto FullyConnectedParameters = combine(framework::dataset::make("TransposeWeights", { false, true }), framework::dataset::make("ReshapeWeights", { false, true })); |
Michele Di Giorgio | f29d1b7 | 2019-10-29 10:58:13 +0000 | [diff] [blame] | 70 | |
| 71 | const auto QuantizationData = framework::dataset::make("QuantizationInfo", |
| 72 | { |
| 73 | QuantizationInfo(1.f / 256.f, 10), |
| 74 | QuantizationInfo(1.1f, 10), |
| 75 | }); |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 76 | const auto EmptyActivationFunctionDataset = framework::dataset::make("ActivationInfo", |
| 77 | { |
| 78 | ActivationLayerInfo(), |
| 79 | }); |
| 80 | const 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 Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 87 | |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 88 | const 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 Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 94 | } // namespace |
| 95 | |
| 96 | TEST_SUITE(NEON) |
| 97 | TEST_SUITE(FullyConnectedLayer) |
| 98 | |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 99 | /** 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 | */ |
| 106 | TEST_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 | */ |
| 159 | TEST_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 | */ |
| 196 | TEST_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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 242 | // *INDENT-OFF* |
| 243 | // clang-format off |
| 244 | DATA_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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 246 | 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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 253 | 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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 260 | 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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 267 | 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 Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 273 | 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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 276 | input_info, weights_info, bias_info, output_info, transpose_weights, reshaped_weights, expected) |
| 277 | { |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 278 | // 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 Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 284 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 285 | } |
| 286 | // clang-format on |
| 287 | // *INDENT-ON* |
| 288 | |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 289 | template <typename T> |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 290 | using NEFullyConnectedLayerFixture = FullyConnectedLayerValidationFixture<Tensor, Accessor, NEFullyConnectedLayer, T>; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 291 | template <typename T> |
| 292 | using NEFullyConnectedLayerMixedDataLayoutFixture = FullyConnectedLayerValidationFixture<Tensor, Accessor, NEFullyConnectedLayer, T, true>; |
Giorgio Arena | 63e0beb | 2021-09-24 14:04:27 +0100 | [diff] [blame] | 293 | template <typename T> |
| 294 | using NEFullyConnectedLayerDynamicWeightsFixture = FullyConnectedWithDynamicWeightsFixture<Tensor, Accessor, NEFullyConnectedLayer, T>; |
| 295 | template <typename T> |
| 296 | using NEFullyConnectedLayerDynamicBiasFixture = FullyConnectedWithDynamicBiasFixture<Tensor, Accessor, NEFullyConnectedLayer, T>; |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 297 | |
| 298 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 299 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 300 | TEST_SUITE(FP16) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 301 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 302 | FullyConnectedParameters), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 303 | framework::dataset::make("DataType", DataType::F16)), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 304 | EmptyActivationFunctionDataset)) |
| 305 | { |
| 306 | // Validate output |
| 307 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16); |
| 308 | } |
| 309 | FIXTURE_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 Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 314 | { |
| 315 | // Validate output |
Gian Marco Iodice | 35aea37 | 2018-08-24 14:30:36 +0100 | [diff] [blame] | 316 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16); |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 317 | } |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 318 | FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 319 | FullyConnectedParameters), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 320 | framework::dataset::make("DataType", DataType::F16)), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 321 | EmptyActivationFunctionDataset)) |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 322 | { |
| 323 | // Validate output |
Gian Marco Iodice | 35aea37 | 2018-08-24 14:30:36 +0100 | [diff] [blame] | 324 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16); |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 325 | } |
Viet-Hoa Do | a3e57c2 | 2023-03-13 16:20:04 +0000 | [diff] [blame] | 326 | FIXTURE_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 Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 332 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 333 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 334 | |
| 335 | TEST_SUITE(FP32) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 336 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), FullyConnectedParameters), |
| 337 | framework::dataset::make("DataType", DataType::F32)), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 338 | EmptyActivationFunctionDataset)) |
| 339 | { |
| 340 | // Validate output |
| 341 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32); |
| 342 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 343 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerMixedDataLayoutFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine( |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 344 | 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 Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 351 | { |
| 352 | // Validate output |
| 353 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32); |
| 354 | } |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 355 | FIXTURE_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 Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 360 | { |
| 361 | // Validate output |
Michele Di Giorgio | 419f33a | 2018-08-27 14:25:24 +0100 | [diff] [blame] | 362 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32); |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 363 | } |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 364 | FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), FullyConnectedParameters), |
| 365 | framework::dataset::make("DataType", DataType::F32)), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 366 | EmptyActivationFunctionDataset)) |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 367 | { |
| 368 | // Validate output |
Michele Di Giorgio | 419f33a | 2018-08-27 14:25:24 +0100 | [diff] [blame] | 369 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32); |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 370 | } |
Viet-Hoa Do | a3e57c2 | 2023-03-13 16:20:04 +0000 | [diff] [blame] | 371 | FIXTURE_DATA_TEST_CASE(RunDynamicWeights, NEFullyConnectedLayerDynamicWeightsFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), |
Giorgio Arena | 63e0beb | 2021-09-24 14:04:27 +0100 | [diff] [blame] | 372 | framework::dataset::make("DataType", DataType::F32)), |
Viet-Hoa Do | a3e57c2 | 2023-03-13 16:20:04 +0000 | [diff] [blame] | 373 | framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))), |
| 374 | framework::dataset::make("WeightsReshaped", { false, true }))) |
Giorgio Arena | 63e0beb | 2021-09-24 14:04:27 +0100 | [diff] [blame] | 375 | { |
| 376 | } |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 377 | TEST_SUITE_END() |
| 378 | TEST_SUITE_END() |
| 379 | |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 380 | template <typename T> |
| 381 | using NEFullyConnectedLayerQuantizedFixture = FullyConnectedLayerValidationQuantizedFixture<Tensor, Accessor, NEFullyConnectedLayer, T>; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 382 | template <typename T> |
| 383 | using NEFullyConnectedLayerQuantizedMixedDataLayoutFixture = FullyConnectedLayerValidationQuantizedFixture<Tensor, Accessor, NEFullyConnectedLayer, T, true>; |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 384 | |
| 385 | TEST_SUITE(Quantized) |
| 386 | TEST_SUITE(QASYMM8) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 387 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine( |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 388 | combine(datasets::SmallFullyConnectedLayerDataset(), |
| 389 | FullyConnectedParameters), |
| 390 | framework::dataset::make("DataType", DataType::QASYMM8)), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 391 | QuantizationData), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 392 | EmptyActivationFunctionDataset)) |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 393 | { |
| 394 | // Validate output |
| 395 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 396 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 397 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerQuantizedMixedDataLayoutFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 398 | combine(combine(combine(combine(combine(combine(combine( |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 399 | 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 Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 407 | { |
| 408 | // Validate output |
| 409 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 410 | } |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 411 | FIXTURE_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 Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 422 | FIXTURE_DATA_TEST_CASE(RunLarge, NEFullyConnectedLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine( |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 423 | combine(datasets::LargeFullyConnectedLayerDataset(), |
| 424 | FullyConnectedParameters), |
| 425 | framework::dataset::make("DataType", DataType::QASYMM8)), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 426 | QuantizationData), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 427 | EmptyActivationFunctionDataset)) |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 428 | { |
| 429 | // Validate output |
| 430 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 431 | } |
Giorgio Arena | 63e0beb | 2021-09-24 14:04:27 +0100 | [diff] [blame] | 432 | |
| 433 | FIXTURE_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 Do | a3e57c2 | 2023-03-13 16:20:04 +0000 | [diff] [blame] | 438 | FIXTURE_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))), |
| 441 | framework::dataset::make("WeightsReshaped", { false, true }))) |
| 442 | { |
| 443 | } |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 444 | TEST_SUITE_END() |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 445 | TEST_SUITE(QASYMM8_SIGNED) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 446 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFullyConnectedLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine( |
Michele Di Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 447 | combine(datasets::SmallFullyConnectedLayerDataset(), |
| 448 | FullyConnectedParameters), |
| 449 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 450 | QuantizationData), |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 451 | EmptyActivationFunctionDataset)) |
| 452 | { |
| 453 | // Validate output |
| 454 | validate(Accessor(_target), _reference, tolerance_qasymm8_signed); |
| 455 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 456 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEFullyConnectedLayerQuantizedMixedDataLayoutFixture<int8_t>, framework::DatasetMode::PRECOMMIT, |
| 457 | combine(combine(combine(combine(combine(combine(combine( |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 458 | 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 Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 466 | { |
| 467 | // Validate output |
| 468 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 469 | } |
SiCongLi | 2e5fd63 | 2020-03-02 15:39:15 +0000 | [diff] [blame] | 470 | FIXTURE_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 Giorgio | 9c70037 | 2020-01-08 11:33:44 +0000 | [diff] [blame] | 476 | { |
| 477 | // Validate output |
| 478 | validate(Accessor(_target), _reference, tolerance_qasymm8_signed); |
| 479 | } |
Viet-Hoa Do | a3e57c2 | 2023-03-13 16:20:04 +0000 | [diff] [blame] | 480 | FIXTURE_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))), |
| 483 | framework::dataset::make("WeightsReshaped", { false, true }))) |
| 484 | { |
| 485 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 486 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 487 | TEST_SUITE_END() // Quantized |
| 488 | TEST_SUITE_END() // FullyConnectedLayer |
| 489 | TEST_SUITE_END() // NEON |
Moritz Pflanzer | 69d3341 | 2017-08-09 11:45:15 +0100 | [diff] [blame] | 490 | } // namespace validation |
| 491 | } // namespace test |
| 492 | } // namespace arm_compute |