Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 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" |
| 31 | #include "tests/datasets/LargeGEMMLowpDataset.h" |
| 32 | #include "tests/datasets/ShapeDatasets.h" |
| 33 | #include "tests/datasets/SmallGEMMLowpDataset.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/GEMMLowpFixture.h" |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | TEST_SUITE(CL) |
| 47 | TEST_SUITE(GEMMLowp) |
| 48 | |
| 49 | TEST_SUITE(MatrixMultiplyCore) |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame] | 50 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 51 | using CLGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>; |
| 52 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 53 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset(), |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 54 | shape_a, shape_b, shape_c, a_offset, b_offset) |
| 55 | { |
| 56 | // Create tensors |
| 57 | CLTensor a = create_tensor<CLTensor>(shape_a, DataType::QASYMM8); |
| 58 | CLTensor b = create_tensor<CLTensor>(shape_b, DataType::QASYMM8); |
| 59 | CLTensor c = create_tensor<CLTensor>(shape_c, DataType::S32); |
| 60 | |
| 61 | a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset)); |
| 62 | b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset)); |
| 63 | |
| 64 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 65 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 66 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 67 | |
| 68 | // Create and configure function |
| 69 | CLGEMMLowpMatrixMultiplyCore gemmlowp_mm; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 70 | // TODO (giaiod01) COMPMID-1672 - Extending the test to validate add bias in offset contribution |
| 71 | gemmlowp_mm.configure(&a, &b, nullptr, &c); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset()) |
| 75 | { |
| 76 | // Validate output |
| 77 | validate(CLAccessor(_target), _reference); |
| 78 | } |
| 79 | |
| 80 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset()) |
| 81 | { |
| 82 | // Validate output |
| 83 | validate(CLAccessor(_target), _reference); |
| 84 | } |
| 85 | |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame] | 86 | TEST_SUITE(Output3D) |
| 87 | using CLGEMMLowpMatrixMultiplyCoreOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, true>; |
| 88 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpOutput3DDataset()) |
| 89 | { |
| 90 | // Validate output |
| 91 | validate(CLAccessor(_target), _reference); |
| 92 | } |
| 93 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpOutput3DDataset()) |
| 94 | { |
| 95 | // Validate output |
| 96 | validate(CLAccessor(_target), _reference); |
| 97 | } |
| 98 | TEST_SUITE_END() // Output3D |
| 99 | |
| 100 | TEST_SUITE(InputOutput3D) |
| 101 | using CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, true, true>; |
| 102 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpInputOutput3DDataset()) |
| 103 | { |
| 104 | // Validate output |
| 105 | validate(CLAccessor(_target), _reference); |
| 106 | } |
| 107 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpInputOutput3DDataset()) |
| 108 | { |
| 109 | // Validate output |
| 110 | validate(CLAccessor(_target), _reference); |
| 111 | } |
| 112 | TEST_SUITE_END() // InputOutput3D |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 113 | TEST_SUITE_END() // MatrixMultiplyCore |
| 114 | |
| 115 | TEST_SUITE(OutputStage) |
| 116 | TEST_SUITE(QuantizeDownInt32ToUint8Scale) |
| 117 | |
| 118 | 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, |
| 119 | 3) |
| 120 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 121 | |
| 122 | const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, |
| 123 | 2) |
| 124 | * 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 }); |
| 125 | |
| 126 | using CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8Scale>; |
| 127 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 128 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases), |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 129 | shape, result_offset, result_mult_int, result_shift, min, max, add_bias) |
| 130 | { |
| 131 | TensorShape shape_bias(shape[0]); |
| 132 | |
| 133 | // Create tensors |
| 134 | CLTensor in = create_tensor<CLTensor>(shape, DataType::S32); |
| 135 | CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32); |
| 136 | CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 137 | |
| 138 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 139 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 140 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 141 | |
| 142 | // Create and configure function |
| 143 | CLGEMMLowpQuantizeDownInt32ToUint8Scale output_stage; |
| 144 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_offset, result_mult_int, result_shift, min, max); |
| 145 | |
| 146 | // Validate valid region input and output |
| 147 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 148 | validate(in.info()->valid_region(), valid_region); |
| 149 | validate(out.info()->valid_region(), valid_region); |
| 150 | |
| 151 | // Validate valid region bias |
| 152 | if(add_bias) |
| 153 | { |
| 154 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 155 | validate(bias.info()->valid_region(), valid_region_bias); |
| 156 | } |
| 157 | |
| 158 | // Validate padding |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 159 | const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding(); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 160 | validate(in.info()->padding(), padding); |
| 161 | validate(out.info()->padding(), padding); |
| 162 | |
| 163 | if(add_bias) |
| 164 | { |
| 165 | validate(bias.info()->padding(), padding); |
| 166 | } |
| 167 | } |
| 168 | |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 169 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases)) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 170 | { |
| 171 | // Validate output |
| 172 | validate(CLAccessor(_target), _reference); |
| 173 | } |
| 174 | |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 175 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases)) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 176 | { |
| 177 | // Validate output |
| 178 | validate(CLAccessor(_target), _reference); |
| 179 | } |
| 180 | |
| 181 | TEST_SUITE(BoundedReLu) |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 182 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases)) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 183 | { |
| 184 | // Validate output |
| 185 | validate(CLAccessor(_target), _reference); |
| 186 | } |
| 187 | |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 188 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 189 | quantize_down_int32_to_uint8_scale_relu_cases)) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 190 | { |
| 191 | // Validate output |
| 192 | validate(CLAccessor(_target), _reference); |
| 193 | } |
| 194 | TEST_SUITE_END() // BoundedReLu |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 195 | TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 196 | |
| 197 | TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint) |
| 198 | |
| 199 | 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, |
| 200 | 2) |
| 201 | * 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 }); |
| 202 | |
| 203 | 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, |
| 204 | 2) |
| 205 | * 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 }); |
| 206 | |
| 207 | using CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture = |
| 208 | GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>; |
| 209 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 210 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 211 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases), |
| 212 | shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias) |
| 213 | { |
| 214 | TensorShape shape_bias(shape[0]); |
| 215 | |
| 216 | // Create tensors |
| 217 | CLTensor in = create_tensor<CLTensor>(shape, DataType::S32); |
| 218 | CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32); |
| 219 | CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 220 | |
| 221 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 222 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 223 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 224 | |
| 225 | // Create and configure function |
| 226 | CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage; |
| 227 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max); |
| 228 | |
| 229 | // Validate valid region input and output |
| 230 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 231 | validate(in.info()->valid_region(), valid_region); |
| 232 | validate(out.info()->valid_region(), valid_region); |
| 233 | |
| 234 | // Validate valid region bias |
| 235 | if(add_bias) |
| 236 | { |
| 237 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 238 | validate(bias.info()->valid_region(), valid_region_bias); |
| 239 | } |
| 240 | |
| 241 | // Validate padding |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 242 | const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding(); |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 243 | validate(in.info()->padding(), padding); |
| 244 | validate(out.info()->padding(), padding); |
| 245 | |
| 246 | if(add_bias) |
| 247 | { |
| 248 | validate(bias.info()->padding(), padding); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 253 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 254 | { |
| 255 | // Validate output |
| 256 | validate(CLAccessor(_target), _reference); |
| 257 | } |
| 258 | |
| 259 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 260 | quantize_down_int32_to_uint8_scale_by_fixedpoint_cases)) |
| 261 | { |
| 262 | // Validate output |
| 263 | validate(CLAccessor(_target), _reference); |
| 264 | } |
| 265 | |
| 266 | TEST_SUITE(BoundedReLu) |
| 267 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), |
| 268 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 269 | { |
| 270 | // Validate output |
| 271 | validate(CLAccessor(_target), _reference); |
| 272 | } |
| 273 | |
| 274 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 275 | quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases)) |
| 276 | { |
| 277 | // Validate output |
| 278 | validate(CLAccessor(_target), _reference); |
| 279 | } |
| 280 | TEST_SUITE_END() // BoundedReLu |
| 281 | TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint |
| 282 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 283 | TEST_SUITE_END() // OutputStage |
| 284 | TEST_SUITE_END() // GEMMLowp |
| 285 | TEST_SUITE_END() // CL |
| 286 | } // namespace validation |
| 287 | } // namespace test |
| 288 | } // namespace arm_compute |