-
Notifications
You must be signed in to change notification settings - Fork 10k
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
ggml: Add run-time detection of neon, i8mm and sve #9331
ggml: Add run-time detection of neon, i8mm and sve #9331
Conversation
ggml/src/ggml.c
Outdated
#if defined(__aarch64__) | ||
ggml_init_aarch64_features(); | ||
#endif |
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.
For clarity, this call should be within the is_first_call
section above
8324367
to
aab436c
Compare
Thanks for the review @ggerganov . I've rebased the patch and addressed your comment by moving the invocation of ggml_init_aarch64_features to the is_first_call section. I also updated ggml_init_aarch64_features to not check for first invocation since this is done in ggml_init. Please let me know if you have additional comments. |
ggml/src/ggml.c
Outdated
#if defined(__aarch64__) | ||
ggml_init_aarch64_features(); | ||
#endif | ||
|
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.
This looks incorrect because ARM NEON presence is now associated with __aarch64__
, but this is not always the case AFAIK. For example, here we have support for __ARM_NEON && !__aarch64__
, such as Raspberry Pi:
llama.cpp/ggml/src/ggml-cpu-impl.h
Lines 132 to 167 in 64c6af3
#if defined(__ARM_NEON) | |
// if YCM cannot find <arm_neon.h>, make a symbolic link to it, for example: | |
// | |
// $ ln -sfn /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/arm_neon.h ./src/ | |
// | |
#include <arm_neon.h> | |
#ifdef _MSC_VER | |
typedef uint16_t ggml_fp16_internal_t; | |
#define ggml_vld1q_u32(w,x,y,z) { ((w) + ((uint64_t)(x) << 32)), ((y) + ((uint64_t)(z) << 32)) } | |
#else | |
typedef __fp16 ggml_fp16_internal_t; | |
#define ggml_vld1q_u32(w,x,y,z) { (w), (x), (y), (z) } | |
#endif // _MSC_VER | |
#if !defined(__aarch64__) | |
// 32-bit ARM compatibility | |
// vaddlvq_s16 | |
// vpaddq_s16 | |
// vpaddq_s32 | |
// vaddvq_s32 | |
// vaddvq_f32 | |
// vmaxvq_f32 | |
// vcvtnq_s32_f32 | |
// vzip1_u8 | |
// vzip2_u8 | |
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.
I've addressed this comment in the update. Non aarch64 Linux builds fallback to using compile time flags for detecting whether or not Neon is enabled.
ggml/src/ggml.c
Outdated
#if defined(__ARM_ARCH) | ||
struct ggml_arm_arch_features_type { | ||
int has_neon; | ||
int has_i8mm; | ||
int has_sve; | ||
int sve_cnt; | ||
} ggml_arm_arch_features = {-1, -1, -1, 0}; | ||
#endif | ||
|
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.
Move down in the global data
section, around line 438
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.
Done!
Adds run-time detection of the Arm instructions set features neon, i8mm and sve for Linux and Apple build targets.
904111a
to
a48284c
Compare
I've addressed @ggerganov's latest comment and rebased the patches on latest master. Please let me know if you have additional comments. |
@@ -2507,6 +2507,9 @@ extern "C" { | |||
GGML_API int ggml_cpu_has_cann (void); | |||
GGML_API int ggml_cpu_has_llamafile (void); | |||
|
|||
// get the sve vector length in bytes | |||
GGML_API int ggml_cpu_get_sve_cnt(void); |
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.
This function is better to not be facing the public API. Will merge this for now, but consider making it private.
* ggml: Added run-time detection of neon, i8mm and sve Adds run-time detection of the Arm instructions set features neon, i8mm and sve for Linux and Apple build targets. * ggml: Extend feature detection to include non aarch64 Arm arch * ggml: Move definition of ggml_arm_arch_features to the global data section
This series breaks the build on Linux (Ubuntu 20.04 here) due to HWCAP2_I8MM not being known (probably depends on libc or kernel source version):
This fixes it:
But I think it would be cleaner to just define the missing HWCAP* flags before such as this, which is easy to extend to new flags when needed (and works as well):
|
* ggml: Added run-time detection of neon, i8mm and sve Adds run-time detection of the Arm instructions set features neon, i8mm and sve for Linux and Apple build targets. * ggml: Extend feature detection to include non aarch64 Arm arch * ggml: Move definition of ggml_arm_arch_features to the global data section
* ggml: Added run-time detection of neon, i8mm and sve Adds run-time detection of the Arm instructions set features neon, i8mm and sve for Linux and Apple build targets. * ggml: Extend feature detection to include non aarch64 Arm arch * ggml: Move definition of ggml_arm_arch_features to the global data section
* ggml: Added run-time detection of neon, i8mm and sve Adds run-time detection of the Arm instructions set features neon, i8mm and sve for Linux and Apple build targets. * ggml: Extend feature detection to include non aarch64 Arm arch * ggml: Move definition of ggml_arm_arch_features to the global data section
This patch adds run-time detection of the Arm instructions set features Arm® Neon™, i8mm and sve for Linux and Apple build targets. The run-time detection is enabled for aarch64 builds and done in ggml_init. The data is stored in a global struct instance to be later used by the ggml_cpu_has_* functions.