-
Notifications
You must be signed in to change notification settings - Fork 12.8k
ARM: Fixes and additions to CPU feature detection #14049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,11 +76,13 @@ | |
struct ggml_arm_arch_features_type { | ||
int has_neon; | ||
int has_dotprod; | ||
int has_fp16_va; | ||
int has_i8mm; | ||
int has_sve; | ||
int has_sve2; | ||
int sve_cnt; | ||
int has_sme; | ||
} ggml_arm_arch_features = {-1, -1, -1, -1, 0, -1}; | ||
} ggml_arm_arch_features = {-1, -1, -1, -1, -1, -1, 0, -1}; | ||
#endif | ||
|
||
|
||
|
@@ -689,8 +691,10 @@ static void ggml_init_arm_arch_features(void) { | |
|
||
ggml_arm_arch_features.has_neon = !!(hwcap & HWCAP_ASIMD); | ||
ggml_arm_arch_features.has_dotprod = !!(hwcap & HWCAP_ASIMDDP); | ||
ggml_arm_arch_features.has_fp16_va = !!(hwcap & HWCAP_FPHP); | ||
ggml_arm_arch_features.has_i8mm = !!(hwcap2 & HWCAP2_I8MM); | ||
ggml_arm_arch_features.has_sve = !!(hwcap & HWCAP_SVE); | ||
ggml_arm_arch_features.has_sve2 = !!(hwcap2 & HWCAP2_SVE2); | ||
ggml_arm_arch_features.has_sme = !!(hwcap2 & HWCAP2_SME); | ||
|
||
#if defined(__ARM_FEATURE_SVE) | ||
|
@@ -709,6 +713,11 @@ static void ggml_init_arm_arch_features(void) { | |
} | ||
ggml_arm_arch_features.has_dotprod = oldp; | ||
|
||
if (sysctlbyname("hw.optional.arm.FEAT_FP16", &oldp, &size, NULL, 0) != 0) { | ||
oldp = 0; | ||
} | ||
ggml_arm_arch_features.has_fp16_va = oldp; | ||
|
||
if (sysctlbyname("hw.optional.arm.FEAT_I8MM", &oldp, &size, NULL, 0) != 0) { | ||
oldp = 0; | ||
} | ||
|
@@ -719,8 +728,9 @@ static void ggml_init_arm_arch_features(void) { | |
} | ||
ggml_arm_arch_features.has_sme = oldp; | ||
|
||
ggml_arm_arch_features.has_sve = 0; | ||
ggml_arm_arch_features.sve_cnt = 0; | ||
ggml_arm_arch_features.has_sve = 0; | ||
ggml_arm_arch_features.has_sve2 = 0; | ||
ggml_arm_arch_features.sve_cnt = 0; | ||
#else | ||
// Run-time CPU feature detection not implemented for this platform, fallback to compile time | ||
#if defined(__ARM_NEON) | ||
|
@@ -729,6 +739,18 @@ static void ggml_init_arm_arch_features(void) { | |
ggml_arm_arch_features.has_neon = 0; | ||
#endif | ||
|
||
#if defined(__ARM_FEATURE_DOTPROD) | ||
ggml_arm_arch_features.has_dotprod = 1; | ||
#else | ||
ggml_arm_arch_features.has_dotprod = 0; | ||
#endif | ||
|
||
#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compile-time block for Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
ggml_arm_arch_features.has_fp16_va = 1; | ||
#else | ||
ggml_arm_arch_features.has_fp16_va = 0; | ||
#endif | ||
|
||
#if defined(__ARM_FEATURE_MATMUL_INT8) | ||
ggml_arm_arch_features.has_i8mm = 1; | ||
#else | ||
|
@@ -743,6 +765,12 @@ static void ggml_init_arm_arch_features(void) { | |
ggml_arm_arch_features.sve_cnt = 0; | ||
#endif | ||
|
||
#if defined(__ARM_FEATURE_SVE2) | ||
ggml_arm_arch_features.has_sve2 = 1; | ||
#else | ||
ggml_arm_arch_features.has_sve2 = 0; | ||
#endif | ||
|
||
#if defined(__ARM_FEATURE_SME) || defined(__ARM_FEATURE_SME2) | ||
ggml_arm_arch_features.has_sme = 1; | ||
#else | ||
|
@@ -3377,14 +3405,6 @@ int ggml_cpu_has_f16c(void) { | |
#endif | ||
} | ||
|
||
int ggml_cpu_has_fp16_va(void) { | ||
#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) | ||
return 1; | ||
#else | ||
return 0; | ||
#endif | ||
} | ||
|
||
int ggml_cpu_has_wasm_simd(void) { | ||
#if defined(__wasm_simd128__) | ||
return 1; | ||
|
@@ -3449,6 +3469,14 @@ int ggml_cpu_has_dotprod(void) { | |
#endif | ||
} | ||
|
||
int ggml_cpu_has_fp16_va(void) { | ||
#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why we do a second ifdef here when this variable is set to 0 or 1 elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment below, case 1. The way I see it, during runtime detection the host may report that the CPU supports this feature, but if we disabled it at compilation, we want the function to always return 0. |
||
return ggml_arm_arch_features.has_fp16_va; | ||
#else | ||
return 0; | ||
#endif | ||
} | ||
|
||
int ggml_cpu_has_sve(void) { | ||
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) | ||
return ggml_arm_arch_features.has_sve; | ||
|
@@ -3457,6 +3485,14 @@ int ggml_cpu_has_sve(void) { | |
#endif | ||
} | ||
|
||
int ggml_cpu_has_sve2(void) { | ||
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE2) | ||
return ggml_arm_arch_features.has_sve2; | ||
#else | ||
return 0; | ||
#endif | ||
} | ||
|
||
int ggml_cpu_has_matmul_int8(void) { | ||
#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_MATMUL_INT8) | ||
return ggml_arm_arch_features.has_i8mm; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro
HWCAP_FPHP
looks like a typo; the standard HWCAP for FP16 support is usuallyHWCAP_FP16
. Verify and correct this macro to ensure proper runtime detection.Copilot uses AI. Check for mistakes.