Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +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" |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 25 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpAssemblyMatrixMultiplyCore.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h" |
| 27 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/Tensor.h" |
| 29 | #include "arm_compute/runtime/TensorAllocator.h" |
| 30 | #include "tests/NEON/Accessor.h" |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 31 | #include "tests/NEON/Helper.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 32 | #include "tests/PaddingCalculator.h" |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 33 | #include "tests/datasets/GEMMLowpFusedOffsetOutputDataset.h" |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 34 | #include "tests/datasets/LargeGEMMLowpDataset.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 35 | #include "tests/datasets/ShapeDatasets.h" |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 36 | #include "tests/datasets/SmallGEMMLowpDataset.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 37 | #include "tests/framework/Asserts.h" |
| 38 | #include "tests/framework/Macros.h" |
| 39 | #include "tests/framework/datasets/Datasets.h" |
| 40 | #include "tests/validation/Validation.h" |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 41 | #include "tests/validation/fixtures/GEMMLowpAssemblyFixture.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 42 | #include "tests/validation/fixtures/GEMMLowpFixture.h" |
| 43 | |
| 44 | namespace arm_compute |
| 45 | { |
| 46 | namespace test |
| 47 | { |
| 48 | namespace validation |
| 49 | { |
| 50 | namespace |
| 51 | { |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 52 | const auto data_matrix_multiply = framework::dataset::make("M", 12, 20) * framework::dataset::make("N", 12, 20) * framework::dataset::make("K", 16); |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 53 | } // namespace |
| 54 | |
| 55 | TEST_SUITE(NEON) |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 56 | TEST_SUITE(ASSEMBLY_MATRIX_MULTIPLY) |
Michalis Spyrou | f3dfa27 | 2017-11-21 17:52:12 +0000 | [diff] [blame] | 57 | |
| 58 | using NEGEMMAssemblyFixture_S8 = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore, int8_t>; |
| 59 | using NEGEMMAssemblyFixture_U8 = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore, uint8_t>; |
| 60 | |
| 61 | TEST_SUITE(S8) |
| 62 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAssemblyFixture_S8, framework::DatasetMode::PRECOMMIT, data_matrix_multiply) |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 63 | { |
| 64 | // Validate output |
| 65 | validate(Accessor(_target), _reference); |
| 66 | } |
| 67 | TEST_SUITE_END() |
| 68 | |
Michalis Spyrou | f3dfa27 | 2017-11-21 17:52:12 +0000 | [diff] [blame] | 69 | TEST_SUITE(U8) |
| 70 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAssemblyFixture_U8, framework::DatasetMode::PRECOMMIT, data_matrix_multiply) |
| 71 | { |
| 72 | // Validate output |
| 73 | validate(Accessor(_target), _reference); |
| 74 | } |
| 75 | TEST_SUITE_END() |
| 76 | TEST_SUITE_END() |
| 77 | |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 78 | TEST_SUITE(GEMMLowp) |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 79 | TEST_SUITE(MatrixMultiplyCore) |
| 80 | using NEGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>; |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 81 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 82 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()), |
| 83 | shape_a, shape_b, shape_c, a_offset, b_offset) |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 84 | { |
| 85 | // Create tensors |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 86 | Tensor a = create_tensor<Tensor>(shape_a, DataType::QASYMM8); |
| 87 | Tensor b = create_tensor<Tensor>(shape_b, DataType::QASYMM8); |
| 88 | Tensor c = create_tensor<Tensor>(shape_c, DataType::S32); |
| 89 | |
| 90 | a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset)); |
| 91 | b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset)); |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 92 | |
| 93 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 94 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 95 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 96 | |
| 97 | // Create and configure function |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 98 | NEGEMMLowpMatrixMultiplyCore gemmlowp_mm; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 99 | gemmlowp_mm.configure(&a, &b, nullptr, &c); |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 102 | // *INDENT-OFF* |
| 103 | // clang-format off |
| 104 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 105 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Input not a multiple of 4 |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 106 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 107 | TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions |
| 108 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions |
| 109 | TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), |
| 110 | }), |
| 111 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 112 | TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 113 | TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 114 | TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 115 | TensorInfo(TensorShape(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 116 | })), |
| 117 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32), |
| 118 | TensorInfo(TensorShape(33U, 13U), 1, DataType::S32), |
| 119 | TensorInfo(TensorShape(33U, 13U), 1, DataType::S32), |
| 120 | TensorInfo(TensorShape(8U, 11U), 1, DataType::S32), |
| 121 | TensorInfo(TensorShape(64U, 32U), 1, DataType::S32), |
| 122 | })), |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 123 | framework::dataset::make("Expected", { false, false, false, false, true })), |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 124 | a_info, b_info, output_info, expected) |
| 125 | { |
| 126 | // Lock tensors |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 127 | Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false), |
| 128 | &b_info.clone()->set_is_resizable(false), |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 129 | nullptr, |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 130 | &output_info.clone()->set_is_resizable(false)); |
| 131 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 132 | } |
| 133 | // clang-format on |
| 134 | // *INDENT-ON* |
| 135 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 136 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset()) |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 137 | { |
| 138 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 139 | validate(Accessor(_target), _reference); |
| 140 | } |
| 141 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 142 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset()) |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 143 | { |
| 144 | // Validate output |
| 145 | validate(Accessor(_target), _reference); |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 146 | } |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 147 | |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 148 | using NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>; |
| 149 | TEST_SUITE(FusedOffsetOutput) |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 150 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(), |
Vidhya Sudhan Loganathan | 951b8a4 | 2019-11-04 14:42:08 +0000 | [diff] [blame] | 151 | framework::dataset::make("DataType", { DataType::QASYMM8 }))) |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 152 | { |
| 153 | // Validate output |
| 154 | validate(Accessor(_target), _reference); |
| 155 | } |
| 156 | |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 157 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(), |
Vidhya Sudhan Loganathan | 951b8a4 | 2019-11-04 14:42:08 +0000 | [diff] [blame] | 158 | framework::dataset::make("DataType", { DataType::QASYMM8 }))) |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 159 | { |
| 160 | // Validate output |
| 161 | validate(Accessor(_target), _reference); |
| 162 | } |
| 163 | TEST_SUITE_END() // FusedOffsetOutput |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 164 | TEST_SUITE_END() // MatrixMultiplyCore |
| 165 | |
| 166 | TEST_SUITE(OutputStage) |
| 167 | |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 168 | TEST_SUITE(QuantizeDownInt32Scale) |
| 169 | |
| 170 | TEST_SUITE(QASYMM8) |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 171 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 172 | const auto quantize_down_int32_to_uint8_scale_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, 2) * framework::dataset::make("result_shift", 2, |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 173 | 3) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 174 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true }); |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 175 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 176 | const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 177 | 2) |
| 178 | * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 174) * framework::dataset::make("addBias", { false, true }); |
| 179 | |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 180 | using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>; |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 181 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 182 | // *INDENT-OFF* |
| 183 | // clang-format off |
| 184 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 185 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 186 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 187 | }), |
| 188 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 189 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 190 | })), |
| 191 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 192 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 193 | })), |
| 194 | framework::dataset::make("Min",{ 0, |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 195 | 13, |
| 196 | })), |
| 197 | framework::dataset::make("Max",{ 205, |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 198 | 180, |
| 199 | })), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 200 | framework::dataset::make("Expected", { true, false })), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 201 | a_info, b_info, output_info, min, max, expected) |
| 202 | { |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 203 | |
| 204 | GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo(); |
| 205 | output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN; |
| 206 | output_stage.gemmlowp_min_bound = min; |
| 207 | output_stage.gemmlowp_max_bound = max; |
| 208 | output_stage.output_data_type = DataType::QASYMM8; |
| 209 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 210 | // Lock tensors |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 211 | Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 212 | &b_info.clone()->set_is_resizable(false), |
| 213 | &output_info.clone()->set_is_resizable(false), |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 214 | output_stage); |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 215 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 216 | } |
| 217 | // clang-format on |
| 218 | // *INDENT-ON* |
| 219 | |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 220 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases)) |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 221 | { |
| 222 | // Validate output |
| 223 | validate(Accessor(_target), _reference); |
| 224 | } |
| 225 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 226 | TEST_SUITE(BoundedReLu) |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 227 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 228 | { |
| 229 | // Validate output |
| 230 | validate(Accessor(_target), _reference); |
| 231 | } |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 232 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 233 | TEST_SUITE_END() // BoundedReLu |
| 234 | |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 235 | TEST_SUITE_END() // QASYMM8 |
| 236 | |
| 237 | TEST_SUITE(QASYMM8_SIGNED) |
| 238 | |
| 239 | const auto quantize_down_int32_to_int8_scale_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, 2) * framework::dataset::make("result_shift", 2, |
| 240 | 3) |
| 241 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 242 | |
| 243 | const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, |
| 244 | 2) |
| 245 | * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", -100, -98) * framework::dataset::make("max", 71, 74) * framework::dataset::make("addBias", { false, true }); |
| 246 | |
| 247 | using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>; |
| 248 | |
| 249 | // *INDENT-OFF* |
| 250 | // clang-format off |
| 251 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 252 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
| 253 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max |
| 254 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 255 | }), |
| 256 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 257 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 258 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 259 | })), |
| 260 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED), |
| 261 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED), |
| 262 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 263 | })), |
| 264 | framework::dataset::make("Min",{ -10, |
| 265 | -200, |
| 266 | -113, |
| 267 | })), |
| 268 | framework::dataset::make("Max",{ 105, |
| 269 | 300, |
| 270 | -18, |
| 271 | })), |
| 272 | framework::dataset::make("Expected", { true, false, false })), |
| 273 | a_info, b_info, output_info, min, max, expected) |
| 274 | { |
| 275 | GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo(); |
| 276 | output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN; |
| 277 | output_stage.gemmlowp_min_bound = min; |
| 278 | output_stage.gemmlowp_max_bound = max; |
| 279 | output_stage.output_data_type = DataType::QASYMM8_SIGNED; |
| 280 | |
| 281 | // Lock tensors |
| 282 | Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false), |
| 283 | &b_info.clone()->set_is_resizable(false), |
| 284 | &output_info.clone()->set_is_resizable(false), |
| 285 | output_stage); |
| 286 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 287 | } |
| 288 | // clang-format on |
| 289 | // *INDENT-ON* |
| 290 | |
| 291 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases)) |
| 292 | { |
| 293 | // Validate output |
| 294 | validate(Accessor(_target), _reference); |
| 295 | } |
| 296 | |
| 297 | TEST_SUITE(BoundedReLu) |
| 298 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases)) |
| 299 | { |
| 300 | // Validate output |
| 301 | validate(Accessor(_target), _reference); |
| 302 | } |
| 303 | |
| 304 | TEST_SUITE_END() // BoundedReLu |
| 305 | |
| 306 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 307 | |
| 308 | TEST_SUITE_END() // QuantizeDownInt32Scale |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 309 | |
| 310 | TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint) |
| 311 | |
| 312 | const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1, |
| 313 | 2) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 314 | * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true }); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 315 | |
| 316 | const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1, |
| 317 | 2) |
| 318 | * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 174) * framework::dataset::make("addBias", { false, true }); |
| 319 | |
| 320 | using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture = |
| 321 | GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>; |
| 322 | |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 323 | using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture = |
| 324 | GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>; |
| 325 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 326 | // *INDENT-OFF* |
| 327 | // clang-format off |
| 328 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 329 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 330 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 331 | }), |
| 332 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 333 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 334 | })), |
| 335 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 336 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 337 | })), |
| 338 | framework::dataset::make("Min",{ 0, |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 339 | 13, |
| 340 | })), |
| 341 | framework::dataset::make("Max",{ 205, |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 342 | 180, |
| 343 | })), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 344 | framework::dataset::make("Expected", { true, false })), |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 345 | a_info, b_info, output_info, min, max, expected) |
| 346 | { |
| 347 | // Lock tensors |
| 348 | Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false), |
| 349 | &b_info.clone()->set_is_resizable(false), |
| 350 | &output_info.clone()->set_is_resizable(false), |
| 351 | min, |
| 352 | max); |
| 353 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 354 | } |
| 355 | // clang-format on |
| 356 | // *INDENT-ON* |
| 357 | |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 358 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 359 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases), |
| 360 | shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias) |
| 361 | { |
| 362 | TensorShape shape_bias(shape[0]); |
| 363 | |
| 364 | // Create tensors |
| 365 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 366 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 367 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 368 | |
| 369 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 370 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 371 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 372 | |
| 373 | // Create and configure function |
| 374 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage; |
| 375 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); |
| 376 | |
| 377 | // Validate valid region input and output |
| 378 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 379 | validate(in.info()->valid_region(), valid_region); |
| 380 | validate(out.info()->valid_region(), valid_region); |
| 381 | |
| 382 | // Validate valid region bias |
| 383 | if(add_bias) |
| 384 | { |
| 385 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 386 | validate(bias.info()->valid_region(), valid_region_bias); |
| 387 | } |
| 388 | |
| 389 | // Validate padding |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 390 | const PaddingSize padding(0); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 391 | validate(in.info()->padding(), padding); |
| 392 | validate(out.info()->padding(), padding); |
| 393 | |
| 394 | if(add_bias) |
| 395 | { |
| 396 | validate(bias.info()->padding(), padding); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 401 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 402 | { |
| 403 | // Validate output |
| 404 | validate(Accessor(_target), _reference); |
| 405 | } |
| 406 | |
| 407 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 408 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 409 | { |
| 410 | // Validate output |
| 411 | validate(Accessor(_target), _reference); |
| 412 | } |
| 413 | |
| 414 | TEST_SUITE(BoundedReLu) |
| 415 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 416 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 417 | { |
| 418 | // Validate output |
| 419 | validate(Accessor(_target), _reference); |
| 420 | } |
| 421 | |
| 422 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 423 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 424 | { |
| 425 | // Validate output |
| 426 | validate(Accessor(_target), _reference); |
| 427 | } |
| 428 | TEST_SUITE_END() // BoundedReLu |
| 429 | |
| 430 | TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 431 | |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 432 | TEST_SUITE(QuantizeDownInt32ToInt8ScaleByFixedPoint) |
| 433 | |
| 434 | const auto quantize_down_int32_to_int8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1, |
| 435 | 2) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 436 | * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", -128) * framework::dataset::make("max", 128) * framework::dataset::make("addBias", { false, true }); |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 437 | |
| 438 | const auto quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1, |
| 439 | 2) |
| 440 | * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true }); |
| 441 | |
| 442 | using NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture = |
| 443 | GEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint>; |
| 444 | |
| 445 | // *INDENT-OFF* |
| 446 | // clang-format off |
| 447 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 448 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::F32), // Invalid input data type |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 449 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 450 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), |
| 451 | }), |
| 452 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 453 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 454 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 455 | })), |
| 456 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED), |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 457 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 458 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED), |
| 459 | })), |
| 460 | framework::dataset::make("Min",{ -110, |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 461 | -113, |
| 462 | -113, |
| 463 | })), |
| 464 | framework::dataset::make("Max",{ 87, |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 465 | 97, |
| 466 | 97, |
| 467 | })), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 468 | framework::dataset::make("Expected", { false, false, true })), |
Georgios Pinitas | 448a81f | 2019-11-21 14:10:25 +0000 | [diff] [blame] | 469 | a_info, b_info, output_info, min, max, expected) |
| 470 | { |
| 471 | // Lock tensors |
| 472 | Status status = NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false), |
| 473 | &b_info.clone()->set_is_resizable(false), |
| 474 | &output_info.clone()->set_is_resizable(false), |
| 475 | min, |
| 476 | max); |
| 477 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 478 | } |
| 479 | // clang-format on |
| 480 | // *INDENT-ON* |
| 481 | |
| 482 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 483 | quantize_down_int32_to_int8_scale_by_fixedpoint_cases), |
| 484 | shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias) |
| 485 | { |
| 486 | TensorShape shape_bias(shape[0]); |
| 487 | |
| 488 | // Create tensors |
| 489 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 490 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 491 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8_SIGNED); |
| 492 | |
| 493 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 494 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 495 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 496 | |
| 497 | // Create and configure function |
| 498 | NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint output_stage; |
| 499 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); |
| 500 | |
| 501 | // Validate valid region input and output |
| 502 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 503 | validate(in.info()->valid_region(), valid_region); |
| 504 | validate(out.info()->valid_region(), valid_region); |
| 505 | |
| 506 | // Validate valid region bias |
| 507 | if(add_bias) |
| 508 | { |
| 509 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 510 | validate(bias.info()->valid_region(), valid_region_bias); |
| 511 | } |
| 512 | |
| 513 | // Validate padding |
| 514 | const PaddingSize padding(0); |
| 515 | validate(in.info()->padding(), padding); |
| 516 | validate(out.info()->padding(), padding); |
| 517 | |
| 518 | if(add_bias) |
| 519 | { |
| 520 | validate(bias.info()->padding(), padding); |
| 521 | } |
| 522 | } |
| 523 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 524 | quantize_down_int32_to_int8_scale_by_fixedpoint_cases)) |
| 525 | { |
| 526 | // Validate output |
| 527 | validate(Accessor(_target), _reference); |
| 528 | } |
| 529 | |
| 530 | TEST_SUITE(BoundedReLu) |
| 531 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 532 | quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases)) |
| 533 | { |
| 534 | // Validate output |
| 535 | validate(Accessor(_target), _reference); |
| 536 | } |
| 537 | TEST_SUITE_END() // BoundedReLu |
| 538 | TEST_SUITE_END() // QuantizeDownInt32ToInt8ScaleByFixedPoint |
| 539 | |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 540 | TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint) |
| 541 | |
| 542 | const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1, |
| 543 | 2) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 544 | * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true }); |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 545 | |
| 546 | const auto quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1, |
| 547 | 2) |
| 548 | * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true }); |
Vidhya Sudhan Loganathan | 951b8a4 | 2019-11-04 14:42:08 +0000 | [diff] [blame] | 549 | const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases = framework::dataset::make("result_fixedpoint_multiplier", 1073741823, |
| 550 | 1073741825) |
| 551 | * framework::dataset::make("result_shift", -3, |
| 552 | -2) |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 553 | * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true }); |
Manuel Bottini | 0726398 | 2019-10-17 18:37:26 +0100 | [diff] [blame] | 554 | |
Vidhya Sudhan Loganathan | 951b8a4 | 2019-11-04 14:42:08 +0000 | [diff] [blame] | 555 | const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, |
| 556 | 254601602) |
| 557 | * framework::dataset::make("result_shift", -3, |
| 558 | -1) |
| 559 | * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true }); |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 560 | |
| 561 | using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture = |
| 562 | GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>; |
| 563 | |
| 564 | // *INDENT-OFF* |
| 565 | // clang-format off |
| 566 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 567 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 568 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 569 | }), |
| 570 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 571 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 572 | })), |
| 573 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16), |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 574 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 575 | })), |
| 576 | framework::dataset::make("Min",{ -205, |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 577 | -180, |
| 578 | })), |
| 579 | framework::dataset::make("Max",{ 205, |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 580 | 180, |
| 581 | })), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 582 | framework::dataset::make("Expected", { true, false })), |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 583 | a_info, b_info, output_info, min, max, expected) |
| 584 | { |
| 585 | // Lock tensors |
| 586 | Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false), |
| 587 | &b_info.clone()->set_is_resizable(false), |
| 588 | &output_info.clone()->set_is_resizable(false), |
| 589 | min, |
| 590 | max); |
| 591 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 592 | } |
| 593 | // clang-format on |
| 594 | // *INDENT-ON* |
| 595 | |
| 596 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 597 | quantize_down_int32_to_int16_scale_by_fixedpoint_cases), |
| 598 | shape, result_fixedpoint_multiplier, result_shift, min, max, add_bias) |
| 599 | { |
| 600 | TensorShape shape_bias(shape[0]); |
| 601 | |
| 602 | // Create tensors |
| 603 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 604 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 605 | Tensor out = create_tensor<Tensor>(shape, DataType::QSYMM16); |
| 606 | |
| 607 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 608 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 609 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 610 | |
| 611 | // Create and configure function |
| 612 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint output_stage; |
| 613 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, min, max); |
| 614 | |
| 615 | // Validate valid region input and output |
| 616 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 617 | validate(in.info()->valid_region(), valid_region); |
| 618 | validate(out.info()->valid_region(), valid_region); |
| 619 | |
| 620 | // Validate valid region bias |
| 621 | if(add_bias) |
| 622 | { |
| 623 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 624 | validate(bias.info()->valid_region(), valid_region_bias); |
| 625 | } |
| 626 | |
| 627 | // Validate padding |
| 628 | const PaddingSize padding(0); |
| 629 | validate(in.info()->padding(), padding); |
| 630 | validate(out.info()->padding(), padding); |
| 631 | |
| 632 | if(add_bias) |
| 633 | { |
| 634 | validate(bias.info()->padding(), padding); |
| 635 | } |
| 636 | } |
Manuel Bottini | 0726398 | 2019-10-17 18:37:26 +0100 | [diff] [blame] | 637 | TEST_SUITE(NoRelu) |
| 638 | TEST_SUITE(MultSmallerEq1) |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 639 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 640 | quantize_down_int32_to_int16_scale_by_fixedpoint_cases)) |
| 641 | { |
| 642 | // Validate output |
| 643 | validate(Accessor(_target), _reference); |
| 644 | } |
Manuel Bottini | 0726398 | 2019-10-17 18:37:26 +0100 | [diff] [blame] | 645 | TEST_SUITE_END() // MultSmallerEq1 |
| 646 | TEST_SUITE(MultGreater1) |
| 647 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 648 | quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases)) |
| 649 | { |
| 650 | // Validate output |
| 651 | validate(Accessor(_target), _reference); |
| 652 | } |
| 653 | TEST_SUITE_END() // MultGreater1 |
| 654 | TEST_SUITE_END() // NoRelu |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 655 | TEST_SUITE(BoundedReLu) |
Manuel Bottini | 0726398 | 2019-10-17 18:37:26 +0100 | [diff] [blame] | 656 | TEST_SUITE(MultSmallerEq1) |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 657 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 658 | quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases)) |
| 659 | { |
| 660 | // Validate output |
| 661 | validate(Accessor(_target), _reference); |
| 662 | } |
Manuel Bottini | 0726398 | 2019-10-17 18:37:26 +0100 | [diff] [blame] | 663 | TEST_SUITE_END() // MultSmallerEq1 |
| 664 | TEST_SUITE(MultGreater1) |
| 665 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 666 | quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases)) |
| 667 | { |
| 668 | // Validate output |
| 669 | validate(Accessor(_target), _reference); |
| 670 | } |
| 671 | TEST_SUITE_END() // MultGreater1 |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 672 | TEST_SUITE_END() // BoundedReLu |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 673 | TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 674 | TEST_SUITE_END() // OutputStage |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 675 | TEST_SUITE_END() // GEMMLowp |
| 676 | TEST_SUITE_END() // NEON |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 677 | } // namespace validation |
| 678 | } // namespace test |
| 679 | } // namespace arm_compute |