Skip to content

Commit

Permalink
Check for both __ARM_NEON and __ARM_FEATURE_FMA so that the project c…
Browse files Browse the repository at this point in the history
…an be compiled for armv7a.

Android armeabi-v7a's NEON support doesn't support FMA unless configured with `-mfpu=neon-fp-armv8`, which would need runtime checks.
* Also removed ABI filter from Android project.
  • Loading branch information
Digipom authored and ggerganov committed Dec 22, 2022
1 parent 22193cb commit e1432dd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/whisper.android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions examples/whisper.android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ android {
versionCode 1
versionName "1.0"

ndk {
abiFilters 'arm64-v8a', 'x86_64'
}

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
Expand Down
16 changes: 12 additions & 4 deletions ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ inline static void ggml_vec_div_f32 (const int n, float * z, const float * x, co

inline static void ggml_vec_dot_f32(const int n, float * restrict s, const float * restrict x, const float * restrict y) {
ggml_float sumf = 0.0;
#ifdef __ARM_NEON
#if defined(__ARM_NEON) && defined(__ARM_FEATURE_FMA)
// NEON 128-bit
const int n16 = (n & ~15);

Expand Down Expand Up @@ -511,7 +511,7 @@ inline static void ggml_vec_dot_f32(const int n, float * restrict s, const float

inline static void ggml_vec_dot_f16(const int n, float * restrict s, ggml_fp16_t * restrict x, ggml_fp16_t * restrict y) {
ggml_float sumf = 0.0;
#ifdef __ARM_NEON
#if defined(__ARM_NEON) && defined(__ARM_FEATURE_FMA)
const int n32 = (n & ~31);

#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
Expand Down Expand Up @@ -760,7 +760,7 @@ inline static void ggml_vec_dot_f16(const int n, float * restrict s, ggml_fp16_t
}

inline static void ggml_vec_mad_f32(const int n, float * restrict y, const float * restrict x, const float v) {
#ifdef __ARM_NEON
#if defined(__ARM_NEON) && defined(__ARM_FEATURE_FMA)
// NEON 128-bit
const int n16 = (n & ~15);

Expand Down Expand Up @@ -909,7 +909,7 @@ inline static void ggml_vec_mad_f32(const int n, float * restrict y, const float
}

inline static void ggml_vec_mad_f16(const int n, ggml_fp16_t * restrict y, ggml_fp16_t * restrict x, const float v) {
#ifdef __ARM_NEON
#if defined(__ARM_NEON) && defined(__ARM_FEATURE_FMA)
// NEON 128-bit
const int n32 = (n & ~31);

Expand Down Expand Up @@ -8432,6 +8432,14 @@ int ggml_cpu_has_neon(void) {
#endif
}

int ggml_cpu_has_arm_fma(void) {
#if defined(__ARM_FEATURE_FMA)
return 1;
#else
return 0;
#endif
}

int ggml_cpu_has_f16c(void) {
#if defined(__F16C__)
return 1;
Expand Down
1 change: 1 addition & 0 deletions ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ int ggml_cpu_has_avx(void);
int ggml_cpu_has_avx2(void);
int ggml_cpu_has_avx512(void);
int ggml_cpu_has_neon(void);
int ggml_cpu_has_arm_fma(void);
int ggml_cpu_has_f16c(void);
int ggml_cpu_has_fp16_va(void);
int ggml_cpu_has_wasm_simd(void);
Expand Down
1 change: 1 addition & 0 deletions whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,7 @@ const char * whisper_print_system_info(void) {
s += "AVX2 = " + std::to_string(ggml_cpu_has_avx2()) + " | ";
s += "AVX512 = " + std::to_string(ggml_cpu_has_avx512()) + " | ";
s += "NEON = " + std::to_string(ggml_cpu_has_neon()) + " | ";
s += "ARM FMA = " + std::to_string(ggml_cpu_has_arm_fma()) + " | ";
s += "F16C = " + std::to_string(ggml_cpu_has_f16c()) + " | ";
s += "FP16_VA = " + std::to_string(ggml_cpu_has_fp16_va()) + " | ";
s += "WASM_SIMD = " + std::to_string(ggml_cpu_has_wasm_simd()) + " | ";
Expand Down

0 comments on commit e1432dd

Please sign in to comment.