Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 1 | /* |
Giorgio Arena | 5f6fdc1 | 2021-06-09 15:23:06 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCore.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLGEMMLowpOutputStage.h" |
| 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 31 | #include "tests/datasets/GEMMLowpFusedOffsetOutputDataset.h" |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 32 | #include "tests/datasets/LargeGEMMLowpDataset.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/datasets/SmallGEMMLowpDataset.h" |
| 35 | #include "tests/framework/Asserts.h" |
| 36 | #include "tests/framework/Macros.h" |
| 37 | #include "tests/framework/datasets/Datasets.h" |
| 38 | #include "tests/validation/Validation.h" |
| 39 | #include "tests/validation/fixtures/GEMMLowpFixture.h" |
| 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 47 | namespace |
| 48 | { |
| 49 | constexpr AbsoluteTolerance<float> tolerance_quant(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 50 | } |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 51 | TEST_SUITE(CL) |
| 52 | TEST_SUITE(GEMMLowp) |
| 53 | |
| 54 | TEST_SUITE(MatrixMultiplyCore) |
| 55 | using CLGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>; |
| 56 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 57 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset()) |
| 58 | { |
| 59 | // Validate output |
| 60 | validate(CLAccessor(_target), _reference); |
| 61 | } |
| 62 | |
| 63 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset()) |
| 64 | { |
| 65 | // Validate output |
| 66 | validate(CLAccessor(_target), _reference); |
| 67 | } |
| 68 | |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 69 | TEST_SUITE(FusedOffsetOutput) |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 70 | TEST_SUITE(QASYMM8) |
Giorgio Arena | 5f6fdc1 | 2021-06-09 15:23:06 +0100 | [diff] [blame] | 71 | using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputUint8Fixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>; |
| 72 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputUint8Fixture, framework::DatasetMode::ALL, combine(combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(), |
| 73 | framework::dataset::make("DataType", { DataType::QASYMM8 })), |
| 74 | framework::dataset::make("reshape_b_only_on_first_run", { true, false }))) |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 75 | { |
| 76 | // Validate output |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 77 | validate(CLAccessor(_target), _reference, tolerance_quant); |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Giorgio Arena | 5f6fdc1 | 2021-06-09 15:23:06 +0100 | [diff] [blame] | 80 | TEST_SUITE(Output3D) |
| 81 | using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputOutput3DUint8Fixture = |
| 82 | GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, true>; |
| 83 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputOutput3DUint8Fixture, framework::DatasetMode::ALL, |
| 84 | combine(combine(datasets::SmallGEMMLowpFusedOffsetOutputOutput3DUint8Dataset(), |
| 85 | framework::dataset::make("DataType", { DataType::QASYMM8 })), |
| 86 | framework::dataset::make("reshape_b_only_on_first_run", { true, false }))) |
| 87 | { |
| 88 | // Validate output |
| 89 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 90 | } |
| 91 | TEST_SUITE_END() // Output3D |
| 92 | |
| 93 | TEST_SUITE(InputOutput3D) |
| 94 | using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInputOutput3DUint8Fixture = |
| 95 | GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, true, true>; |
| 96 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInputOutput3DUint8Fixture, framework::DatasetMode::ALL, |
| 97 | combine(combine(datasets::SmallGEMMLowpFusedOffsetOutputInputOutput3DUint8Dataset(), |
| 98 | framework::dataset::make("DataType", { DataType::QASYMM8 })), |
| 99 | framework::dataset::make("reshape_b_only_on_first_run", { true, false }))) |
| 100 | { |
| 101 | // Validate output |
| 102 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 103 | } |
| 104 | TEST_SUITE_END() // InputOutput3D |
| 105 | |
| 106 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputUint8Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(), |
| 107 | framework::dataset::make("DataType", { DataType::QASYMM8 })), |
| 108 | framework::dataset::make("reshape_b_only_on_first_run", { true, false }))) |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 109 | { |
| 110 | // Validate output |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 111 | validate(CLAccessor(_target), _reference, tolerance_quant); |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 112 | } |
Manuel Bottini | 959c26d | 2019-12-02 16:22:35 +0000 | [diff] [blame] | 113 | TEST_SUITE_END() // QASYMM8 |
| 114 | TEST_SUITE(QASYMM8_SIGNED) |
| 115 | using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInt8Fixture = |
| 116 | GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, false, int8_t, int8_t>; |
| 117 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInt8Fixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputInt8Dataset(), |
| 118 | framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED }))) |
| 119 | { |
| 120 | // Validate output |
| 121 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 122 | } |
| 123 | TEST_SUITE_END() // QASYMM8_SIGNED |
George Wort | 2d7e683 | 2019-02-22 16:37:41 +0000 | [diff] [blame] | 124 | TEST_SUITE_END() // FusedOffsetOutput |
| 125 | |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame] | 126 | TEST_SUITE(Output3D) |
| 127 | using CLGEMMLowpMatrixMultiplyCoreOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, true>; |
| 128 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpOutput3DDataset()) |
| 129 | { |
| 130 | // Validate output |
| 131 | validate(CLAccessor(_target), _reference); |
| 132 | } |
| 133 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpOutput3DDataset()) |
| 134 | { |
| 135 | // Validate output |
| 136 | validate(CLAccessor(_target), _reference); |
| 137 | } |
| 138 | TEST_SUITE_END() // Output3D |
| 139 | |
| 140 | TEST_SUITE(InputOutput3D) |
| 141 | using CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, true, true>; |
| 142 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpInputOutput3DDataset()) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(CLAccessor(_target), _reference); |
| 146 | } |
| 147 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpInputOutput3DDataset()) |
| 148 | { |
| 149 | // Validate output |
| 150 | validate(CLAccessor(_target), _reference); |
| 151 | } |
| 152 | TEST_SUITE_END() // InputOutput3D |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 153 | TEST_SUITE_END() // MatrixMultiplyCore |
| 154 | |
| 155 | TEST_SUITE(OutputStage) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 156 | |
Luca Foschiani | 4b86953 | 2020-02-13 15:07:36 +0000 | [diff] [blame] | 157 | TEST_SUITE(QuantizeDownInt32Scale) |
| 158 | |
| 159 | TEST_SUITE(QASYMM8) |
| 160 | |
| 161 | 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, |
| 162 | 3) |
| 163 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true }); |
| 164 | |
| 165 | const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, |
| 166 | 2) |
| 167 | * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 173) * framework::dataset::make("addBias", { false, true }); |
| 168 | |
| 169 | using CLGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage>; |
| 170 | |
| 171 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases)) |
| 172 | { |
| 173 | // Validate output |
| 174 | validate(CLAccessor(_target), _reference); |
| 175 | } |
| 176 | |
| 177 | TEST_SUITE(BoundedReLu) |
| 178 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
| 179 | { |
| 180 | // Validate output |
| 181 | validate(CLAccessor(_target), _reference); |
| 182 | } |
| 183 | |
| 184 | TEST_SUITE_END() // BoundedReLu |
| 185 | TEST_SUITE_END() // QASYMM8 |
| 186 | |
| 187 | TEST_SUITE(QASYMM8_SIGNED) |
| 188 | |
| 189 | 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, |
| 190 | 3) |
| 191 | * framework::dataset::make("min", -128) * framework::dataset::make("max", 127) * framework::dataset::make("addBias", { false, true }); |
| 192 | |
| 193 | const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, |
| 194 | 2) |
| 195 | * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", -100, -98) * framework::dataset::make("max", 71, 73) * framework::dataset::make("addBias", { false, true }); |
| 196 | |
| 197 | using CLGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage>; |
| 198 | |
| 199 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases)) |
| 200 | { |
| 201 | // Validate output |
| 202 | validate(CLAccessor(_target), _reference); |
| 203 | } |
| 204 | |
| 205 | TEST_SUITE(BoundedReLu) |
| 206 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases)) |
| 207 | { |
| 208 | // Validate output |
| 209 | validate(CLAccessor(_target), _reference); |
| 210 | } |
| 211 | |
| 212 | TEST_SUITE_END() // BoundedReLu |
| 213 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 214 | TEST_SUITE_END() // QuantizeDownInt32Scale |
| 215 | |
Sheri Zhang | 1b14c75 | 2020-03-09 14:29:52 +0000 | [diff] [blame] | 216 | TEST_SUITE(QuantizeDownInt32ScaleByFloat) |
| 217 | |
| 218 | TEST_SUITE(QASYMM8) |
| 219 | using CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture = |
| 220 | GEMMLowpQuantizeDownInt32ScaleByFloatValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage, uint8_t>; |
| 221 | |
| 222 | FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture, framework::DatasetMode::ALL, |
| 223 | combine(combine(combine(combine(combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), |
| 224 | datasets::TinyShapes()), |
| 225 | framework::dataset::make("result_real_multiplier", 0.33f)), |
| 226 | framework::dataset::make("result_offset", 2, 3)), |
| 227 | framework::dataset::make("min", 0)), |
| 228 | framework::dataset::make("max", 255)), |
| 229 | framework::dataset::make("addBias", { false, true }))) |
| 230 | { |
| 231 | // Validate output |
| 232 | validate(CLAccessor(_target), _reference); |
| 233 | } |
| 234 | TEST_SUITE_END() // QASYMM8 |
| 235 | |
| 236 | TEST_SUITE(QASYMM8_SIGNED) |
| 237 | using CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture_Signed = |
| 238 | GEMMLowpQuantizeDownInt32ScaleByFloatValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage, int8_t>; |
| 239 | FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture_Signed, framework::DatasetMode::ALL, |
| 240 | combine(combine(combine(combine(combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), |
| 241 | datasets::TinyShapes()), |
| 242 | framework::dataset::make("result_real_multiplier", 0.33f)), |
| 243 | framework::dataset::make("result_offset", 2, 3)), |
| 244 | framework::dataset::make("min", -128)), |
| 245 | framework::dataset::make("max", 127)), |
| 246 | framework::dataset::make("addBias", { false, true }))) |
| 247 | { |
| 248 | // Validate output |
| 249 | validate(CLAccessor(_target), _reference); |
| 250 | } |
| 251 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 252 | |
| 253 | TEST_SUITE_END() // QuantizeDownInt32ScaleByFloat |
| 254 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 255 | TEST_SUITE_END() // OutputStage |
| 256 | TEST_SUITE_END() // GEMMLowp |
| 257 | TEST_SUITE_END() // CL |
| 258 | } // namespace validation |
| 259 | } // namespace test |
| 260 | } // namespace arm_compute |