From e6794dc16a9c84c48e8ee32f66c383cf108b8677 Mon Sep 17 00:00:00 2001 From: Anton Bondarenko Date: Wed, 7 May 2025 01:07:56 +0200 Subject: [PATCH 1/4] Steamline test functionality * Remove duplicate data types and structures * Cleanup unused headers * Move common CPU feature checkers to cpu_info Signed-off-by: Anton Bondarenko --- test/common/cpu_info.cpp | 8 +++++ test/common/cpu_info.hpp | 8 ++++- test/common/int4.cpp | 1 - test/common/matmul_test_common.hpp | 2 ++ test/common/test_suite.hpp | 35 ------------------- .../matmul_clamp_f16_bf16p_bf16p_test.cpp | 2 -- .../matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp | 18 ++++------ .../matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp | 17 ++++----- ...atmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp | 19 ++++------ .../matmul_clamp_f32_bf16p_bf16p_test.cpp | 1 - test/tests/matmul_clamp_f32_f32_f32p_test.cpp | 15 +++++--- ...matmul_clamp_f32_qai8dxp_qsi4c32p_test.cpp | 17 +++++---- .../matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp | 16 ++++----- .../matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp | 12 +++---- ...atmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp | 15 ++++---- ...atmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp | 17 ++++----- .../matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp | 13 +------ test/tests/matmul_test.cpp | 2 -- 18 files changed, 85 insertions(+), 133 deletions(-) diff --git a/test/common/cpu_info.cpp b/test/common/cpu_info.cpp index 99770295..172a9937 100644 --- a/test/common/cpu_info.cpp +++ b/test/common/cpu_info.cpp @@ -243,10 +243,18 @@ bool cpu_has_dotprod() { return CpuInfo::current().has_dotprod; } +bool cpu_has_dotprod_and_fp16() { + return cpu_has_dotprod() && cpu_has_fp16(); +} + bool cpu_has_i8mm() { return CpuInfo::current().has_i8mm; } +bool cpu_has_i8mm_and_fp16() { + return cpu_has_i8mm() && cpu_has_fp16(); +} + bool cpu_has_fp16() { return CpuInfo::current().has_fp16; } diff --git a/test/common/cpu_info.hpp b/test/common/cpu_info.hpp index 298a358a..e9fe8601 100644 --- a/test/common/cpu_info.hpp +++ b/test/common/cpu_info.hpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 // @@ -14,9 +14,15 @@ bool cpu_has_advsimd(); /// Returns a value indicating whether the current CPU supports FEAT_DotProd. bool cpu_has_dotprod(); +/// Returns a value indicating whether the current CPU supports FEAT_DotProd and FEAT_FP16. +bool cpu_has_dotprod_and_fp16(); + /// Returns a value indicating whether the current CPU supports FEAT_I8MM. bool cpu_has_i8mm(); +/// Returns a value indicating whether the current CPU supports FEAT_I8MM and FEAT_FP16. +bool cpu_has_i8mm_and_fp16(); + /// Returns a value indicating whether the current CPU supports FEAT_FP16. bool cpu_has_fp16(); diff --git a/test/common/int4.cpp b/test/common/int4.cpp index 2dbcd07c..ff64de20 100644 --- a/test/common/int4.cpp +++ b/test/common/int4.cpp @@ -12,7 +12,6 @@ #include "kai/kai_common.h" #include "test/common/memory.hpp" -#include "test/common/round.hpp" namespace kai::test { diff --git a/test/common/matmul_test_common.hpp b/test/common/matmul_test_common.hpp index 030f1787..86ffe615 100644 --- a/test/common/matmul_test_common.hpp +++ b/test/common/matmul_test_common.hpp @@ -486,6 +486,8 @@ struct MatMulMethod { /// Matrix multiplication test information. using MatMulTestParams = std::tuple; +using MatMulTestPortionedParams = std::tuple; +using MatMulTestPortionedParamsWithBias = std::tuple; /// Prints the test information. void PrintTo(const MatMulTestParams& param, std::ostream* os); diff --git a/test/common/test_suite.hpp b/test/common/test_suite.hpp index 3c71c48c..5432e9ac 100644 --- a/test/common/test_suite.hpp +++ b/test/common/test_suite.hpp @@ -6,14 +6,9 @@ #pragma once -#include - #include #include #include -#include - -#include "matrix_portion.hpp" // clang-format off #define UKERNEL_MATMUL_VARIANT(name) \ @@ -71,35 +66,5 @@ struct UkernelPackVariant { UkernelVariant ukernel; P pack_interface; }; -/// Matrix multiplication shape. -struct MatMulShape { - size_t m{}; ///< LHS height. - size_t n{}; ///< RHS width. - size_t k{}; ///< LHS width and RHS height. - - struct Hash { - size_t operator()(const kai::test::MatMulShape& shape) const { - return // - (std::hash{}(shape.m) << 0) ^ // - (std::hash{}(shape.n) << 1) ^ // - (std::hash{}(shape.k) << 2); - } - }; - -private: - friend bool operator==(const MatMulShape& lhs, const MatMulShape& rhs) { - return // - lhs.m == rhs.m && // - lhs.n == rhs.n && // - lhs.k == rhs.k; - } -}; - -/// Matrix multiplication test information. -using MatMulTestParams = std::tuple; -using MatMulTestPortionedParams = std::tuple; -using MatMulTestPortionedParamsWithBias = std::tuple; - -class UkernelVariantTest : public ::testing::TestWithParam {}; } // namespace kai::test diff --git a/test/tests/matmul_clamp_f16_bf16p_bf16p_test.cpp b/test/tests/matmul_clamp_f16_bf16p_bf16p_test.cpp index 09a4ee1e..2363ace7 100644 --- a/test/tests/matmul_clamp_f16_bf16p_bf16p_test.cpp +++ b/test/tests/matmul_clamp_f16_bf16p_bf16p_test.cpp @@ -4,14 +4,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include #include #include #include -#include #include #include #include diff --git a/test/tests/matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp b/test/tests/matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp index 1b8bc29a..2098e9e6 100644 --- a/test/tests/matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp +++ b/test/tests/matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -28,6 +27,7 @@ #include "test/common/data_format.hpp" #include "test/common/float16.hpp" #include "test/common/int4.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" @@ -42,9 +42,6 @@ namespace kai::test { -static auto cpu_has_dotprod_and_fp16 = []() { return cpu_has_dotprod() && cpu_has_fp16(); }; -static auto cpu_has_i8mm_and_fp16 = []() { return cpu_has_i8mm() && cpu_has_fp16(); }; - static const std::array, 4> variants_kai_matmul_clamp_f16_qai8dxp_qsi4cxp = {{ {UKERNEL_MATMUL_VARIANT(clamp_f16_qai8dxp1x4_qsi4cxp4x4_1x4_neon_dotprod), @@ -225,13 +222,12 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000) // - << (has_bias ? "__Bias" : ""); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + sstream << (has_bias ? "__Bias" : ""); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp b/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp index 043c217e..634519ab 100644 --- a/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp @@ -28,6 +28,7 @@ #include "test/common/cpu_info.hpp" #include "test/common/data_format.hpp" #include "test/common/float16.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" @@ -42,9 +43,6 @@ namespace kai::test { -static auto cpu_has_dotprod_and_fp16 = []() { return cpu_has_dotprod() && cpu_has_fp16(); }; -static auto cpu_has_i8mm_and_fp16 = []() { return cpu_has_i8mm() && cpu_has_fp16(); }; - static const std::array, 4> variants_kai_matmul_clamp_f16_qai8dxp_qsi8cxp = {{ {UKERNEL_MATMUL_VARIANT(clamp_f16_qai8dxp1x4_qsi8cxp4x4_1x4_neon_dotprod), @@ -219,13 +217,12 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000) // - << (has_bias ? "__Bias" : ""); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + sstream << (has_bias ? "__Bias" : ""); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp b/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp index 376f78d0..979eea67 100644 --- a/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp +++ b/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,7 @@ #include "test/common/data_format.hpp" #include "test/common/float16.hpp" #include "test/common/int4.hpp" -#include "test/common/matrix_portion.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" #include "test/common/test_suite.hpp" @@ -39,9 +38,6 @@ namespace kai::test { -static auto cpu_has_dotprod_and_fp16 = []() { return cpu_has_dotprod() && cpu_has_fp16(); }; -static auto cpu_has_i8mm_and_fp16 = []() { return cpu_has_i8mm() && cpu_has_fp16(); }; - static const std::array, 2> variants_kai_matmul_clamp_f16_qsi8d32p_qai4c32p = { {{UKERNEL_MATMUL_VARIANT(clamp_f16_qsi8d32p1x8_qai4c32p4x8_1x4_neon_dotprod), @@ -231,13 +227,12 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000) // - << (has_bias ? "__Bias" : ""); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + sstream << (has_bias ? "__Bias" : ""); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_bf16p_bf16p_test.cpp b/test/tests/matmul_clamp_f32_bf16p_bf16p_test.cpp index be38ca16..2b4ca713 100644 --- a/test/tests/matmul_clamp_f32_bf16p_bf16p_test.cpp +++ b/test/tests/matmul_clamp_f32_bf16p_bf16p_test.cpp @@ -4,7 +4,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include diff --git a/test/tests/matmul_clamp_f32_f32_f32p_test.cpp b/test/tests/matmul_clamp_f32_f32_f32p_test.cpp index 9842e9fb..f970b3e1 100644 --- a/test/tests/matmul_clamp_f32_f32_f32p_test.cpp +++ b/test/tests/matmul_clamp_f32_f32_f32p_test.cpp @@ -26,6 +26,8 @@ #include "test/common/buffer.hpp" #include "test/common/cpu_info.hpp" #include "test/common/data_type.hpp" +#include "test/common/matmul_test_common.hpp" +#include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/test_suite.hpp" #include "test/reference/clamp.hpp" @@ -98,11 +100,11 @@ Buffer fill_random(size_t length, uint32_t seed) { } } // namespace -class MatMulTest_f32_f32_f32p : public ::testing::TestWithParam {}; +class MatMulTest_f32_f32_f32p : public ::testing::TestWithParam {}; TEST_P(MatMulTest_f32_f32_f32p, EndToEnd) // NOLINT(google-readability-avoid-underscore-in-googletest-name) { - const auto& [variant_idx, matmul_shape] = GetParam(); + const auto& [variant_idx, matmul_shape, _] = GetParam(); const auto& ukernel_variant = ukernel_variants.at(variant_idx); if (ukernel_variant.fn_is_supported && !ukernel_variant.fn_is_supported()) { @@ -195,14 +197,19 @@ INSTANTIATE_TEST_SUITE_P( MatMulShape{1, 7, 74}, // MatMulShape{1, 800, 64}, // MatMulShape{1, 512, 130} // + ), + testing::Values( // + MatrixPortion(0.0, 0.0, 1.0, 1.0) // )), [](const auto& info) { const auto variant_idx = std::get<0>(info.param); const std::string name{ukernel_variants.at(variant_idx).name}; const auto shape = std::get(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k; + std::ostringstream sstream; + sstream << name << "__"; + kai::test::PrintTo(shape, &sstream); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qai8dxp_qsi4c32p_test.cpp b/test/tests/matmul_clamp_f32_qai8dxp_qsi4c32p_test.cpp index 9a0d2469..968f5e60 100644 --- a/test/tests/matmul_clamp_f32_qai8dxp_qsi4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qai8dxp_qsi4c32p_test.cpp @@ -38,6 +38,7 @@ #include "test/common/bfloat16.hpp" #include "test/common/cpu_info.hpp" #include "test/common/int4.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" @@ -77,9 +78,7 @@ static const std::array; -class UkernelVariantTest_withBL : public ::testing::TestWithParam {}; - -class MatMulTest_f32_qmatmul_clamp_f32_qai8dxp_qsi4c32p : public UkernelVariantTest_withBL {}; +class MatMulTest_f32_qmatmul_clamp_f32_qai8dxp_qsi4c32p : public ::testing::TestWithParam {}; TEST_P(MatMulTest_f32_qmatmul_clamp_f32_qai8dxp_qsi4c32p, Offset_RHS) { const auto& [variant_index, matmul_shape, bl, portion] = GetParam(); @@ -449,12 +448,12 @@ INSTANTIATE_TEST_SUITE_P( const auto bl = std::get<2>(info.param); const auto portion = std::get<3>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k << "__BL_" << bl - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + sstream << "__BL_" << bl; + PrintTo(portion, &sstream); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp b/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp index 9b02d50b..edd450a3 100644 --- a/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp +++ b/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp @@ -35,6 +35,7 @@ #include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_qsi4cxps1s0_qsu4cxs1s0_neon.h" #include "test/common/cpu_info.hpp" #include "test/common/int4.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" @@ -48,9 +49,7 @@ namespace kai::test { /// Matrix multiplication test information. -using MatMulTestParams_with_portion = std::tuple; -class UkernelVariantTest_with_portions : public ::testing::TestWithParam {}; enum class RhsPackType { NxK, KxN }; using ukernel_rhs_pack_function = std::function; @@ -203,7 +202,7 @@ static const std::array {}; TEST_P(MatMulTest_f32_qai8dxp_qsi4cxp, Offset_RHS) { const auto& [variant_index, matmul_shape, portion] = GetParam(); @@ -814,12 +813,11 @@ INSTANTIATE_TEST_SUITE_P( const auto shape = std::get(info.param); const auto portion = std::get<2>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k << "__PortionStartRow_" - << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp b/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp index f55213de..2c57e3f5 100644 --- a/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp @@ -25,6 +25,7 @@ #include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_qsi8cxp_qsi8cx_neon.h" #include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_qsi8cxp_qsi8cx_neon.h" #include "test/common/cpu_info.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/test_suite.hpp" @@ -354,12 +355,11 @@ INSTANTIATE_TEST_SUITE_P( const auto shape = std::get(info.param); const auto portion = std::get(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp b/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp index 457c4d70..92e29136 100644 --- a/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_qai4c32p_qau4c32s0s1_f32_f32_f32_neon.h" #include "test/common/cpu_info.hpp" #include "test/common/int4.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" @@ -226,13 +226,12 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000) // - << (has_bias ? "__Bias" : ""); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + sstream << (has_bias ? "__Bias" : ""); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp b/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp index 153decb5..a5591ee8 100644 --- a/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp @@ -31,6 +31,7 @@ #include "test/common/cpu_info.hpp" #include "test/common/float16.hpp" #include "test/common/int4.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/round.hpp" @@ -92,10 +93,7 @@ static const std::array< clamp_f32_qsi8d32p1x4_qsi4c32p4vlx4_1x4vl_sme2_sdot, cpu_has_sme2, lhs_quant_pack_qsi8d32p_f32_neon, rhs_pack_nxk_qsi4c32ps1s0scalef16_qsu4c32s16s0_neon)}}; -using MatMulTestParams_withPortion = std::tuple; - -class UkernelVariantTest_withPortion : public ::testing::TestWithParam {}; -class MatMulTest_f32_qsi8d32p_qsi4c32p : public UkernelVariantTest_withPortion {}; +class MatMulTest_f32_qsi8d32p_qsi4c32p : public ::testing::TestWithParam {}; TEST_P(MatMulTest_f32_qsi8d32p_qsi4c32p, Offset_RHS) { const auto& [variant_index, matmul_shape, portion] = GetParam(); @@ -295,12 +293,11 @@ INSTANTIATE_TEST_SUITE_P( const auto shape = std::get(info.param); const auto portion = std::get<2>(info.param); - std::stringstream sstream; - sstream << name << "__M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000); + std::ostringstream sstream; + sstream << name << "__"; + PrintTo(shape, &sstream); + PrintTo(portion, &sstream); + return sstream.str(); }); diff --git a/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp b/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp index 66191ca2..f0ed3fdc 100644 --- a/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp @@ -31,11 +31,11 @@ #include "kai/ukernels/matmul/pack/kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.h" #include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.h" #include "test/common/cpu_info.hpp" +#include "test/common/matmul_test_common.hpp" #include "test/common/matrix_portion.hpp" #include "test/common/memory.hpp" #include "test/common/rect.hpp" #include "test/common/sme.hpp" -#include "test/common/test_suite.hpp" #include "test/reference/binary_elementwise.hpp" #include "test/reference/clamp.hpp" #include "test/reference/fill.hpp" @@ -345,17 +345,6 @@ const std::array& get_gemv_variants() { constexpr uint32_t seed = 0; ///< Random seed used for tests -/// Value range -template -struct Range { - T min; - T max; - - [[nodiscard]] T range() const { - return max - min; - } -}; - /// Quantization parameters struct Quant { float scale; diff --git a/test/tests/matmul_test.cpp b/test/tests/matmul_test.cpp index f22a593e..dbae9718 100644 --- a/test/tests/matmul_test.cpp +++ b/test/tests/matmul_test.cpp @@ -12,8 +12,6 @@ #include #include #include -#include -#include #include #include #include -- GitLab From ee82a556d3f52482bcdd0097f239d3753f2b59ec Mon Sep 17 00:00:00 2001 From: Anton Bondarenko Date: Wed, 7 May 2025 12:01:40 +0200 Subject: [PATCH 2/4] Address review comments Signed-off-by: Anton Bondarenko --- test/common/matmul_test_common.cpp | 11 +++++++++++ test/common/matmul_test_common.hpp | 3 +++ test/tests/matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp | 5 +---- test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp | 5 +---- .../tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp | 5 +---- test/tests/matmul_clamp_f32_f32_f32p_test.cpp | 1 + test/tests/matmul_clamp_f32_qai8dxp_qsi4c32p_test.cpp | 2 +- test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp | 4 +--- test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp | 4 +--- .../tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp | 5 +---- .../tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp | 4 +--- 11 files changed, 23 insertions(+), 26 deletions(-) diff --git a/test/common/matmul_test_common.cpp b/test/common/matmul_test_common.cpp index 91853dea..a5bb8c56 100644 --- a/test/common/matmul_test_common.cpp +++ b/test/common/matmul_test_common.cpp @@ -24,6 +24,17 @@ void PrintTo(const MatMulTestParams& param, std::ostream* os) { PrintTo(portion, os); } +void PrintTo( + const std::string_view& name, const MatMulShape& shape, const MatrixPortion& portion, bool bias, std::ostream* os) { + *os << "Method_" << name << "__"; + PrintTo(shape, os); + *os << "__"; + PrintTo(portion, os); + if (bias) { + *os << "__Bias"; + } +} + void PrintTo(const MatMulShape& shape, std::ostream* os) { *os << "M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k; } diff --git a/test/common/matmul_test_common.hpp b/test/common/matmul_test_common.hpp index 86ffe615..ab73230e 100644 --- a/test/common/matmul_test_common.hpp +++ b/test/common/matmul_test_common.hpp @@ -493,4 +493,7 @@ using MatMulTestPortionedParamsWithBias = std::tuple(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); - sstream << (has_bias ? "__Bias" : ""); + PrintTo(name, shape, portion, has_bias, &sstream); return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp b/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp index 634519ab..7c57c220 100644 --- a/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp @@ -218,10 +218,7 @@ INSTANTIATE_TEST_SUITE_P( const auto has_bias = std::get<3>(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); - sstream << (has_bias ? "__Bias" : ""); + PrintTo(name, shape, portion, has_bias, &sstream); return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp b/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp index 979eea67..4baccbf4 100644 --- a/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp +++ b/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp @@ -228,10 +228,7 @@ INSTANTIATE_TEST_SUITE_P( const auto has_bias = std::get<3>(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); - sstream << (has_bias ? "__Bias" : ""); + PrintTo(name, shape, portion, has_bias, &sstream); return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_f32_f32p_test.cpp b/test/tests/matmul_clamp_f32_f32_f32p_test.cpp index f970b3e1..34602634 100644 --- a/test/tests/matmul_clamp_f32_f32_f32p_test.cpp +++ b/test/tests/matmul_clamp_f32_f32_f32p_test.cpp @@ -104,6 +104,7 @@ class MatMulTest_f32_f32_f32p : public ::testing::TestWithParam(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); + PrintTo(name, shape, portion, true, &sstream); return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp b/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp index 2c57e3f5..8985c76c 100644 --- a/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp @@ -356,9 +356,7 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); + PrintTo(name, shape, portion, true, &sstream); return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp b/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp index 92e29136..a6b178e1 100644 --- a/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp @@ -227,10 +227,7 @@ INSTANTIATE_TEST_SUITE_P( const auto has_bias = std::get<3>(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); - sstream << (has_bias ? "__Bias" : ""); + PrintTo(name, shape, portion, has_bias, &sstream); return sstream.str(); }); diff --git a/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp b/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp index a5591ee8..721d340f 100644 --- a/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp @@ -294,9 +294,7 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); std::ostringstream sstream; - sstream << name << "__"; - PrintTo(shape, &sstream); - PrintTo(portion, &sstream); + PrintTo(name, shape, portion, true, &sstream); return sstream.str(); }); -- GitLab From c488705ab35bd72ef77dc21067a83eba062aa1a4 Mon Sep 17 00:00:00 2001 From: Anton Bondarenko Date: Wed, 7 May 2025 17:21:54 +0200 Subject: [PATCH 3/4] Rework test name generation for some tests Signed-off-by: Anton Bondarenko --- test/common/matmul_test_common.cpp | 30 +++++++++++-------- test/common/matmul_test_common.hpp | 6 ++-- .../matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp | 5 +--- .../matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp | 5 +--- ...atmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp | 5 +--- test/tests/matmul_clamp_f32_f32_f32p_test.cpp | 7 ++--- .../matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp | 5 +--- .../matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp | 5 +--- ...atmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp | 5 +--- ...atmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp | 5 +--- .../matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp | 27 +++++++---------- 11 files changed, 41 insertions(+), 64 deletions(-) diff --git a/test/common/matmul_test_common.cpp b/test/common/matmul_test_common.cpp index a5bb8c56..371f7920 100644 --- a/test/common/matmul_test_common.cpp +++ b/test/common/matmul_test_common.cpp @@ -6,8 +6,7 @@ #include "matmul_test_common.hpp" -#include -#include +#include namespace kai::test { @@ -24,17 +23,6 @@ void PrintTo(const MatMulTestParams& param, std::ostream* os) { PrintTo(portion, os); } -void PrintTo( - const std::string_view& name, const MatMulShape& shape, const MatrixPortion& portion, bool bias, std::ostream* os) { - *os << "Method_" << name << "__"; - PrintTo(shape, os); - *os << "__"; - PrintTo(portion, os); - if (bias) { - *os << "__Bias"; - } -} - void PrintTo(const MatMulShape& shape, std::ostream* os) { *os << "M_" << shape.m << "__N_" << shape.n << "__K_" << shape.k; } @@ -45,4 +33,20 @@ void PrintTo(const MatrixPortion& portion, std::ostream* os) { << "__PortionHeight_" << static_cast(portion.height() * 1000) // << "__PortionWidth_" << static_cast(portion.width() * 1000); } + +std::string test_description( + const std::string_view& name, const MatMulShape& shape, const MatrixPortion& portion, bool bias) { + std::ostringstream os; + + os << "Method_" << name << "__"; + PrintTo(shape, &os); + os << "__"; + PrintTo(portion, &os); + if (bias) { + os << "__Bias"; + } + + return os.str(); +} + } // namespace kai::test diff --git a/test/common/matmul_test_common.hpp b/test/common/matmul_test_common.hpp index ab73230e..528c7566 100644 --- a/test/common/matmul_test_common.hpp +++ b/test/common/matmul_test_common.hpp @@ -493,7 +493,9 @@ using MatMulTestPortionedParamsWithBias = std::tuple(info.param); const auto has_bias = std::get<3>(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, has_bias, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, has_bias); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp b/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp index 7c57c220..0500d8f6 100644 --- a/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp @@ -217,10 +217,7 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, has_bias, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, has_bias); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp b/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp index 4baccbf4..de6c3a90 100644 --- a/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp +++ b/test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp @@ -227,10 +227,7 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, has_bias, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, has_bias); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f32_f32_f32p_test.cpp b/test/tests/matmul_clamp_f32_f32_f32p_test.cpp index 34602634..c80e42ad 100644 --- a/test/tests/matmul_clamp_f32_f32_f32p_test.cpp +++ b/test/tests/matmul_clamp_f32_f32_f32p_test.cpp @@ -206,12 +206,9 @@ INSTANTIATE_TEST_SUITE_P( const auto variant_idx = std::get<0>(info.param); const std::string name{ukernel_variants.at(variant_idx).name}; const auto shape = std::get(info.param); + const auto portion = std::get<2>(info.param); - std::ostringstream sstream; - sstream << name << "__"; - kai::test::PrintTo(shape, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, true); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp b/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp index eb247323..5a770fbe 100644 --- a/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp +++ b/test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp @@ -813,10 +813,7 @@ INSTANTIATE_TEST_SUITE_P( const auto shape = std::get(info.param); const auto portion = std::get<2>(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, true, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, true); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp b/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp index 8985c76c..f22671a1 100644 --- a/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp @@ -355,10 +355,7 @@ INSTANTIATE_TEST_SUITE_P( const auto shape = std::get(info.param); const auto portion = std::get(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, true, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, true); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp b/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp index a6b178e1..14184151 100644 --- a/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp @@ -226,10 +226,7 @@ INSTANTIATE_TEST_SUITE_P( const auto portion = std::get<2>(info.param); const auto has_bias = std::get<3>(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, has_bias, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, has_bias); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp b/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp index 721d340f..a93a0b65 100644 --- a/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp +++ b/test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp @@ -293,10 +293,7 @@ INSTANTIATE_TEST_SUITE_P( const auto shape = std::get(info.param); const auto portion = std::get<2>(info.param); - std::ostringstream sstream; - PrintTo(name, shape, portion, true, &sstream); - - return sstream.str(); + return test_description(name, shape, portion, true); }); } // namespace kai::test diff --git a/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp b/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp index f0ed3fdc..e3c1cb91 100644 --- a/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp @@ -715,14 +715,11 @@ static std::string test_description( const MatMulVariant& variant, // const MatMulShape& shape, // const MatrixPortion& portion, float clamp_ratio) { - std::stringstream sstream; - sstream << "Method_" << variant.name << "__M_" // - << shape.m << "__N_" << shape.n << "__K_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000) // + std::ostringstream sstream; + + sstream << test_description(variant.name, shape, portion, true) // << "__clamp_ratio_" << static_cast(clamp_ratio * 100); + return sstream.str(); }; @@ -730,15 +727,13 @@ static std::string test_description( const IndirectMatMulVariant& variant, // const MatMulShape& shape, // const MatrixPortion& portion, size_t k_chunk_len, float clamp_ratio) { - std::stringstream sstream; - sstream << "Method_" << variant.name << "__M_" // - << shape.m << "__N_" << shape.n << "__k_chunk_count_" << shape.k // - << "__PortionStartRow_" << static_cast(portion.start_row() * 1000) // - << "__PortionStartCol_" << static_cast(portion.start_col() * 1000) // - << "__PortionHeight_" << static_cast(portion.height() * 1000) // - << "__PortionWidth_" << static_cast(portion.width() * 1000) // - << "__k_chunk_len_" << k_chunk_len // - << "__clamp_ratio_" << static_cast(clamp_ratio * 100); + std::ostringstream sstream; + + sstream << "Method_" << variant.name << "__M_" << shape.m << "__N_" << shape.n << "__k_chunk_count_" << shape.k + << "__"; + PrintTo(portion, &sstream); + sstream << "__k_chunk_len_" << k_chunk_len << "__clamp_ratio_" << static_cast(clamp_ratio * 100); + return sstream.str(); }; -- GitLab From 39f63275dd5bc608309f0d831ac805c5d9aa3cdf Mon Sep 17 00:00:00 2001 From: Anton Bondarenko Date: Thu, 8 May 2025 13:35:21 +0200 Subject: [PATCH 4/4] Fix build on some platforms Signed-off-by: Anton Bondarenko --- test/common/matmul_test_common.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/common/matmul_test_common.hpp b/test/common/matmul_test_common.hpp index 528c7566..9b576d8e 100644 --- a/test/common/matmul_test_common.hpp +++ b/test/common/matmul_test_common.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include -- GitLab