| 1 | // |
| 2 | // SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | // |
| 4 | // SPDX-License-Identifier: Apache-2.0 |
| 5 | // |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | #include <array> |
| 10 | #include <cstddef> |
| 11 | #include <ostream> |
| 12 | #include <sstream> |
| 13 | #include <string> |
| 14 | #include <tuple> |
| 15 | #include <utility> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "kai/kai_common.h" |
| 19 | #include "kai/ukernels/matmul/matmul_clamp_f32_qai8dxp_qsu2cxp/kai_matmul_clamp_f32_qai8dxp1vlx4_qsu2cxp4vlx4_1vlx4vl_sme2_mopa.h" |
| 20 | #include "kai/ukernels/matmul/matmul_clamp_f32_qai8dxp_qsu2cxp/kai_matmul_clamp_f32_qai8dxp1x4_qsu2cxp4vlx4_1x4vl_sme2_dot.h" |
| 21 | #include "kai/ukernels/matmul/matmul_clamp_f32_qai8dxp_qsu2cxp/kai_matmul_clamp_f32_qai8dxp1x4_qsu2cxp4x4bf32sf32_1x4_neon_dotprod.h" |
| 22 | #include "kai/ukernels/matmul/matmul_clamp_f32_qai8dxp_qsu2cxp/kai_matmul_clamp_f32_qai8dxp4x4_qsu2cxp4x4bf32sf32_8x4_neon_dotprod.h" |
| 23 | #include "kai/ukernels/matmul/matmul_clamp_f32_qai8dxp_qsu2cxp/kai_matmul_clamp_f32_qai8dxp_qsu2cxp_interface.h" |
| 24 | #include "kai/ukernels/matmul/pack/kai_lhs_quant_pack_qai8dxp_f32.h" |
| 25 | #include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon.h" |
| 26 | #include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_qsu2cxp4x4bf32sf32_qsu2cx_neon.h" |
| 27 | #include "test/common/abi_checker.hpp" |
| 28 | #include "test/common/buffer.hpp" |
| 29 | #include "test/common/cache.hpp" |
| 30 | #include "test/common/compare.hpp" |
| 31 | #include "test/common/cpu_info.hpp" |
| 32 | #include "test/common/data_type.hpp" |
| 33 | #include "test/common/int2.hpp" |
| 34 | #include "test/common/matmul_test_common.hpp" |
| 35 | #include "test/common/matrix_portion.hpp" |
| 36 | #include "test/common/memory.hpp" |
| 37 | #include "test/common/round.hpp" |
| 38 | #include "test/common/test_suite.hpp" |
| 39 | #include "test/reference/cast.hpp" |
| 40 | #include "test/reference/clamp.hpp" |
| 41 | #include "test/reference/fill.hpp" |
| 42 | #include "test/reference/matmul.hpp" |
| 43 | #include "test/reference/pad.hpp" |
| 44 | #include "test/reference/quantize.hpp" |
| 45 | #include "test/reference/transpose.hpp" |
| 46 | |
| 47 | namespace kai::test { |
| 48 | /// Matrix multiplication test information. |
| 49 | namespace { |
| 50 | |
| 51 | using kai_get_lhs_packed_size_func_t = decltype(&kai_get_lhs_packed_size_lhs_quant_pack_qai8dxp_f32); |
| 52 | using kai_get_lhs_packed_offset_func_t = decltype(&kai_get_lhs_packed_offset_lhs_quant_pack_qai8dxp_f32); |
| 53 | using kai_get_lhs_offset_func_t = decltype(&kai_get_lhs_offset_lhs_quant_pack_qai8dxp_f32); |
| 54 | using kai_run_lhs_pack_func_t = decltype(&kai_run_lhs_quant_pack_qai8dxp_f32); |
| 55 | |
| 56 | struct kai_qai8dxp_pack_functions { |
| 57 | kai_get_lhs_packed_size_func_t packed_size; |
| 58 | kai_get_lhs_packed_offset_func_t get_packed_offset; |
| 59 | kai_get_lhs_offset_func_t get_offset; |
| 60 | kai_run_lhs_pack_func_t run_pack; |
| 61 | }; |
| 62 | |
| 63 | using kai_get_rhs_packed_size_func_t = decltype(&kai_get_rhs_packed_size_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon); |
| 64 | using kai_get_rhs_packed_offset_func_t = decltype(&kai_get_rhs_packed_offset_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon); |
| 65 | using kai_get_rhs_offset_func_t = decltype(&kai_get_rhs_offset_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon); |
| 66 | using kai_run_rhs_pack_func_t = decltype(&kai_run_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon); |
| 67 | |
| 68 | struct kai_qsu2cxp_pack_functions { |
| 69 | kai_get_rhs_packed_size_func_t packed_size; |
| 70 | kai_get_rhs_packed_offset_func_t get_packed_offset; |
| 71 | kai_get_rhs_offset_func_t get_offset; |
| 72 | kai_run_rhs_pack_func_t run_pack; |
| 73 | }; |
| 74 | |
| 75 | const auto& get_qsi2cx_gemm_variants() noexcept { |
| 76 | using Variant = UkernelMatmulPackVariant< |
| 77 | kai_matmul_clamp_f32_qai8dxp_qsu2cxp_ukernel, kai_qai8dxp_pack_functions, kai_qsu2cxp_pack_functions>; |
| 78 | static const std::array<Variant, 2> variants = {{ |
| 79 | UKERNEL_MATMUL_PACK_VARIANT_NAME( |
| 80 | clamp_f32_qai8dxp1vlx4_qsu2cxp4vlx4_1vlx4vl_sme2_mopa__RHS_NxK__, |
| 81 | clamp_f32_qai8dxp1vlx4_qsu2cxp4vlx4_1vlx4vl_sme2_mopa, cpu_has_sme2, lhs_quant_pack_qai8dxp_f32, |
| 82 | rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon, false), |
| 83 | UKERNEL_MATMUL_PACK_VARIANT_NAME( |
| 84 | clamp_f32_qai8dxp4x4_qsu2cxp4x4bf32sf32_8x4_neon_dotprod__RHS_NxK__, |
| 85 | clamp_f32_qai8dxp4x4_qsu2cxp4x4bf32sf32_8x4_neon_dotprod, cpu_has_dotprod, lhs_quant_pack_qai8dxp_f32, |
| 86 | rhs_pack_nxk_qsu2cxp4x4bf32sf32_qsu2cx_neon, false), |
| 87 | }}; |
| 88 | return variants; |
| 89 | } |
| 90 | |
| 91 | const auto& get_qsi2cx_gemv_variants() noexcept { |
| 92 | using Variant = UkernelMatmulPackVariant< |
| 93 | kai_matmul_clamp_f32_qai8dxp_qsu2cxp_ukernel, kai_qai8dxp_pack_functions, kai_qsu2cxp_pack_functions>; |
| 94 | static const std::array<Variant, 2> variants = {{ |
| 95 | UKERNEL_MATMUL_PACK_VARIANT_NAME( |
| 96 | clamp_f32_qai8dxp1x4_qsu2cxp4vlx4_1x4vl_sme2_dot__RHS_NxK__, |
| 97 | clamp_f32_qai8dxp1x4_qsu2cxp4vlx4_1x4vl_sme2_dot, cpu_has_sme2, lhs_quant_pack_qai8dxp_f32, |
| 98 | rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon, false), |
| 99 | UKERNEL_MATMUL_PACK_VARIANT_NAME( |
| 100 | clamp_f32_qai8dxp1x4_qsu2cxp4x4bf32sf32_1x4_neon_dotprod__RHS_NxK__, |
| 101 | clamp_f32_qai8dxp1x4_qsu2cxp4x4bf32sf32_1x4_neon_dotprod, cpu_has_dotprod, lhs_quant_pack_qai8dxp_f32, |
| 102 | rhs_pack_nxk_qsu2cxp4x4bf32sf32_qsu2cx_neon, false), |
| 103 | }}; |
| 104 | return variants; |
| 105 | } |
| 106 | |
| 107 | std::tuple<Buffer, size_t> pack_lhs_qai8dxp( |
| 108 | const kai_qai8dxp_pack_functions& pack_interface, |
| 109 | // clang-format off |
| 110 | const size_t M, |
| 111 | const size_t K, |
| 112 | const size_t mr, |
| 113 | const size_t kr, |
| 114 | const size_t sr, |
| 115 | const Buffer& lhs_values_f32, |
| 116 | const size_t lhs_stride_bytes, |
| 117 | const size_t rect_start_row, |
| 118 | const size_t rect_height) { |
| 119 | |
| 120 | const auto lhs_packed_size = pack_interface.packed_size(M, K, mr, kr, sr); |
| 121 | Buffer lhs_packed(lhs_packed_size, 0); |
| 122 | |
| 123 | auto lhs_offset = pack_interface.get_offset(rect_start_row, lhs_stride_bytes); |
| 124 | auto lhs_packed_offset = pack_interface.get_packed_offset(rect_start_row, K, mr, kr, sr); |
| 125 | |
| 126 | abi_check( |
| 127 | pack_interface.run_pack, |
| 128 | rect_height/* m */, K, mr, kr, sr, 0 /* m_idx_start*/, |
| 129 | reinterpret_cast<const float*>(lhs_values_f32.data() + lhs_offset), lhs_stride_bytes, |
| 130 | lhs_packed.data() + lhs_packed_offset); |
| 131 | |
| 132 | return {std::move(lhs_packed), lhs_packed_offset}; |
| 133 | } |
| 134 | |
| 135 | std::tuple<Buffer, size_t> pack_rhs_qsu2cxp( |
| 136 | const kai_qsu2cxp_pack_functions& pack_interface, |
| 137 | // clang-format off |
| 138 | const size_t N, |
| 139 | const size_t K, |
| 140 | const size_t nr, |
| 141 | const size_t kr, |
| 142 | const size_t sr, |
| 143 | const bool has_bias, |
| 144 | const Buffer& rhs_values_qsi2, |
| 145 | const Buffer& biases, |
| 146 | const size_t bias_offset, |
| 147 | const Buffer& rhs_scales, |
| 148 | const size_t rect_start_row, |
| 149 | const size_t rect_width, |
| 150 | const int32_t* lut) { |
| 151 | // clang-format on |
| 152 | |
| 153 | const size_t num_bytes_recip_qvalue_rhs = 4; |
| 154 | |
| 155 | const size_t rhs_stride = round_up_multiple(K, num_bytes_recip_qvalue_rhs); |
| 156 | const size_t rhs_stride_bytes = round_up_division(K, num_bytes_recip_qvalue_rhs); |
| 157 | const size_t scales_stride_bytes = sizeof(float); |
| 158 | |
| 159 | const auto rhs_values_qsu2 = cast_u2_i2(rhs_values_qsi2.data(), N * K); |
| 160 | const size_t dst_bytes_total = round_up_division(N * rhs_stride, num_bytes_recip_qvalue_rhs); |
| 161 | const auto rhs_qsu2 = pad_row<UInt2>(rhs_values_qsu2.data(), N, K, K, rhs_stride, dst_bytes_total); |
| 162 | |
| 163 | const size_t scale_offset = rect_start_row * scales_stride_bytes; |
| 164 | size_t rhs_offset = 0; |
| 165 | size_t rhs_packed_offset = 0; |
| 166 | size_t imp_packed_rhs_size = 0; |
| 167 | |
| 168 | rhs_offset = pack_interface.get_offset(rect_start_row, rhs_stride_bytes); |
| 169 | rhs_packed_offset = pack_interface.get_packed_offset(rect_start_row, K, nr, kr, sr); |
| 170 | imp_packed_rhs_size = pack_interface.packed_size(N, K, nr, kr, sr); |
| 171 | |
| 172 | Buffer imp_packed_rhs(imp_packed_rhs_size); |
| 173 | kai_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon_params params{}; |
| 174 | params.lhs_zero_point = 1; |
| 175 | params.rhs_zero_point = 2; |
| 176 | |
| 177 | abi_check( |
| 178 | // clang-format off |
| 179 | pack_interface.run_pack, |
| 180 | 1, |
| 181 | rect_width, /* n */ |
| 182 | K, |
| 183 | nr, kr, sr, |
| 184 | reinterpret_cast<const uint8_t*>(rhs_qsu2.data() + rhs_offset), |
| 185 | has_bias ? reinterpret_cast<const float*>(biases.data() + bias_offset) : nullptr, |
| 186 | reinterpret_cast<const float*>(rhs_scales.data() + scale_offset), |
| 187 | static_cast<void*>(imp_packed_rhs.data() + rhs_packed_offset), |
| 188 | 0, |
| 189 | ¶ms, |
| 190 | lut |
| 191 | ); |
| 192 | // clang-format on |
| 193 | |
| 194 | return {std::move(imp_packed_rhs), rhs_packed_offset}; |
| 195 | } |
| 196 | |
| 197 | } // namespace |
| 198 | |
| 199 | /// Cached test data that is shared between multiple test case. |
| 200 | using TestDataKey = std::tuple< |
| 201 | MatMulShape, // shape |
| 202 | bool, // has_bias |
| 203 | size_t, // mr |
| 204 | size_t, // nr |
| 205 | size_t, // kr |
| 206 | size_t, // sr |
| 207 | size_t, size_t, size_t, size_t, // rect.start_row, rect.start_col, rect.height, rect.width |
| 208 | std::optional<float> // clamp_keep_ratio |
| 209 | >; |
| 210 | |
| 211 | struct TestData { |
| 212 | size_t M{}, N{}, K{}; |
| 213 | |
| 214 | Rect rect{0, 0, 0, 0}; |
| 215 | |
| 216 | Buffer lhs; |
| 217 | Buffer rhs; |
| 218 | Buffer bias; |
| 219 | |
| 220 | Buffer rhs_quant; |
| 221 | Buffer rhs_scales; |
| 222 | |
| 223 | Buffer ref_dst_clamped; |
| 224 | Range<float> clamp; |
| 225 | }; |
| 226 | |
| 227 | template <> |
| 228 | TestData ReferenceGenerator<TestDataKey, TestData>::generate_reference(const TestDataKey& test_id) { |
| 229 | TestData ref{}; |
| 230 | |
| 231 | const auto& [shape, has_bias, mr, kr, nr, sr, rect_start_row, rect_start_col, rect_height, rect_width, clamp_keep_ratio] = |
| 232 | test_id; |
| 233 | |
| 234 | ref.M = shape.m; |
| 235 | ref.N = shape.n; |
| 236 | ref.K = shape.k; |
| 237 | ref.rect = Rect(rect_start_row, rect_start_col, rect_height, rect_width); |
| 238 | |
| 239 | // Creates a unique seed for the test data. |
| 240 | const auto key = std::string("QSI2CXMatMulRefKey:") + std::to_string(ref.M) + "x" + std::to_string(ref.N) + "x" + |
| 241 | std::to_string(ref.K) + "_" + |
| 242 | (clamp_keep_ratio.has_value() ? std::to_string(clamp_keep_ratio.value()) : "noclamp"); |
| 243 | auto& feed = seed_stream(key); |
| 244 | |
| 245 | // Inputs |
| 246 | ref.lhs = fill_random<float>(ref.M * ref.K, feed()); |
| 247 | ref.rhs = fill_random<float>(ref.N * ref.K, feed()); |
| 248 | ref.bias = has_bias ? fill_random<float>(ref.N, feed()) : Buffer(); |
| 249 | |
| 250 | // Reference quantizations for LHS and RHS |
| 251 | QuantizationInfo lhs_qinfo{}; |
| 252 | lhs_qinfo.quant_width = ref.K; |
| 253 | lhs_qinfo.dst_type = DataType::QAI8; |
| 254 | lhs_qinfo.scale_type = DataType::FP32; |
| 255 | lhs_qinfo.zero_point_type = DataType::I32; |
| 256 | auto [ref_lhs_quant, lhs_qoutputs] = quantize_dynamic(ref.lhs.data(), DataType::FP32, ref.M, ref.K, lhs_qinfo); |
| 257 | |
| 258 | QuantizationInfo rhs_qinfo{}; |
| 259 | rhs_qinfo.quant_width = ref.K; |
| 260 | rhs_qinfo.dst_type = DataType::QSI2; |
| 261 | rhs_qinfo.scale_type = DataType::FP32; |
| 262 | auto [ref_rhs_quant, rhs_qoutputs] = quantize_dynamic(ref.rhs.data(), DataType::FP32, ref.N, ref.K, rhs_qinfo); |
| 263 | |
| 264 | ref.rhs_quant = std::move(ref_rhs_quant); |
| 265 | ref.rhs_scales = std::move(rhs_qoutputs.scales); |
| 266 | |
| 267 | const auto ref_dst_no_clamp = |
| 268 | matmul_nt_t_quantized<int8_t, float, int32_t, Int2, float, int32_t, float, float, int32_t, float>( |
| 269 | ref.M, ref.N, ref.K, ref_lhs_quant.data(), lhs_qoutputs.scales.data(), lhs_qoutputs.zero_points.data(), 1, |
| 270 | ref.K, ref.rhs_quant.data(), ref.rhs_scales.data(), nullptr, 1, ref.K, has_bias ? ref.bias.data() : nullptr, |
| 271 | nullptr, nullptr, 1); |
| 272 | |
| 273 | const auto [clamp_min, clamp_max] = |
| 274 | find_clamp_range(DataType::FP32, ref_dst_no_clamp.data(), ref.M * ref.N, clamp_keep_ratio); |
| 275 | |
| 276 | ref.clamp = {clamp_min, clamp_max}; |
| 277 | ref.ref_dst_clamped = clamp<float>(ref_dst_no_clamp.data(), ref.M * ref.N, clamp_min, clamp_max); |
| 278 | |
| 279 | return ref; |
| 280 | } |
| 281 | |
| 282 | static std::string test_description( |
| 283 | const std::string_view& name, const MatMulShape& shape, const MatrixPortion& portion, bool bias, |
| 284 | std::optional<float> clamp_keep_ratio, bool lut) { |
| 285 | std::ostringstream os; |
| 286 | |
| 287 | os << name << "__"; |
| 288 | PrintTo(shape, &os); |
| 289 | os << "__"; |
| 290 | PrintTo(portion, &os); |
| 291 | if (bias) { |
| 292 | os << "__Bias"; |
| 293 | } |
| 294 | os << "__clamp_keep_ratio_" |
| 295 | << (clamp_keep_ratio.has_value() ? std::to_string(static_cast<int>(clamp_keep_ratio.value() * 100)) : "noclamp"); |
| 296 | if (lut) { |
| 297 | os << "__Lut"; |
| 298 | } |
| 299 | return os.str(); |
| 300 | } |
| 301 | |
| 302 | using QMatmulClampF32ParamT = std::tuple<size_t, bool, MatMulShape, MatrixPortion, std::optional<float>, bool, bool>; |
| 303 | |
| 304 | class MatMulTest_f32_qai8dxp_qsu2cxp : public ::testing::TestWithParam<QMatmulClampF32ParamT> {}; |
| 305 | |
| 306 | TEST_P(MatMulTest_f32_qai8dxp_qsu2cxp, EndToEnd) { |
| 307 | const auto& [variant_index, is_gemm, matmul_shape, portion, clamp_keep_ratio, has_bias, has_lut] = GetParam(); |
| 308 | const auto& variant = |
| 309 | is_gemm ? get_qsi2cx_gemm_variants().at(variant_index) : get_qsi2cx_gemv_variants().at(variant_index); |
| 310 | |
| 311 | if (variant.ukernel.fn_is_supported && !variant.ukernel.fn_is_supported()) { |
| 312 | GTEST_SKIP() << "Unsupported CPU feature"; |
| 313 | } |
| 314 | |
| 315 | const size_t M = matmul_shape.m; |
| 316 | const size_t N = matmul_shape.n; |
| 317 | const size_t K = matmul_shape.k; |
| 318 | |
| 319 | const auto mr = variant.ukernel.interface.get_mr(); |
| 320 | const auto nr = variant.ukernel.interface.get_nr(); |
| 321 | const auto kr = variant.ukernel.interface.get_kr(); |
| 322 | const auto sr = variant.ukernel.interface.get_sr(); |
| 323 | |
| 324 | const auto m_step = variant.ukernel.interface.get_m_step(); |
| 325 | ASSERT_TRUE(m_step % mr == 0); |
| 326 | |
| 327 | const auto n_step = variant.ukernel.interface.get_n_step(); |
| 328 | ASSERT_TRUE(n_step % nr == 0); |
| 329 | |
| 330 | const auto rect = portion.compute_portion(M, N, m_step, n_step); |
| 331 | ASSERT_GT(rect.height(), 0U); |
| 332 | ASSERT_GT(rect.width(), 0U); |
| 333 | |
| 334 | const int32_t lut[4] = {-2, -1, 0, 1}; |
| 335 | |
| 336 | // Cached reference and inputs |
| 337 | const TestDataKey key{ |
| 338 | matmul_shape, has_bias, mr, nr, kr, sr, rect.start_row(), rect.start_col(), rect.height(), |
| 339 | rect.width(), clamp_keep_ratio}; |
| 340 | const TestData& data = getV<TestDataKey, TestData>(key); |
| 341 | |
| 342 | // Runs the LHS packing micro-kernel. |
| 343 | const auto lhs_start_row = rect.start_row(); |
| 344 | const size_t lhs_stride_bytes = K * sizeof(float); |
| 345 | |
| 346 | auto [imp_packed_lhs, lhs_packed_offset] = pack_lhs_qai8dxp( |
| 347 | variant.lhs_pack_interface, M, K, mr, kr, sr, data.lhs, lhs_stride_bytes, rect.start_row(), rect.height()); |
| 348 | |
| 349 | auto lhs_matmul_offset = variant.ukernel.interface.get_lhs_packed_offset(lhs_start_row, K); |
| 350 | ASSERT_EQ(lhs_packed_offset, lhs_matmul_offset); |
| 351 | |
| 352 | // Runs the RHS packing micro-kernel. |
| 353 | const auto rhs_start_row = rect.start_col(); |
| 354 | size_t bias_offset = rhs_start_row * sizeof(float); |
| 355 | auto [imp_packed_rhs, rhs_packed_offset] = pack_rhs_qsu2cxp( |
| 356 | variant.rhs_pack_interface, N, K, nr, kr, sr, has_bias, data.rhs_quant, data.bias, bias_offset, data.rhs_scales, |
| 357 | rhs_start_row, rect.width(), has_lut ? lut : nullptr); |
| 358 | auto rhs_matmul_offset = variant.ukernel.interface.get_rhs_packed_offset(rhs_start_row, K); |
| 359 | ASSERT_EQ(rhs_packed_offset, rhs_matmul_offset); |
| 360 | |
| 361 | // Runs the GEMM micro-kernel. |
| 362 | const auto dst_stride = N * sizeof(float); |
| 363 | const auto dst_offset = variant.ukernel.interface.get_dst_offset(rect.start_row(), rect.start_col(), dst_stride); |
| 364 | const auto ref_dst_offset = rect.start_row() * dst_stride + rect.start_col() * sizeof(float); |
| 365 | ASSERT_EQ(dst_offset, ref_dst_offset); |
| 366 | |
| 367 | const auto imp_dst_size = variant.ukernel.interface.get_dst_size(M, N); |
| 368 | ASSERT_EQ(imp_dst_size, data.ref_dst_clamped.size()); |
| 369 | Buffer imp_dst(imp_dst_size); |
| 370 | abi_check( |
| 371 | variant.ukernel.interface.run_matmul, rect.height(), rect.width(), K, imp_packed_lhs.data() + lhs_matmul_offset, |
| 372 | imp_packed_rhs.data() + rhs_matmul_offset, reinterpret_cast<float*>(imp_dst.data() + dst_offset), |
| 373 | N * sizeof(float), sizeof(float), data.clamp.min, data.clamp.max, has_lut ? lut : nullptr); |
| 374 | |
| 375 | DefaultMismatchHandler handler(0, 0.02, 0, 0.05); |
| 376 | auto dst_format = DataFormat(DataType::FP32); |
| 377 | const auto success = compare(imp_dst.data(), data.ref_dst_clamped.data(), dst_format, M, N, rect, handler); |
| 378 | ASSERT_TRUE(success); |
| 379 | } |
| 380 | |
| 381 | INSTANTIATE_TEST_SUITE_P( |
| 382 | MatMulGemm, MatMulTest_f32_qai8dxp_qsu2cxp, |
| 383 | testing::Combine( |
| 384 | testing::Range<size_t>(0, get_qsi2cx_gemm_variants().size()), testing::Values(true), |
| 385 | testing::Values( |
| 386 | MatMulShape{8, 4, 32}, // |
| 387 | MatMulShape{16, 8, 64}, // |
| 388 | MatMulShape{7, 3, 32}, // |
| 389 | MatMulShape{9, 5, 32}, // |
| 390 | MatMulShape{5, 5, 32}, // |
| 391 | MatMulShape{3, 3, 32}, // |
| 392 | MatMulShape{4, 4, 32}, // |
| 393 | MatMulShape{16, 32, 64}, // |
| 394 | MatMulShape{15, 63, 32}, // |
| 395 | MatMulShape{17, 65, 32}, // |
| 396 | MatMulShape{32, 128, 64}, // |
| 397 | MatMulShape{15, 31, 64}, // |
| 398 | MatMulShape{19, 129, 64}, // |
| 399 | MatMulShape{1, 128, 32}), |
| 400 | testing::Values( |
| 401 | MatrixPortion(0, 0, 1, 1), // Full matrix. |
| 402 | MatrixPortion(0, 0, 1, 0.25), // Leftmost portion. |
| 403 | MatrixPortion(0, 0.75, 1, 1), // Rightmost portion. |
| 404 | MatrixPortion(0.4, 0.5, 0.6, 0.8)), // Somewhere Middle block |
| 405 | testing::ValuesIn(std::initializer_list<std::optional<float>>{ |
| 406 | std::nullopt, // Disable clamping |
| 407 | 1.0f, // Clamp to full range |
| 408 | 0.9f, // Clamp to 90% range |
| 409 | 0.5f}), // Clamp to 50% range |
| 410 | testing::Bool(), // Bias |
| 411 | testing::Bool()), // Look up table argument |
| 412 | [](const auto& info) { |
| 413 | const auto variant_idx = std::get<0>(info.param); |
| 414 | const std::string name{get_qsi2cx_gemm_variants().at(variant_idx).ukernel.name}; |
| 415 | const auto shape = std::get<MatMulShape>(info.param); |
| 416 | const auto portion = std::get<3>(info.param); |
| 417 | const auto clamp_keep_ratio = std::get<4>(info.param); |
| 418 | const auto has_bias = std::get<5>(info.param); |
| 419 | const auto has_lut = std::get<6>(info.param); |
| 420 | |
| 421 | return test_description(name, shape, portion, has_bias, clamp_keep_ratio, has_lut); |
| 422 | }); |
| 423 | |
| 424 | INSTANTIATE_TEST_SUITE_P( |
| 425 | MatMulGemv, MatMulTest_f32_qai8dxp_qsu2cxp, |
| 426 | testing::Combine( |
| 427 | testing::Range<size_t>(0, get_qsi2cx_gemv_variants().size()), testing::Values(false), |
| 428 | testing::Values( |
| 429 | MatMulShape{1, 4, 32}, // |
| 430 | MatMulShape{1, 8, 64}, // |
| 431 | MatMulShape{1, 3, 32}, // |
| 432 | MatMulShape{1, 5, 32}, // |
| 433 | MatMulShape{1, 63, 32}, // |
| 434 | MatMulShape{1, 64, 32}, // |
| 435 | MatMulShape{1, 65, 32}, // |
| 436 | MatMulShape{1, 71, 32}, // |
| 437 | MatMulShape{1, 128, 64}, // |
| 438 | MatMulShape{1, 225, 64}), |
| 439 | testing::Values( |
| 440 | MatrixPortion(0, 0, 1, 1), // Full matrix. |
| 441 | MatrixPortion(0, 0, 1, 0.25), // Leftmost portion. |
| 442 | MatrixPortion(0, 0.75, 1, 1), // Rightmost portion. |
| 443 | MatrixPortion(0.4, 0.5, 0.6, 0.8)), // Somewhere Middle block |
| 444 | testing::ValuesIn(std::initializer_list<std::optional<float>>{ |
| 445 | std::nullopt, // Disable clamping |
| 446 | 1.0f, // Clamp to full range |
| 447 | 0.9f, // Clamp to 90% range |
| 448 | 0.5f}), // Clamp to 50% range |
| 449 | testing::Bool(), // Bias |
| 450 | testing::Bool()), // Look up table argument |
| 451 | [](const auto& info) { |
| 452 | const auto variant_idx = std::get<0>(info.param); |
| 453 | const std::string name{get_qsi2cx_gemv_variants().at(variant_idx).ukernel.name}; |
| 454 | const auto shape = std::get<MatMulShape>(info.param); |
| 455 | const auto portion = std::get<3>(info.param); |
| 456 | const auto clamp_keep_ratio = std::get<4>(info.param); |
| 457 | const auto has_bias = std::get<5>(info.param); |
| 458 | const auto has_lut = std::get<6>(info.param); |
| 459 | |
| 460 | return test_description(name, shape, portion, has_bias, clamp_keep_ratio, has_lut); |
| 461 | }); |
| 462 | } // namespace kai::test |