Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 1 | /* |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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" |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 33 | #include "tests/datasets/LargeGEMMLowpDataset.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 34 | #include "tests/datasets/ShapeDatasets.h" |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 35 | #include "tests/datasets/SmallGEMMLowpDataset.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 36 | #include "tests/framework/Asserts.h" |
| 37 | #include "tests/framework/Macros.h" |
| 38 | #include "tests/framework/datasets/Datasets.h" |
| 39 | #include "tests/validation/Validation.h" |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 40 | #include "tests/validation/fixtures/GEMMLowpAssemblyFixture.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 41 | #include "tests/validation/fixtures/GEMMLowpFixture.h" |
| 42 | |
| 43 | namespace arm_compute |
| 44 | { |
| 45 | namespace test |
| 46 | { |
| 47 | namespace validation |
| 48 | { |
| 49 | namespace |
| 50 | { |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 51 | 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] | 52 | } // namespace |
| 53 | |
| 54 | TEST_SUITE(NEON) |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 55 | TEST_SUITE(ASSEMBLY_MATRIX_MULTIPLY) |
Michalis Spyrou | f3dfa27 | 2017-11-21 17:52:12 +0000 | [diff] [blame] | 56 | |
| 57 | using NEGEMMAssemblyFixture_S8 = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore, int8_t>; |
| 58 | using NEGEMMAssemblyFixture_U8 = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore, uint8_t>; |
| 59 | |
| 60 | TEST_SUITE(S8) |
| 61 | 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] | 62 | { |
| 63 | // Validate output |
| 64 | validate(Accessor(_target), _reference); |
| 65 | } |
| 66 | TEST_SUITE_END() |
| 67 | |
Michalis Spyrou | f3dfa27 | 2017-11-21 17:52:12 +0000 | [diff] [blame] | 68 | TEST_SUITE(U8) |
| 69 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAssemblyFixture_U8, framework::DatasetMode::PRECOMMIT, data_matrix_multiply) |
| 70 | { |
| 71 | // Validate output |
| 72 | validate(Accessor(_target), _reference); |
| 73 | } |
| 74 | TEST_SUITE_END() |
| 75 | TEST_SUITE_END() |
| 76 | |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 77 | TEST_SUITE(GEMMLowp) |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 78 | TEST_SUITE(MatrixMultiplyCore) |
| 79 | using NEGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>; |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 80 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 81 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()), |
| 82 | shape_a, shape_b, shape_c, a_offset, b_offset) |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 83 | { |
| 84 | // Create tensors |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 85 | Tensor a = create_tensor<Tensor>(shape_a, DataType::QASYMM8); |
| 86 | Tensor b = create_tensor<Tensor>(shape_b, DataType::QASYMM8); |
| 87 | Tensor c = create_tensor<Tensor>(shape_c, DataType::S32); |
| 88 | |
| 89 | a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset)); |
| 90 | b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset)); |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 91 | |
| 92 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 93 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 94 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 95 | |
| 96 | // Create and configure function |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 97 | NEGEMMLowpMatrixMultiplyCore gemmlowp_mm; |
| 98 | gemmlowp_mm.configure(&a, &b, &c); |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 101 | // *INDENT-OFF* |
| 102 | // clang-format off |
| 103 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 104 | 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] | 105 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 106 | TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions |
| 107 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions |
| 108 | TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), |
| 109 | }), |
| 110 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 111 | 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(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)), |
| 115 | })), |
| 116 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32), |
| 117 | TensorInfo(TensorShape(33U, 13U), 1, DataType::S32), |
| 118 | TensorInfo(TensorShape(33U, 13U), 1, DataType::S32), |
| 119 | TensorInfo(TensorShape(8U, 11U), 1, DataType::S32), |
| 120 | TensorInfo(TensorShape(64U, 32U), 1, DataType::S32), |
| 121 | })), |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 122 | framework::dataset::make("Expected", { false, false, false, false, true })), |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 123 | a_info, b_info, output_info, expected) |
| 124 | { |
| 125 | // Lock tensors |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 126 | Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false), |
| 127 | &b_info.clone()->set_is_resizable(false), |
| 128 | &output_info.clone()->set_is_resizable(false)); |
| 129 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 130 | } |
| 131 | // clang-format on |
| 132 | // *INDENT-ON* |
| 133 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 134 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset()) |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 135 | { |
| 136 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 137 | validate(Accessor(_target), _reference); |
| 138 | } |
| 139 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 140 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset()) |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 141 | { |
| 142 | // Validate output |
| 143 | validate(Accessor(_target), _reference); |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 144 | } |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 145 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 146 | TEST_SUITE_END() // MatrixMultiplyCore |
| 147 | |
| 148 | TEST_SUITE(OutputStage) |
| 149 | |
| 150 | TEST_SUITE(QuantizeDownInt32ToUint8Scale) |
| 151 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 152 | 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] | 153 | 3) |
| 154 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 155 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 156 | 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] | 157 | 2) |
| 158 | * 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 }); |
| 159 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 160 | using NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8Scale>; |
| 161 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 162 | // *INDENT-OFF* |
| 163 | // clang-format off |
| 164 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 165 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
| 166 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max |
| 167 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 168 | }), |
| 169 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 170 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 171 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 172 | })), |
| 173 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 174 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 175 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 176 | })), |
| 177 | framework::dataset::make("Min",{ 0, |
| 178 | 8, |
| 179 | 13, |
| 180 | })), |
| 181 | framework::dataset::make("Max",{ 205, |
| 182 | 300, |
| 183 | 180, |
| 184 | })), |
| 185 | framework::dataset::make("Expected", { true, false, false })), |
| 186 | a_info, b_info, output_info, min, max, expected) |
| 187 | { |
| 188 | // Lock tensors |
| 189 | Status status = NEGEMMLowpQuantizeDownInt32ToUint8Scale::validate(&a_info.clone()->set_is_resizable(false), |
| 190 | &b_info.clone()->set_is_resizable(false), |
| 191 | &output_info.clone()->set_is_resizable(false), |
| 192 | min, |
| 193 | max); |
| 194 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 195 | } |
| 196 | // clang-format on |
| 197 | // *INDENT-ON* |
| 198 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 199 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), quantize_down_int32_to_uint8_scale_cases), |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 200 | shape, result_offset, result_mult_int, result_shift, min, max, add_bias) |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 201 | { |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 202 | TensorShape shape_bias(shape[0]); |
| 203 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 204 | // Create tensors |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 205 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 206 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 207 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 208 | |
| 209 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 210 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 211 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 212 | |
| 213 | // Create and configure function |
| 214 | NEGEMMLowpQuantizeDownInt32ToUint8Scale output_stage; |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 215 | 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] | 216 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 217 | // Validate valid region input and output |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 218 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 219 | validate(in.info()->valid_region(), valid_region); |
| 220 | validate(out.info()->valid_region(), valid_region); |
| 221 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 222 | // Validate valid region bias |
| 223 | if(add_bias) |
| 224 | { |
| 225 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 226 | validate(bias.info()->valid_region(), valid_region_bias); |
| 227 | } |
| 228 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 229 | // Validate padding |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 230 | const PaddingSize padding(0); |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 231 | validate(in.info()->padding(), padding); |
| 232 | validate(out.info()->padding(), padding); |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 233 | |
| 234 | if(add_bias) |
| 235 | { |
| 236 | validate(bias.info()->padding(), padding); |
| 237 | } |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | 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] | 241 | { |
| 242 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 243 | validate(Accessor(_target), _reference); |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 244 | } |
Pablo Tello | 6ff12a0 | 2017-11-02 16:09:35 +0000 | [diff] [blame] | 245 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 246 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases)) |
| 247 | { |
| 248 | // Validate output |
| 249 | validate(Accessor(_target), _reference); |
| 250 | } |
| 251 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 252 | TEST_SUITE(BoundedReLu) |
| 253 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
| 254 | { |
| 255 | // Validate output |
| 256 | validate(Accessor(_target), _reference); |
| 257 | } |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 258 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 259 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
| 260 | { |
| 261 | // Validate output |
| 262 | validate(Accessor(_target), _reference); |
| 263 | } |
| 264 | TEST_SUITE_END() // BoundedReLu |
| 265 | |
Gian Marco | 6b77e91 | 2017-11-17 09:27:57 +0000 | [diff] [blame] | 266 | TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 267 | |
| 268 | TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint) |
| 269 | |
| 270 | 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, |
| 271 | 2) |
| 272 | * 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 }); |
| 273 | |
| 274 | 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, |
| 275 | 2) |
| 276 | * 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 }); |
| 277 | |
| 278 | using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture = |
| 279 | GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>; |
| 280 | |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 281 | // *INDENT-OFF* |
| 282 | // clang-format off |
| 283 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 284 | framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16 |
| 285 | TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max |
| 286 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type |
| 287 | }), |
| 288 | framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 289 | TensorInfo(TensorShape(21U), 1, DataType::S32), |
| 290 | TensorInfo(TensorShape(20U), 1, DataType::S32), |
| 291 | })), |
| 292 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 293 | TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8), |
| 294 | TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), |
| 295 | })), |
| 296 | framework::dataset::make("Min",{ 0, |
| 297 | 8, |
| 298 | 13, |
| 299 | })), |
| 300 | framework::dataset::make("Max",{ 205, |
| 301 | 300, |
| 302 | 180, |
| 303 | })), |
| 304 | framework::dataset::make("Expected", { true, false, false })), |
| 305 | a_info, b_info, output_info, min, max, expected) |
| 306 | { |
| 307 | // Lock tensors |
| 308 | Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false), |
| 309 | &b_info.clone()->set_is_resizable(false), |
| 310 | &output_info.clone()->set_is_resizable(false), |
| 311 | min, |
| 312 | max); |
| 313 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 314 | } |
| 315 | // clang-format on |
| 316 | // *INDENT-ON* |
| 317 | |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 318 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), |
| 319 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases), |
| 320 | shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias) |
| 321 | { |
| 322 | TensorShape shape_bias(shape[0]); |
| 323 | |
| 324 | // Create tensors |
| 325 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 326 | Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32); |
| 327 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 328 | |
| 329 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 330 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 331 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 332 | |
| 333 | // Create and configure function |
| 334 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage; |
| 335 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); |
| 336 | |
| 337 | // Validate valid region input and output |
| 338 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 339 | validate(in.info()->valid_region(), valid_region); |
| 340 | validate(out.info()->valid_region(), valid_region); |
| 341 | |
| 342 | // Validate valid region bias |
| 343 | if(add_bias) |
| 344 | { |
| 345 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 346 | validate(bias.info()->valid_region(), valid_region_bias); |
| 347 | } |
| 348 | |
| 349 | // Validate padding |
Gian Marco | 7f0f790 | 2017-12-07 09:26:56 +0000 | [diff] [blame] | 350 | const PaddingSize padding(0); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 351 | validate(in.info()->padding(), padding); |
| 352 | validate(out.info()->padding(), padding); |
| 353 | |
| 354 | if(add_bias) |
| 355 | { |
| 356 | validate(bias.info()->padding(), padding); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 361 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 362 | { |
| 363 | // Validate output |
| 364 | validate(Accessor(_target), _reference); |
| 365 | } |
| 366 | |
| 367 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 368 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 369 | { |
| 370 | // Validate output |
| 371 | validate(Accessor(_target), _reference); |
| 372 | } |
| 373 | |
| 374 | TEST_SUITE(BoundedReLu) |
| 375 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 376 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 377 | { |
| 378 | // Validate output |
| 379 | validate(Accessor(_target), _reference); |
| 380 | } |
| 381 | |
| 382 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 383 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 384 | { |
| 385 | // Validate output |
| 386 | validate(Accessor(_target), _reference); |
| 387 | } |
| 388 | TEST_SUITE_END() // BoundedReLu |
| 389 | |
| 390 | TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 391 | TEST_SUITE_END() // OutputStage |
| 392 | |
| 393 | TEST_SUITE_END() // GEMMLowp |
| 394 | TEST_SUITE_END() // NEON |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 395 | } // namespace validation |
| 396 | } // namespace test |
| 397 | } // namespace arm_compute |