Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eddnjjn
Copy link
Contributor

@eddnjjn eddnjjn commented Sep 6, 2024

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.

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 6, 2024
ggml/src/ggml.c Outdated
Comment on lines 3771 to 3773
#if defined(__aarch64__)
ggml_init_aarch64_features();
#endif
Copy link
Owner

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

Adds run-time detection of the Arm instructions set features
neon, i8mm and sve for Linux and Apple build targets.
@eddnjjn eddnjjn force-pushed the cpu-runtime-feature-detection branch from 8324367 to aab436c Compare September 18, 2024 06:12
@eddnjjn
Copy link
Contributor Author

eddnjjn commented Sep 18, 2024

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.

Comment on lines +3761 to +3764
#if defined(__aarch64__)
ggml_init_aarch64_features();
#endif

Copy link
Owner

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:

#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants