Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [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 | */ |
| 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) |
| 50 | using CLGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>; |
| 51 | |
| 52 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()), |
| 53 | shape_a, shape_b, shape_c, a_offset, b_offset) |
| 54 | { |
| 55 | // Create tensors |
| 56 | CLTensor a = create_tensor<CLTensor>(shape_a, DataType::QASYMM8); |
| 57 | CLTensor b = create_tensor<CLTensor>(shape_b, DataType::QASYMM8); |
| 58 | CLTensor c = create_tensor<CLTensor>(shape_c, DataType::S32); |
| 59 | |
| 60 | a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset)); |
| 61 | b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset)); |
| 62 | |
| 63 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 64 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 65 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 66 | |
| 67 | // Create and configure function |
| 68 | CLGEMMLowpMatrixMultiplyCore gemmlowp_mm; |
| 69 | gemmlowp_mm.configure(&a, &b, &c); |
| 70 | } |
| 71 | |
| 72 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset()) |
| 73 | { |
| 74 | // Validate output |
| 75 | validate(CLAccessor(_target), _reference); |
| 76 | } |
| 77 | |
| 78 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset()) |
| 79 | { |
| 80 | // Validate output |
| 81 | validate(CLAccessor(_target), _reference); |
| 82 | } |
| 83 | |
| 84 | TEST_SUITE_END() // MatrixMultiplyCore |
| 85 | |
| 86 | TEST_SUITE(OutputStage) |
| 87 | TEST_SUITE(QuantizeDownInt32ToUint8Scale) |
| 88 | |
| 89 | 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, |
| 90 | 3) |
| 91 | * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true }); |
| 92 | |
| 93 | const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, |
| 94 | 2) |
| 95 | * 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 }); |
| 96 | |
| 97 | using CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8Scale>; |
| 98 | |
| 99 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), quantize_down_int32_to_uint8_scale_cases), |
| 100 | shape, result_offset, result_mult_int, result_shift, min, max, add_bias) |
| 101 | { |
| 102 | TensorShape shape_bias(shape[0]); |
| 103 | |
| 104 | // Create tensors |
| 105 | CLTensor in = create_tensor<CLTensor>(shape, DataType::S32); |
| 106 | CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32); |
| 107 | CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8); |
| 108 | |
| 109 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 110 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 111 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 112 | |
| 113 | // Create and configure function |
| 114 | CLGEMMLowpQuantizeDownInt32ToUint8Scale output_stage; |
| 115 | output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_offset, result_mult_int, result_shift, min, max); |
| 116 | |
| 117 | // Validate valid region input and output |
| 118 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 119 | validate(in.info()->valid_region(), valid_region); |
| 120 | validate(out.info()->valid_region(), valid_region); |
| 121 | |
| 122 | // Validate valid region bias |
| 123 | if(add_bias) |
| 124 | { |
| 125 | const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias); |
| 126 | validate(bias.info()->valid_region(), valid_region_bias); |
| 127 | } |
| 128 | |
| 129 | // Validate padding |
| 130 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 131 | validate(in.info()->padding(), padding); |
| 132 | validate(out.info()->padding(), padding); |
| 133 | |
| 134 | if(add_bias) |
| 135 | { |
| 136 | validate(bias.info()->padding(), padding); |
| 137 | } |
| 138 | } |
| 139 | |
Georgios Pinitas | 45bcc3a | 2017-11-29 11:06:49 +0000 | [diff] [blame^] | 140 | DISABLED_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] | 141 | { |
| 142 | // Validate output |
| 143 | validate(CLAccessor(_target), _reference); |
| 144 | } |
| 145 | |
Georgios Pinitas | 45bcc3a | 2017-11-29 11:06:49 +0000 | [diff] [blame^] | 146 | DISABLED_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] | 147 | { |
| 148 | // Validate output |
| 149 | validate(CLAccessor(_target), _reference); |
| 150 | } |
| 151 | |
| 152 | TEST_SUITE(BoundedReLu) |
Georgios Pinitas | 45bcc3a | 2017-11-29 11:06:49 +0000 | [diff] [blame^] | 153 | DISABLED_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] | 154 | { |
| 155 | // Validate output |
| 156 | validate(CLAccessor(_target), _reference); |
| 157 | } |
| 158 | |
Georgios Pinitas | 45bcc3a | 2017-11-29 11:06:49 +0000 | [diff] [blame^] | 159 | DISABLED_FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), |
| 160 | quantize_down_int32_to_uint8_scale_relu_cases)) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 161 | { |
| 162 | // Validate output |
| 163 | validate(CLAccessor(_target), _reference); |
| 164 | } |
| 165 | TEST_SUITE_END() // BoundedReLu |
| 166 | |
| 167 | TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale |
| 168 | TEST_SUITE_END() // OutputStage |
| 169 | TEST_SUITE_END() // GEMMLowp |
| 170 | TEST_SUITE_END() // CL |
| 171 | } // namespace validation |
| 172 | } // namespace test |
| 173 | } // namespace arm_compute |