]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
Check for both __ARM_NEON and __ARM_FEATURE_FMA so that the project can be compiled...
authorKevin Brothaler <redacted>
Tue, 20 Dec 2022 18:33:33 +0000 (13:33 -0500)
committerGeorgi Gerganov <redacted>
Thu, 22 Dec 2022 14:47:54 +0000 (16:47 +0200)
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.

examples/whisper.android/.idea/gradle.xml
examples/whisper.android/app/build.gradle
ggml.c
ggml.h
whisper.cpp

index a9f4e522a7f06c51dca0bb89f9ffcde7920648de..a2d7c21338e98a66cd8af9e352f293e52324608b 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
+  <component name="GradleMigrationSettings" migrationVersion="1" />
   <component name="GradleSettings">
     <option name="linkedExternalProjectsSettings">
       <GradleProjectSettings>
index 64a43bbba57b3919c20beeef56d6accc5392f015..66add99161052dad9930ff4d6b4eadc0aba6c07a 100644 (file)
@@ -14,10 +14,6 @@ android {
         versionCode 1
         versionName "1.0"
 
-        ndk {
-            abiFilters 'arm64-v8a', 'x86_64'
-        }
-
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         vectorDrawables {
             useSupportLibrary true
diff --git a/ggml.c b/ggml.c
index f1d2b2564325204f4dd3dcc7a89ad7a857d665c1..df4a779f1eceac560f43ea4b99d4cd7446f2382a 100644 (file)
--- a/ggml.c
+++ b/ggml.c
@@ -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);
 
@@ -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)
@@ -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);
 
@@ -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);
 
@@ -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;
diff --git a/ggml.h b/ggml.h
index 7f24e5312f6b479b0bb477e6e3f7c369ec462bf6..4bb6118fe256ff0490b74623ab124c453dcb0e9b 100644 (file)
--- a/ggml.h
+++ b/ggml.h
@@ -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);
index 0aaaea0da69032dd9d35e9d5e7259421bfe50746..fb50705338c09b0dc6bc9ff3ad9b0f57cef6968a 100644 (file)
@@ -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()) + " | ";