From b37107d28042f95c3c58a2fe1541b1ccc73f48bd Mon Sep 17 00:00:00 2001 From: Emil Ohlsson Date: Tue, 22 Apr 2025 13:22:30 +0200 Subject: [PATCH] QAI8 cleanup changes There are few cleanups for QAI8 that were discovered while doing FP16 work. This change bundles these cleanups Signed-off-by: Emil Ohlsson --- ...ack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c | 1 + test/common/test_suite.hpp | 19 ++++++++------- test/reference/matmul.hpp | 8 +++---- .../matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp | 24 +++++++++---------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/kai/ukernels/matmul/pack/kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c b/kai/ukernels/matmul/pack/kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c index 3db501b6..8cd1201a 100644 --- a/kai/ukernels/matmul/pack/kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c +++ b/kai/ukernels/matmul/pack/kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c @@ -73,6 +73,7 @@ void kai_run_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme( const void* scale, void* rhs_packed, const struct kai_rhs_pack_qsi8cx_params* params) { KAI_ASSUME(rhs != NULL); KAI_ASSUME(bias != NULL); + KAI_ASSUME(scale != NULL); KAI_ASSUME(rhs_packed != NULL); KAI_ASSUME(params != NULL); diff --git a/test/common/test_suite.hpp b/test/common/test_suite.hpp index c86e33cf..3c71c48c 100644 --- a/test/common/test_suite.hpp +++ b/test/common/test_suite.hpp @@ -76,6 +76,16 @@ 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 // @@ -85,15 +95,6 @@ private: } }; -struct HashMatMulShape { - 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); - } -}; - /// Matrix multiplication test information. using MatMulTestParams = std::tuple; using MatMulTestPortionedParams = std::tuple; diff --git a/test/reference/matmul.hpp b/test/reference/matmul.hpp index 8d83e98c..758d2fbb 100644 --- a/test/reference/matmul.hpp +++ b/test/reference/matmul.hpp @@ -122,10 +122,10 @@ std::vector matmul_clamp_nt_t( /// @param[in] m The LHS and output height. /// @param[in] n The RHS height and output width. /// @param[in] k The LHS and RHS width. -/// @param[in] k_chunk_count Number of K chunk pointers per row in lhs_idata matrix -/// @param[in] k_chunk_length Lenght of each K chunk pointed to in lhs_idata matrix +/// @param[in] k_chunk_count Number of K chunk pointers per row in lhs_ptrs matrix +/// @param[in] k_chunk_length Lenght of each K chunk pointed to in lhs_ptrs matrix /// @param[in] lhs_data The LHS data matrix. -/// @param[in] lhs_idata The indirect LHS data matrix. +/// @param[in] lhs_ptrs The indirect LHS data matrix. /// @param[in] lhs_offset The indirection LHS data matrix offset, applied to non-padding pointers /// @parma[in] lhs_padding The indirection LHS padding chunk pointer /// @param[in] lhs_scales The LHS quantization scales matrix. @@ -166,7 +166,7 @@ template < typename RhsZeroPoint, typename BiasData, typename BiasScale, typename BiasZeroPoint, typename DstData> std::vector indirect_matmul_nt_t_quantized( size_t m, size_t n, size_t k_chunk_count, size_t k_chunk_length, // - const void* const* lhs_idata, uintptr_t lhs_offset, const void* lhs_padding, const void* lhs_scales, + const void* const* lhs_ptrs, uintptr_t lhs_offset, const void* lhs_padding, const void* lhs_scales, const void* lhs_zero_points, size_t lhs_quant_height, size_t lhs_quant_width, // const void* rhs_data, const void* rhs_scales, const void* rhs_zero_points, size_t rhs_quant_height, diff --git a/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp b/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp index 9ac28a93..6823bf9d 100644 --- a/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp +++ b/test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp @@ -378,6 +378,17 @@ struct TestDataId { bool pad_testing; float clamp_ratio; + struct Hash { + size_t operator()(const TestDataId& id) const { + return // + (MatMulShape::Hash{}(id.shape) << 0) ^ // + (MatMulShape::Hash{}(id.shape_pack) << 1) ^ // + (std::hash{}(id.chunk_len) << 2) ^ // + (std::hash{}(id.pad_testing) << 3) ^ // + (std::hash{}(id.clamp_ratio) << 4); + } + }; + private: friend bool operator==(const TestDataId& lhs, const TestDataId& rhs) { return // @@ -389,19 +400,8 @@ private: } }; -struct HashTestDataId { - size_t operator()(const TestDataId& id) const { - return // - (HashMatMulShape{}(id.shape) << 0) ^ // - (HashMatMulShape{}(id.shape_pack) << 1) ^ // - (std::hash{}(id.chunk_len) << 2) ^ // - (std::hash{}(id.pad_testing) << 3) ^ // - (std::hash{}(id.clamp_ratio) << 4); - } -}; - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) -std::unordered_map g_data; +std::unordered_map g_data; // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) /// Generate test reference data -- GitLab