Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 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 | */ |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 24 | #include "arm_compute/core/Types.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/functions/CLMatMul.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 27 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 29 | #include "tests/framework/DatasetModes.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 30 | #include "tests/framework/Macros.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 31 | #include "tests/framework/TestCase.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 32 | #include "tests/framework/datasets/Datasets.h" |
| 33 | #include "tests/validation/Validation.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 34 | |
| 35 | #include "tests/datasets/LargeMatMulDataset.h" |
| 36 | #include "tests/datasets/SmallMatMulDataset.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 37 | #include "tests/validation/fixtures/MatMulFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 47 | RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for fp32 data type */ |
| 48 | constexpr float abs_tolerance_f32(0.0001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for fp32 data type in case using relative tolerance fails because of small values */ |
| 49 | constexpr float abs_tolerance_f16(0.001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for fp16 data type in case using relative tolerance fails because of small values */ |
| 50 | RelativeTolerance<half_float::half> tolerance_f16(half(0.01)); /**< Tolerance value for comparing reference's output against implementation's output for fp16 data type */ |
| 51 | constexpr AbsoluteTolerance<uint8_t> tolerance_quant(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 52 | } // namespace |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 53 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 54 | template <typename T> |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 55 | using CLMatMulFixture = MatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
| 56 | |
| 57 | template <typename T> |
| 58 | using CLQuantizedMatMulFixture = QuantizedMatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 59 | |
| 60 | TEST_SUITE(CL) |
| 61 | TEST_SUITE(MatMul) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 62 | |
| 63 | TEST_SUITE(Float) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 64 | TEST_SUITE(FP32) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 65 | |
| 66 | FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallMatMulDataset(), |
| 67 | framework::dataset::make("TransposeA", { false, true })), |
| 68 | framework::dataset::make("TransposeB", { false, true })), |
| 69 | framework::dataset::make("DataType", DataType::F32))) |
| 70 | { |
| 71 | // Validate output |
| 72 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
| 73 | } |
| 74 | |
| 75 | FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeMatMulDataset(), |
| 76 | framework::dataset::make("TransposeA", { false, true })), |
| 77 | framework::dataset::make("TransposeB", { false, true })), |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 78 | framework::dataset::make("DataType", DataType::F32))) |
| 79 | { |
| 80 | // Validate output |
Ramy Elgammal | dcab9ca | 2023-04-04 14:41:10 +0100 | [diff] [blame] | 81 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 82 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 83 | |
| 84 | TEST_SUITE_END() // FP32 |
| 85 | |
| 86 | TEST_SUITE(FP16) |
| 87 | |
| 88 | FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallMatMulDataset(), |
| 89 | framework::dataset::make("TransposeA", { false, true })), |
| 90 | framework::dataset::make("TransposeB", { false, true })), |
| 91 | framework::dataset::make("DataType", DataType::F16))) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 92 | { |
| 93 | // Validate output |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 94 | validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 95 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 96 | |
| 97 | FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeMatMulDataset(), |
| 98 | framework::dataset::make("TransposeA", { false, true })), |
| 99 | framework::dataset::make("TransposeB", { false, true })), |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 100 | framework::dataset::make("DataType", DataType::F16))) |
| 101 | { |
| 102 | // Validate output |
Ramy Elgammal | dcab9ca | 2023-04-04 14:41:10 +0100 | [diff] [blame] | 103 | validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 104 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 105 | |
| 106 | TEST_SUITE_END() // FP16 |
| 107 | TEST_SUITE_END() // Float |
| 108 | |
| 109 | TEST_SUITE(Quantized) |
| 110 | TEST_SUITE(QASYMM8) |
| 111 | |
| 112 | FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine( |
| 113 | datasets::SmallMatMulDataset(), |
| 114 | framework::dataset::make("TransposeA", { false, true })), |
| 115 | framework::dataset::make("TransposeB", { false, true })), |
| 116 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 117 | framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })), |
| 118 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 119 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })), |
| 120 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })), |
| 121 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })) |
| 122 | ) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 123 | { |
| 124 | // Validate output |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 125 | validate(CLAccessor(_target), _reference, tolerance_quant); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 126 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 127 | |
| 128 | FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine( |
| 129 | datasets::LargeMatMulDataset(), |
| 130 | framework::dataset::make("TransposeA", { false, true })), |
| 131 | framework::dataset::make("TransposeB", { false, true })), |
| 132 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 133 | framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })), |
| 134 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 135 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })), |
| 136 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })), |
| 137 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })) |
| 138 | ) |
| 139 | { |
| 140 | // Validate output |
| 141 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 142 | } |
| 143 | |
| 144 | TEST_SUITE_END() // QASYMM8 |
| 145 | |
| 146 | TEST_SUITE(QASYMM8_SIGNED) |
| 147 | |
| 148 | FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine( |
| 149 | datasets::SmallMatMulDataset(), |
| 150 | framework::dataset::make("TransposeA", { false, true })), |
| 151 | framework::dataset::make("TransposeB", { false, true })), |
| 152 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 153 | framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })), |
| 154 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 155 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })), |
| 156 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })), |
| 157 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })) |
| 158 | ) |
| 159 | { |
| 160 | // Validate output |
| 161 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 162 | } |
| 163 | |
| 164 | FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine( |
| 165 | datasets::LargeMatMulDataset(), |
| 166 | framework::dataset::make("TransposeA", { false, true })), |
| 167 | framework::dataset::make("TransposeB", { false, true })), |
| 168 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 169 | framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })), |
| 170 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 171 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })), |
| 172 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })), |
| 173 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })) |
| 174 | ) |
| 175 | { |
| 176 | // Validate output |
| 177 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 178 | } |
| 179 | |
| 180 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 181 | |
| 182 | TEST_SUITE_END() // Quantized |
| 183 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 184 | TEST_SUITE_END() // MatMul |
| 185 | TEST_SUITE_END() // CL |
| 186 | } // namespace validation |
| 187 | } // namespace test |
| 188 | } // namespace arm_compute |