diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77c901fa..b43a174a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/Package.swift b/Package.swift index 367ce03b..303ed0d7 100644 --- a/Package.swift +++ b/Package.swift @@ -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 index 00000000..a266c0f2 --- /dev/null +++ b/Sources/whisper/module.modulemap @@ -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 index 00000000..e503c8a3 --- /dev/null +++ b/Sources/whisper/whisper.h @@ -0,0 +1,4 @@ +#pragma once + +#include + diff --git a/cmake/whisper.pc.in b/cmake/whisper.pc.in index 50ab4f82..00ec7912 100644 --- a/cmake/whisper.pc.in +++ b/cmake/whisper.pc.in @@ -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} diff --git a/examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt b/examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt index 1243d732..8dd106f0 100644 --- a/examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt +++ b/examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt @@ -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. diff --git a/examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj b/examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj index 11447909..fcf06141 100644 --- a/examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj +++ b/examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj @@ -363,7 +363,7 @@ 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; @@ -417,7 +417,7 @@ 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; diff --git a/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift b/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift index 125be4f8..3c769e7a 100644 --- a/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift +++ b/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift @@ -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) {