From 30db89c4ca5c76bee664d3b7bd241198a90b7d21 Mon Sep 17 00:00:00 2001 From: higkoo Date: Tue, 26 May 2026 14:26:02 +0800 Subject: [PATCH] Add support for SVE vector length retrieval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对aarch64的支持,测试环境:双路鲲鹏920处理器、Debian11操作系统。 --- nnml/include/nnml.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nnml/include/nnml.h b/nnml/include/nnml.h index ed95986..319d732 100644 --- a/nnml/include/nnml.h +++ b/nnml/include/nnml.h @@ -15,6 +15,7 @@ #if !defined(_WIN32) #include +#include #endif @@ -574,7 +575,16 @@ static inline int nnml_cpu_has_matmul_int8(void) { static inline int nnml_cpu_get_sve_cnt(void) { #if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) - return nnml_arm_arch_features.sve_cnt; + return __builtin_sve_vector_length(); +# if defined(_GNU_SOURCE) && defined(_SC_SVE_VQ_MAX) + return sysconf(_SC_SVE_VQ_MAX); +# elif defined(__aarch64__) + uint64_t zcr; + asm("mrs %0, ZCR_EL1" : "=r"(zcr)); + return (zcr & 0xf) + 1; +# else + return 4; +# endif #else return 0; #endif