Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 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) |
| 150 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpFusedOffsetOutputDataset()) |
| 151 | { |
| 152 | // Validate output |
| 153 | validate(Accessor(_target), _reference); |
| 154 | } |
| 155 | |
| 156 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpFusedOffsetOutputDataset()) |
| 157 | { |
| 158 | // Validate output |
| 159 | validate(Accessor(_target), _reference); |
| 160 | } |
| 161 | TEST_SUITE_END() // FusedOffsetOutput |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 162 | TEST_SUITE_END() // MatrixMultiplyCore |
| 163 | |
| 164 | TEST_SUITE(OutputStage) |
| 165 | |
| 166 | TEST_SUITE(QuantizeDownInt32ToUint8Scale) |
| 167 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 168 | 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] | 169 | 3) |
| 170 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 171 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 172 | 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] | 173 | 2) |
| 174 | * 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 }); |
| 175 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 176 | using NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8Scale>; |
| 177 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 178 | // *INDENT-OFF* |
| 179 | // clang-format off |
| 180 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 181 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
| 182 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max |
| 183 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 184 | }), |
| 185 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 186 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 187 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 188 | })), |
| 189 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 190 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 191 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 192 | })), |
| 193 | framework::dataset::make("Min",{ 0, |
| 194 | 8, |
| 195 | 13, |
| 196 | })), |
| 197 | framework::dataset::make("Max",{ 205, |
| 198 | 300, |
| 199 | 180, |
| 200 | })), |
| 201 | framework::dataset::make("Expected", { true, false, false })), |
| 202 | a_info, b_info, output_info, min, max, expected) |
| 203 | { |
| 204 | // Lock tensors |
| 205 | Status status = NEGEMMLowpQuantizeDownInt32ToUint8Scale::validate(&a_info.clone()->set_is_resizable(false), |
| 206 | &b_info.clone()->set_is_resizable(false), |
| 207 | &output_info.clone()->set_is_resizable(false), |
| 208 | min, |
| 209 | max); |
| 210 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 211 | } |
| 212 | // clang-format on |
| 213 | // *INDENT-ON* |
| 214 | |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 215 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases), |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 216 | shape, result_offset, result_mult_int, result_shift, min, max, add_bias) |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 217 | { |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 218 | TensorShape shape_bias(shape[0]); |
| 219 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 220 | // Create tensors |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 221 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 222 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 223 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 224 | |
| 225 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 226 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 227 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 228 | |
| 229 | // Create and configure function |
| 230 | NEGEMMLowpQuantizeDownInt32ToUint8Scale output_stage; |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 231 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_offset, result_mult_int, result_shift, min, max); |
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 | // Validate valid region input and output |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 234 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 235 | validate(in.info()->valid_region(), valid_region); |
| 236 | validate(out.info()->valid_region(), valid_region); |
| 237 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 238 | // Validate valid region bias |
| 239 | if(add_bias) |
| 240 | { |
| 241 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 242 | validate(bias.info()->valid_region(), valid_region_bias); |
| 243 | } |
| 244 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 245 | // Validate padding |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 246 | const PaddingSize padding(0); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 247 | validate(in.info()->padding(), padding); |
| 248 | validate(out.info()->padding(), padding); |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 249 | |
| 250 | if(add_bias) |
| 251 | { |
| 252 | validate(bias.info()->padding(), padding); |
| 253 | } |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases)) |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 257 | { |
| 258 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 259 | validate(Accessor(_target), _reference); |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 260 | } |
Pablo Tello | 6ff12a0 | 2017-11-02 16:09:35 +0000 | [diff] [blame] | 261 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 262 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases)) |
| 263 | { |
| 264 | // Validate output |
| 265 | validate(Accessor(_target), _reference); |
| 266 | } |
| 267 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 268 | TEST_SUITE(BoundedReLu) |
| 269 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
| 270 | { |
| 271 | // Validate output |
| 272 | validate(Accessor(_target), _reference); |
| 273 | } |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 274 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 275 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
| 276 | { |
| 277 | // Validate output |
| 278 | validate(Accessor(_target), _reference); |
| 279 | } |
| 280 | TEST_SUITE_END() // BoundedReLu |
| 281 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 282 | TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 283 | |
| 284 | TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint) |
| 285 | |
| 286 | 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, |
| 287 | 2) |
| 288 | * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 289 | |
| 290 | 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, |
| 291 | 2) |
| 292 | * 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 }); |
| 293 | |
| 294 | using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture = |
| 295 | GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>; |
| 296 | |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 297 | using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture = |
| 298 | GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>; |
| 299 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 300 | // *INDENT-OFF* |
| 301 | // clang-format off |
| 302 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 303 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
| 304 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max |
| 305 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 306 | }), |
| 307 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 308 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 309 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 310 | })), |
| 311 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 312 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 313 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 314 | })), |
| 315 | framework::dataset::make("Min",{ 0, |
| 316 | 8, |
| 317 | 13, |
| 318 | })), |
| 319 | framework::dataset::make("Max",{ 205, |
| 320 | 300, |
| 321 | 180, |
| 322 | })), |
| 323 | framework::dataset::make("Expected", { true, false, false })), |
| 324 | a_info, b_info, output_info, min, max, expected) |
| 325 | { |
| 326 | // Lock tensors |
| 327 | Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false), |
| 328 | &b_info.clone()->set_is_resizable(false), |
| 329 | &output_info.clone()->set_is_resizable(false), |
| 330 | min, |
| 331 | max); |
| 332 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 333 | } |
| 334 | // clang-format on |
| 335 | // *INDENT-ON* |
| 336 | |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 337 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 338 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases), |
| 339 | shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias) |
| 340 | { |
| 341 | TensorShape shape_bias(shape[0]); |
| 342 | |
| 343 | // Create tensors |
| 344 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 345 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 346 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 347 | |
| 348 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 349 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 350 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 351 | |
| 352 | // Create and configure function |
| 353 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage; |
| 354 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); |
| 355 | |
| 356 | // Validate valid region input and output |
| 357 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 358 | validate(in.info()->valid_region(), valid_region); |
| 359 | validate(out.info()->valid_region(), valid_region); |
| 360 | |
| 361 | // Validate valid region bias |
| 362 | if(add_bias) |
| 363 | { |
| 364 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 365 | validate(bias.info()->valid_region(), valid_region_bias); |
| 366 | } |
| 367 | |
| 368 | // Validate padding |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 369 | const PaddingSize padding(0); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 370 | validate(in.info()->padding(), padding); |
| 371 | validate(out.info()->padding(), padding); |
| 372 | |
| 373 | if(add_bias) |
| 374 | { |
| 375 | validate(bias.info()->padding(), padding); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 380 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 381 | { |
| 382 | // Validate output |
| 383 | validate(Accessor(_target), _reference); |
| 384 | } |
| 385 | |
| 386 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 387 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 388 | { |
| 389 | // Validate output |
| 390 | validate(Accessor(_target), _reference); |
| 391 | } |
| 392 | |
| 393 | TEST_SUITE(BoundedReLu) |
| 394 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 395 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 396 | { |
| 397 | // Validate output |
| 398 | validate(Accessor(_target), _reference); |
| 399 | } |
| 400 | |
| 401 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 402 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 403 | { |
| 404 | // Validate output |
| 405 | validate(Accessor(_target), _reference); |
| 406 | } |
| 407 | TEST_SUITE_END() // BoundedReLu |
| 408 | |
| 409 | TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint |
Gian Marco Iodice | bc415af | 2019-06-13 15:58:32 +0100 | [diff] [blame] | 410 | |
| 411 | TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint) |
| 412 | |
| 413 | 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, |
| 414 | 2) |
| 415 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 416 | |
| 417 | 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, |
| 418 | 2) |
| 419 | * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true }); |
| 420 | |
| 421 | using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture = |
| 422 | GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>; |
| 423 | |
| 424 | // *INDENT-OFF* |
| 425 | // clang-format off |
| 426 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 427 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
| 428 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max |
| 429 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 430 | }), |
| 431 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 432 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 433 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 434 | })), |
| 435 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16), |
| 436 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16), |
| 437 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 438 | })), |
| 439 | framework::dataset::make("Min",{ -205, |
| 440 | -60000, |
| 441 | -180, |
| 442 | })), |
| 443 | framework::dataset::make("Max",{ 205, |
| 444 | 60000, |
| 445 | 180, |
| 446 | })), |
| 447 | framework::dataset::make("Expected", { true, false, false })), |
| 448 | a_info, b_info, output_info, min, max, expected) |
| 449 | { |
| 450 | // Lock tensors |
| 451 | Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false), |
| 452 | &b_info.clone()->set_is_resizable(false), |
| 453 | &output_info.clone()->set_is_resizable(false), |
| 454 | min, |
| 455 | max); |
| 456 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 457 | } |
| 458 | // clang-format on |
| 459 | // *INDENT-ON* |
| 460 | |
| 461 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 462 | quantize_down_int32_to_int16_scale_by_fixedpoint_cases), |
| 463 | shape, result_fixedpoint_multiplier, result_shift, min, max, add_bias) |
| 464 | { |
| 465 | TensorShape shape_bias(shape[0]); |
| 466 | |
| 467 | // Create tensors |
| 468 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 469 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 470 | Tensor out = create_tensor<Tensor>(shape, DataType::QSYMM16); |
| 471 | |
| 472 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 473 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 474 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 475 | |
| 476 | // Create and configure function |
| 477 | NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint output_stage; |
| 478 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, min, max); |
| 479 | |
| 480 | // Validate valid region input and output |
| 481 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 482 | validate(in.info()->valid_region(), valid_region); |
| 483 | validate(out.info()->valid_region(), valid_region); |
| 484 | |
| 485 | // Validate valid region bias |
| 486 | if(add_bias) |
| 487 | { |
| 488 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 489 | validate(bias.info()->valid_region(), valid_region_bias); |
| 490 | } |
| 491 | |
| 492 | // Validate padding |
| 493 | const PaddingSize padding(0); |
| 494 | validate(in.info()->padding(), padding); |
| 495 | validate(out.info()->padding(), padding); |
| 496 | |
| 497 | if(add_bias) |
| 498 | { |
| 499 | validate(bias.info()->padding(), padding); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 504 | quantize_down_int32_to_int16_scale_by_fixedpoint_cases)) |
| 505 | { |
| 506 | // Validate output |
| 507 | validate(Accessor(_target), _reference); |
| 508 | } |
| 509 | |
| 510 | TEST_SUITE(BoundedReLu) |
| 511 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 512 | quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases)) |
| 513 | { |
| 514 | // Validate output |
| 515 | validate(Accessor(_target), _reference); |
| 516 | } |
| 517 | TEST_SUITE_END() // BoundedReLu |
| 518 | |
| 519 | TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint |
| 520 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 521 | TEST_SUITE_END() // OutputStage |
| 522 | |
| 523 | TEST_SUITE_END() // GEMMLowp |
| 524 | TEST_SUITE_END() // NEON |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 525 | } // namespace validation |
| 526 | } // namespace test |
| 527 | } // namespace arm_compute |