jhenhong commited on
Commit
dedf05b
·
unverified ·
1 Parent(s): 542cfc1

ggml, ci : fix build on whisper.android (ARM_NEON) + add CI (#764)

Browse files

* ggml : fix undefined symbol by remove inline handle

* ggml : make own ggml_aligned_malloc function

* ci: add ios/android build

Files changed (2) hide show
  1. .github/workflows/build.yml +41 -0
  2. ggml.c +16 -7
.github/workflows/build.yml CHANGED
@@ -265,3 +265,44 @@ jobs:
265
  popd
266
  emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
267
  make
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  popd
266
  emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
267
  make
268
+
269
+ ios:
270
+ runs-on: macos-latest
271
+
272
+ strategy:
273
+ matrix:
274
+ build: [Release]
275
+
276
+ steps:
277
+ - name: Clone
278
+ uses: actions/checkout@v1
279
+
280
+ - name: Configure
281
+ run: cp models/for-tests-ggml-base.en.bin models/ggml-base.en.bin
282
+
283
+ - name: Build objc example
284
+ run: xcodebuild -project examples/whisper.objc/whisper.objc.xcodeproj -scheme whisper.objc -configuration ${{ matrix.build }} -sdk iphonesimulator build
285
+
286
+ - name: Build swiftui example
287
+ run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk iphonesimulator build
288
+
289
+ android:
290
+ runs-on: ubuntu-latest
291
+
292
+ steps:
293
+ - name: Clone
294
+ uses: actions/checkout@v1
295
+
296
+ - name: Install Java
297
+ uses: actions/setup-java@v3
298
+ with:
299
+ distribution: zulu
300
+ java-version: 17
301
+
302
+ - name: Setup Android SDK
303
+ uses: android-actions/setup-android@v2
304
+
305
+ - name: Build
306
+ run: |
307
+ cd examples/whisper.android
308
+ ./gradlew assembleRelease --no-daemon
ggml.c CHANGED
@@ -118,7 +118,16 @@ typedef void* thread_ret_t;
118
  #define GGML_ALIGNED_MALLOC(size) _aligned_malloc(size, GGML_MEM_ALIGN)
119
  #define GGML_ALIGNED_FREE(ptr) _aligned_free(ptr)
120
  #else
121
- #define GGML_ALIGNED_MALLOC(size) aligned_alloc(GGML_MEM_ALIGN, size)
 
 
 
 
 
 
 
 
 
122
  #define GGML_ALIGNED_FREE(ptr) free(ptr)
123
  #endif
124
 
@@ -531,31 +540,31 @@ inline static float vaddvq_f32(float32x4_t v) {
531
  return vgetq_lane_f32(v, 0) + vgetq_lane_f32(v, 1) + vgetq_lane_f32(v, 2) + vgetq_lane_f32(v, 3);
532
  }
533
 
534
- inline float vminvq_f32(float32x4_t v) {
535
  return
536
  MIN(MIN(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
537
  MIN(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
538
  }
539
 
540
- inline float vmaxvq_f32(float32x4_t v) {
541
  return
542
  MAX(MAX(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
543
  MAX(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
544
  }
545
 
546
- inline int8x8_t vzip1_s8(int8x8_t a, int8x8_t b) {
547
  return vget_low_s8(vcombine_s8(a, b));
548
  }
549
 
550
- inline int8x8_t vzip2_s8(int8x8_t a, int8x8_t b) {
551
  return vget_high_s8(vcombine_s8(a, b));
552
  }
553
 
554
- inline uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) {
555
  return vget_low_u8(vcombine_u8(a, b));
556
  }
557
 
558
- inline uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) {
559
  return vget_high_u8(vcombine_u8(a, b));
560
  }
561
 
 
118
  #define GGML_ALIGNED_MALLOC(size) _aligned_malloc(size, GGML_MEM_ALIGN)
119
  #define GGML_ALIGNED_FREE(ptr) _aligned_free(ptr)
120
  #else
121
+ inline static void* ggml_aligned_malloc(size_t size) {
122
+ void* aligned_memory = NULL;
123
+ int result = posix_memalign(&aligned_memory, GGML_MEM_ALIGN, size);
124
+ if (result != 0) {
125
+ // Handle allocation failure
126
+ return NULL;
127
+ }
128
+ return aligned_memory;
129
+ }
130
+ #define GGML_ALIGNED_MALLOC(size) ggml_aligned_malloc(size)
131
  #define GGML_ALIGNED_FREE(ptr) free(ptr)
132
  #endif
133
 
 
540
  return vgetq_lane_f32(v, 0) + vgetq_lane_f32(v, 1) + vgetq_lane_f32(v, 2) + vgetq_lane_f32(v, 3);
541
  }
542
 
543
+ float vminvq_f32(float32x4_t v) {
544
  return
545
  MIN(MIN(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
546
  MIN(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
547
  }
548
 
549
+ float vmaxvq_f32(float32x4_t v) {
550
  return
551
  MAX(MAX(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
552
  MAX(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
553
  }
554
 
555
+ int8x8_t vzip1_s8(int8x8_t a, int8x8_t b) {
556
  return vget_low_s8(vcombine_s8(a, b));
557
  }
558
 
559
+ int8x8_t vzip2_s8(int8x8_t a, int8x8_t b) {
560
  return vget_high_s8(vcombine_s8(a, b));
561
  }
562
 
563
+ uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) {
564
  return vget_low_u8(vcombine_u8(a, b));
565
  }
566
 
567
+ uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) {
568
  return vget_high_u8(vcombine_u8(a, b));
569
  }
570