]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
ci : disable Obj-C build + fixes
authorGeorgi Gerganov <redacted>
Sun, 8 Dec 2024 11:35:35 +0000 (13:35 +0200)
committerGeorgi Gerganov <redacted>
Sun, 8 Dec 2024 18:14:35 +0000 (20:14 +0200)
.github/workflows/build.yml
Package.swift
Sources/whisper/module.modulemap [new file with mode: 0644]
Sources/whisper/whisper.h [new file with mode: 0644]
cmake/whisper.pc.in
examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt
examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj
examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift

index 77c901faaf198822b87cbda9d225fb4aa691f0cb..b43a174a9d55afc6d96ef74b633c66810f17a297 100644 (file)
@@ -518,7 +518,7 @@ jobs:
           emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }}
           make
 
-  ios:
+  ios-xcode-build:
     runs-on: macos-latest
 
     strategy:
@@ -526,7 +526,7 @@ jobs:
         build: [Release]
 
     steps:
-      - name: Clone
+      - name: Checkout code
         uses: actions/checkout@v4
 
       - name: Configure
@@ -534,11 +534,34 @@ jobs:
           cp models/for-tests-ggml-base.en.bin models/ggml-base.en.bin
           mkdir models/ggml-base.en-encoder.mlmodelc
 
-      - name: Build objc example
-        run: xcodebuild -project examples/whisper.objc/whisper.objc.xcodeproj -scheme whisper.objc -configuration ${{ matrix.build }} -sdk iphonesimulator build
+      - name: Build
+        id: cmake_build
+        run: |
+          sysctl -a
+          mkdir build
+          cd build
+          cmake -G Xcode .. \
+            -DGGML_METAL_USE_BF16=ON \
+            -DGGML_METAL_EMBED_LIBRARY=ON \
+            -DWHISPER_BUILD_EXAMPLES=OFF \
+            -DWHISPER_BUILD_TESTS=OFF \
+            -DWHISPER_BUILD_SERVER=OFF \
+            -DCMAKE_SYSTEM_NAME=iOS \
+            -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
+            -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
+          cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
+          sudo cmake --install . --config Release
+
+      - name: xcodebuild for swift package
+        id: xcodebuild
+        run: |
+          xcodebuild -scheme whisper-Package -destination 'generic/platform=iOS'
+
+#- name: Build objc example
+#  run: xcodebuild -project examples/whisper.objc/whisper.objc.xcodeproj -scheme whisper.objc -configuration ${{ matrix.build }} -sdk iphoneos build
 
       - name: Build swiftui example
-        run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk iphonesimulator build
+        run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk iphoneos CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= -destination 'generic/platform=iOS' build
 
   android:
     runs-on: ubuntu-latest
index 367ce03b5a3b3fab9ef6ce13de46afa998ba6a6c..303ed0d78fbd73ebcad2dde562d1e377d6d8dcf4 100644 (file)
@@ -14,55 +14,6 @@ let package = Package(
         .library(name: "whisper", targets: ["whisper"]),
     ],
     targets: [
-        .target(
-            name: "whisper",
-            path: ".",
-            exclude: [
-               "build",
-               "bindings",
-               "cmake",
-               "examples",
-               "scripts",
-               "models",
-               "samples",
-               "tests",
-               "CMakeLists.txt",
-               "Makefile",
-               "ggml/src/ggml-metal/ggml-metal-embed.metal"
-            ],
-            sources: [
-                "ggml/src/ggml.c",
-                "src/whisper.cpp",
-                "ggml/src/ggml-aarch64.c",
-                "ggml/src/ggml-alloc.c",
-                "ggml/src/ggml-backend.cpp",
-                "ggml/src/ggml-backend-reg.cpp",
-                "ggml/src/ggml-cpu/ggml-cpu.c",
-                "ggml/src/ggml-cpu/ggml-cpu.cpp",
-                "ggml/src/ggml-cpu/ggml-cpu-aarch64.c",
-                "ggml/src/ggml-cpu/ggml-cpu-quants.c",
-                "ggml/src/ggml-quants.c",
-                "ggml/src/ggml-threading.cpp",
-                "ggml/src/ggml-metal/ggml-metal.m"
-            ],
-            resources: [.process("ggml/src/ggml-metal/ggml-metal.metal")],
-            publicHeadersPath: "spm-headers",
-            cSettings: [
-                .unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
-                .unsafeFlags(["-fno-objc-arc"]),
-                .headerSearchPath("ggml/src"),
-                .define("GGML_USE_ACCELERATE"),
-                .define("GGML_USE_METAL")
-                // NOTE: NEW_LAPACK will required iOS version 16.4+
-                // We should consider add this in the future when we drop support for iOS 14
-                // (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
-                // .define("ACCELERATE_NEW_LAPACK"),
-                // .define("ACCELERATE_LAPACK_ILP64")
-            ],
-            linkerSettings: [
-                .linkedFramework("Accelerate")
-            ]
-        )
-    ],
-    cxxLanguageStandard: .cxx11
+        .systemLibrary(name: "whisper", pkgConfig: "whisper"),
+    ]
 )
diff --git a/Sources/whisper/module.modulemap b/Sources/whisper/module.modulemap
new file mode 100644 (file)
index 0000000..a266c0f
--- /dev/null
@@ -0,0 +1,5 @@
+module whisper [system] {
+    header "whisper.h"
+    link "whisper"
+    export *
+}
diff --git a/Sources/whisper/whisper.h b/Sources/whisper/whisper.h
new file mode 100644 (file)
index 0000000..e503c8a
--- /dev/null
@@ -0,0 +1,4 @@
+#pragma once
+
+#include <whisper.h>
+
index 50ab4f8285adeb84c02bcd40b3d732a06be29a4a..00ec7912014c02defe39add37a4b92adc3ea0afa 100644 (file)
@@ -1,10 +1,10 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=${prefix}
-libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+libdir=${exec_prefix}/lib
 includedir=${prefix}/include
 
 Name: whisper
 Description: Port of OpenAI's Whisper model in C/C++
 Version: @PROJECT_VERSION@
-Libs: -L${libdir} -lwhisper
+Libs: -L${libdir} -lggml  -lggml-base -lwhisper
 Cflags: -I${includedir}
index 1243d732c349842238e108697fa96d09326d63e4..8dd106f075a7b02c1b92347e1006e387d3a95cc4 100644 (file)
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
 
 project(whisper.cpp)
 
-set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD 17)
 set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../..)
 
 # Path to external GGML, otherwise uses the copy in whisper.cpp.
index 114479096953a6d80cbda45e34f7cab0c9b5ae92..fcf0614179e51129804ba82497c46220c5c7125b 100644 (file)
                                GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
                                GCC_WARN_UNUSED_FUNCTION = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
-                               HEADER_SEARCH_PATHS = "";
+                               HEADER_SEARCH_PATHS = ../../../ggml/src/;
                                IPHONEOS_DEPLOYMENT_TARGET = 16.0;
                                MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
                                MTL_FAST_MATH = YES;
                                GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
                                GCC_WARN_UNUSED_FUNCTION = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
-                               HEADER_SEARCH_PATHS = "";
+                               HEADER_SEARCH_PATHS = ../../../ggml/src/;
                                IPHONEOS_DEPLOYMENT_TARGET = 16.0;
                                MTL_ENABLE_DEBUG_INFO = NO;
                                MTL_FAST_MATH = YES;
index 125be4f881ca6cdcea35a289c2c0787877ea16db..3c769e7af8e3125e4124088ee0ba8b8b2abb7c3a 100644 (file)
@@ -66,7 +66,7 @@ actor WhisperContext {
 
     private func systemInfo() -> String {
         var info = ""
-        if (ggml_cpu_has_neon() != 0) { info += "NEON " }
+        //if (ggml_cpu_has_neon() != 0) { info += "NEON " }
         return String(info.dropLast())
     }
 
@@ -75,45 +75,45 @@ actor WhisperContext {
         if (whisper_set_mel(context, nil, 0, nMels) != 0) {
             return "error: failed to set mel"
         }
-        
+
         // heat encoder
         if (whisper_encode(context, 0, nThreads) != 0) {
             return "error: failed to encode"
         }
-        
+
         var tokens = [whisper_token](repeating: 0, count: 512)
-        
+
         // prompt heat
         if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) {
             return "error: failed to decode"
         }
-        
+
         // text-generation heat
         if (whisper_decode(context, &tokens, 1, 256, nThreads) != 0) {
             return "error: failed to decode"
         }
-        
+
         whisper_reset_timings(context)
-        
+
         // actual run
         if (whisper_encode(context, 0, nThreads) != 0) {
             return "error: failed to encode"
         }
-        
+
         // text-generation
         for i in 0..<256 {
             if (whisper_decode(context, &tokens, 1, Int32(i), nThreads) != 0) {
                 return "error: failed to decode"
             }
         }
-        
+
         // batched decoding
         for _ in 0..<64 {
             if (whisper_decode(context, &tokens, 5, 0, nThreads) != 0) {
                 return "error: failed to decode"
             }
         }
-        
+
         // prompt processing
         for _ in 0..<16 {
             if (whisper_decode(context, &tokens, 256, 0, nThreads) != 0) {