From ea1f8a50d4f70b54d9dd03205207a80019e243f9 Mon Sep 17 00:00:00 2001 From: Jhen-Jie Hong Date: Sat, 15 Apr 2023 19:21:58 +0800 Subject: [PATCH] ggml, ci : fix build on whisper.android (ARM_NEON) + add CI (#764) * ggml : fix undefined symbol by remove inline handle * ggml : make own ggml_aligned_malloc function * ci: add ios/android build --- .github/workflows/build.yml | 41 +++++++++++++++++++++++++++++++++++++ ggml.c | 23 ++++++++++++++------- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a2baac..08f039b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -265,3 +265,44 @@ jobs: popd emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }} make + + ios: + runs-on: macos-latest + + strategy: + matrix: + build: [Release] + + steps: + - name: Clone + uses: actions/checkout@v1 + + - name: Configure + run: cp models/for-tests-ggml-base.en.bin models/ggml-base.en.bin + + - name: Build objc example + run: xcodebuild -project examples/whisper.objc/whisper.objc.xcodeproj -scheme whisper.objc -configuration ${{ matrix.build }} -sdk iphonesimulator build + + - name: Build swiftui example + run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk iphonesimulator build + + android: + runs-on: ubuntu-latest + + steps: + - name: Clone + uses: actions/checkout@v1 + + - name: Install Java + uses: actions/setup-java@v3 + with: + distribution: zulu + java-version: 17 + + - name: Setup Android SDK + uses: android-actions/setup-android@v2 + + - name: Build + run: | + cd examples/whisper.android + ./gradlew assembleRelease --no-daemon \ No newline at end of file diff --git a/ggml.c b/ggml.c index ce48b78..ca3b7b9 100644 --- a/ggml.c +++ b/ggml.c @@ -118,7 +118,16 @@ typedef void* thread_ret_t; #define GGML_ALIGNED_MALLOC(size) _aligned_malloc(size, GGML_MEM_ALIGN) #define GGML_ALIGNED_FREE(ptr) _aligned_free(ptr) #else -#define GGML_ALIGNED_MALLOC(size) aligned_alloc(GGML_MEM_ALIGN, size) +inline static void* ggml_aligned_malloc(size_t size) { + void* aligned_memory = NULL; + int result = posix_memalign(&aligned_memory, GGML_MEM_ALIGN, size); + if (result != 0) { + // Handle allocation failure + return NULL; + } + return aligned_memory; +} +#define GGML_ALIGNED_MALLOC(size) ggml_aligned_malloc(size) #define GGML_ALIGNED_FREE(ptr) free(ptr) #endif @@ -531,31 +540,31 @@ inline static float vaddvq_f32(float32x4_t v) { return vgetq_lane_f32(v, 0) + vgetq_lane_f32(v, 1) + vgetq_lane_f32(v, 2) + vgetq_lane_f32(v, 3); } -inline float vminvq_f32(float32x4_t v) { +float vminvq_f32(float32x4_t v) { return MIN(MIN(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)), MIN(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3))); } -inline float vmaxvq_f32(float32x4_t v) { +float vmaxvq_f32(float32x4_t v) { return MAX(MAX(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)), MAX(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3))); } -inline int8x8_t vzip1_s8(int8x8_t a, int8x8_t b) { +int8x8_t vzip1_s8(int8x8_t a, int8x8_t b) { return vget_low_s8(vcombine_s8(a, b)); } -inline int8x8_t vzip2_s8(int8x8_t a, int8x8_t b) { +int8x8_t vzip2_s8(int8x8_t a, int8x8_t b) { return vget_high_s8(vcombine_s8(a, b)); } -inline uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) { +uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) { return vget_low_u8(vcombine_u8(a, b)); } -inline uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) { +uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) { return vget_high_u8(vcombine_u8(a, b)); }