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" |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 29 | #include "tests/datasets/ActivationFunctionsDataset.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 30 | #include "tests/framework/DatasetModes.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 31 | #include "tests/framework/Macros.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 32 | #include "tests/framework/TestCase.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 35 | |
| 36 | #include "tests/datasets/LargeMatMulDataset.h" |
| 37 | #include "tests/datasets/SmallMatMulDataset.h" |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 38 | #include "tests/validation/fixtures/MatMulFixture.h" |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | namespace |
| 47 | { |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 48 | RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for fp32 data type */ |
| 49 | constexpr float abs_tolerance_f32( |
| 50 | 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 */ |
| 51 | constexpr float abs_tolerance_f16( |
| 52 | 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 */ |
| 53 | RelativeTolerance<half_float::half> tolerance_f16(half(0.01)); /**< Tolerance value for comparing reference's output against implementation's output for fp16 data type */ |
| 54 | 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] | 55 | } // namespace |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 56 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 57 | template <typename T> |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 58 | using CLMatMulFixture = MatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
| 59 | |
| 60 | template <typename T> |
| 61 | using CLQuantizedMatMulFixture = QuantizedMatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 62 | |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 63 | template <typename T> |
| 64 | using CLMatMulActivationFixture = MatMulValidationWithActivationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
| 65 | |
| 66 | template <typename T> |
| 67 | using CLMatMulActivationAlphaBetaFixture = MatMulValidationWithActivationAlphaBetaFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
| 68 | |
| 69 | template <typename T> |
| 70 | using CLQuantizedMatMulActivationFixture = QuantizedMatMulValidationWithActivationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>; |
| 71 | |
| 72 | /* The main act functions matmul is expected to support */ |
| 73 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 74 | { |
| 75 | ActivationLayerInfo(), |
| 76 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 77 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f), |
| 78 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f), |
| 79 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH) |
| 80 | }); |
| 81 | |
| 82 | const auto ActivationFunctionsQuantizedDataset = concat(concat(concat( |
| 83 | framework::dataset::make("ActivationInfo", ActivationLayerInfo()), |
| 84 | framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))), |
| 85 | framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f))), |
| 86 | framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f))); |
| 87 | |
| 88 | /* Larger activation functions dataset, used during some nightly tests. */ |
| 89 | const auto AllActivationsDataset = combine(datasets::ActivationFunctions(), framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
| 90 | |
| 91 | const auto AllQuantizedActivationsDataset = combine(concat(datasets::ActivationFunctionsQuantized(), |
| 92 | framework::dataset::make("ActivationFunction", { ActivationLayerInfo::ActivationFunction::HARD_SWISH, |
| 93 | ActivationLayerInfo::ActivationFunction::LEAKY_RELU |
| 94 | })), |
| 95 | framework::dataset::make("AlphaBeta", { 0.5f, 1.f })); |
| 96 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 97 | TEST_SUITE(CL) |
| 98 | TEST_SUITE(MatMul) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 99 | |
| 100 | TEST_SUITE(Float) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 101 | TEST_SUITE(FP32) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 102 | |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 103 | FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulActivationFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallMatMulDataset(), |
| 104 | framework::dataset::make("TransposeA", { false, true })), |
| 105 | framework::dataset::make("TransposeB", { false, true })), |
| 106 | framework::dataset::make("DataType", DataType::F32)), |
| 107 | ActivationFunctionsDataset)) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 108 | { |
| 109 | // Validate output |
| 110 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
| 111 | } |
| 112 | |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 113 | FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulActivationFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(), |
| 114 | framework::dataset::make("TransposeA", { false, true })), |
| 115 | framework::dataset::make("TransposeB", { false, true })), |
| 116 | framework::dataset::make("DataType", DataType::F32)), |
| 117 | ActivationFunctionsDataset)) |
| 118 | { |
| 119 | // Validate output |
| 120 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
| 121 | } |
| 122 | |
| 123 | FIXTURE_DATA_TEST_CASE(RunAllActivations, CLMatMulActivationAlphaBetaFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SmallerMatMulDataset(), |
| 124 | framework::dataset::make("TransposeA", { false })), |
| 125 | framework::dataset::make("TransposeB", { true })), |
| 126 | framework::dataset::make("DataType", DataType::F32)), |
| 127 | AllActivationsDataset)) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 128 | { |
| 129 | // Validate output |
Ramy Elgammal | dcab9ca | 2023-04-04 14:41:10 +0100 | [diff] [blame] | 130 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 131 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 132 | |
| 133 | TEST_SUITE_END() // FP32 |
| 134 | |
| 135 | TEST_SUITE(FP16) |
| 136 | |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 137 | FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulActivationFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallMatMulDataset(), |
| 138 | framework::dataset::make("TransposeA", { false, true })), |
| 139 | framework::dataset::make("TransposeB", { false, true })), |
| 140 | framework::dataset::make("DataType", DataType::F16)), |
| 141 | ActivationFunctionsDataset)) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 142 | { |
| 143 | // Validate output |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 144 | validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 145 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 146 | |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 147 | FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulActivationFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(), |
| 148 | framework::dataset::make("TransposeA", { false, true })), |
| 149 | framework::dataset::make("TransposeB", { false, true })), |
| 150 | framework::dataset::make("DataType", DataType::F16)), |
| 151 | ActivationFunctionsDataset)) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 152 | { |
| 153 | // Validate output |
Ramy Elgammal | dcab9ca | 2023-04-04 14:41:10 +0100 | [diff] [blame] | 154 | validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 155 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 156 | |
| 157 | TEST_SUITE_END() // FP16 |
| 158 | TEST_SUITE_END() // Float |
| 159 | |
| 160 | TEST_SUITE(Quantized) |
| 161 | TEST_SUITE(QASYMM8) |
| 162 | |
| 163 | FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine( |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 164 | datasets::SmallMatMulDataset(), |
| 165 | framework::dataset::make("TransposeA", { false, true })), |
| 166 | framework::dataset::make("TransposeB", { false, true })), |
| 167 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 168 | ActivationFunctionsQuantizedDataset), |
| 169 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 170 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })), |
| 171 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })), |
| 172 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))) |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 173 | { |
| 174 | // Validate output |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 175 | validate(CLAccessor(_target), _reference, tolerance_quant); |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 176 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 177 | |
| 178 | FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine( |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 179 | datasets::LargeMatMulDataset(), |
| 180 | framework::dataset::make("TransposeA", { false, true })), |
| 181 | framework::dataset::make("TransposeB", { false, true })), |
| 182 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 183 | ActivationFunctionsQuantizedDataset), |
| 184 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 185 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })), |
| 186 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })), |
| 187 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 188 | { |
| 189 | // Validate output |
| 190 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 191 | } |
| 192 | |
| 193 | TEST_SUITE_END() // QASYMM8 |
| 194 | |
| 195 | TEST_SUITE(QASYMM8_SIGNED) |
| 196 | |
| 197 | FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine( |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 198 | datasets::SmallMatMulDataset(), |
| 199 | framework::dataset::make("TransposeA", { false, true })), |
| 200 | framework::dataset::make("TransposeB", { false, true })), |
| 201 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 202 | ActivationFunctionsQuantizedDataset), |
| 203 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 204 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })), |
| 205 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })), |
| 206 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 207 | { |
| 208 | // Validate output |
| 209 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 210 | } |
| 211 | |
| 212 | FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine( |
Mohammed Suhail Munshi | 94abde4 | 2023-05-25 16:48:43 +0100 | [diff] [blame] | 213 | datasets::LargeMatMulDataset(), |
| 214 | framework::dataset::make("TransposeA", { false, true })), |
| 215 | framework::dataset::make("TransposeB", { false, true })), |
| 216 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 217 | ActivationFunctionsQuantizedDataset), |
| 218 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 219 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })), |
| 220 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })), |
| 221 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))) |
| 222 | { |
| 223 | // Validate output |
| 224 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 225 | } |
| 226 | |
| 227 | FIXTURE_DATA_TEST_CASE(RunAllActivations, CLQuantizedMatMulActivationFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine( |
| 228 | datasets::LargeMatMulDataset(), |
| 229 | framework::dataset::make("TransposeA", { false })), |
| 230 | framework::dataset::make("TransposeB", { true })), |
| 231 | framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 232 | AllQuantizedActivationsDataset), |
| 233 | framework::dataset::make("NumberOfExtraRuns", { 0, 1 })), |
| 234 | framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })), |
| 235 | framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })), |
| 236 | framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))) |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 237 | { |
| 238 | // Validate output |
| 239 | validate(CLAccessor(_target), _reference, tolerance_quant); |
| 240 | } |
| 241 | |
| 242 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 243 | |
| 244 | TEST_SUITE_END() // Quantized |
| 245 | |
Ramy Elgammal | f26ea2f | 2023-03-24 11:42:03 +0000 | [diff] [blame] | 246 | TEST_SUITE_END() // MatMul |
| 247 | TEST_SUITE_END() // CL |
| 248 | } // namespace validation |
| 249 | } // namespace test |
| 250 | } // namespace arm_compute |