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