diff --git a/.github/workflows/build_cpp.yml b/.github/workflows/build_cpp.yml index 2ad5559..034605c 100644 --- a/.github/workflows/build_cpp.yml +++ b/.github/workflows/build_cpp.yml @@ -84,9 +84,8 @@ jobs: if-no-files-found: error build-linux: - name: Build for Linux (Ubuntu 18.04 x86_64) - runs-on: ubuntu-latest - container: ubuntu:18.04 + name: Build for Linux (x86_64) + runs-on: ubuntu-20.04 steps: - name: Clone whisper.unity uses: actions/checkout@v3 @@ -99,33 +98,11 @@ jobs: repository: ${{ github.event.inputs.whisper_cpp_repo }} ref: ${{ github.event.inputs.whisper_cpp_repo_ref }} path: whisper-cpp - - - name: Latest Cmake - run: | - apt-get update \ - && apt-get install -y build-essential \ - && apt-get install -y wget \ - && rm -rf /var/lib/apt/lists/* \ - && wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \ - -q -O /tmp/cmake-install.sh \ - && chmod u+x /tmp/cmake-install.sh \ - && mkdir /opt/cmake-3.24.1 \ - && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \ - && rm /tmp/cmake-install.sh \ - && ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin - - - name: Change gcc and g++ - run: | - apt-get update - apt-get install -y gcc-8 g++-8 - name: Run build script run: | cd whisper-unity - sh build_cpp_linux.sh ../whisper-cpp/ - env: - CC: gcc-8 - CXX: g++-8 + sh build_cpp_linux.sh ../whisper-cpp/ cpu - name: Upload results uses: actions/upload-artifact@v3 @@ -133,6 +110,43 @@ jobs: name: linux path: ${{ github.workspace }}/whisper-cpp/build/libwhisper.so if-no-files-found: error + + build-linux-cuda: + name: Build for Linux (x86_64, CUDA) + runs-on: ubuntu-20.04 + steps: + - name: Clone whisper.unity + uses: actions/checkout@v3 + with: + path: whisper-unity + + - name: Clone whisper.cpp + uses: actions/checkout@v3 + with: + repository: ${{ github.event.inputs.whisper_cpp_repo }} + ref: ${{ github.event.inputs.whisper_cpp_repo_ref }} + path: whisper-cpp + + - name: Install CUDA Toolkit + id: cuda-toolkit + uses: Jimver/cuda-toolkit@v0.2.11 + with: + cuda: '12.2.0' + method: 'network' + + - name: Run build script + run: | + cd whisper-unity + sh build_cpp_linux.sh ../whisper-cpp cuda + cd ${{ github.workspace }}/whisper-cpp/build/ + mv libwhisper.so libwhisper_cuda.so + + - name: Upload results + uses: actions/upload-artifact@v3 + with: + name: linux-cuda + path: ${{ github.workspace }}/whisper-cpp/build/libwhisper_cuda.so + if-no-files-found: error build-macos: name: Build for MacOS (ARM, x86_64) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 930db79..78dc1bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - 2019.4.40f1 steps: - uses: actions/checkout@v3 - - uses: game-ci/unity-test-runner@v2 + - uses: game-ci/unity-test-runner@v4 id: tests with: testMode: playmode diff --git a/Packages/com.whisper.unity/Plugins/Linux/libwhisper.so b/Packages/com.whisper.unity/Plugins/Linux/libwhisper.so index 773b466..610ae90 100644 Binary files a/Packages/com.whisper.unity/Plugins/Linux/libwhisper.so and b/Packages/com.whisper.unity/Plugins/Linux/libwhisper.so differ diff --git a/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so b/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so new file mode 100644 index 0000000..326f2f3 Binary files /dev/null and b/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so differ diff --git a/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so.meta b/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so.meta new file mode 100644 index 0000000..b6f8f87 --- /dev/null +++ b/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so.meta @@ -0,0 +1,63 @@ +fileFormatVersion: 2 +guid: 39a6ea3cc1aa3eebdb8d16dc05db5cf8 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 0 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Linux + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.whisper.unity/Runtime/Native/WhisperNative.cs b/Packages/com.whisper.unity/Runtime/Native/WhisperNative.cs index c36f9a0..5cd544a 100644 --- a/Packages/com.whisper.unity/Runtime/Native/WhisperNative.cs +++ b/Packages/com.whisper.unity/Runtime/Native/WhisperNative.cs @@ -14,13 +14,19 @@ public static unsafe class WhisperNative { #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR - private const string LibraryName = "__Internal"; -#else -#if UNITY_STANDALONE_WIN && WHISPER_CUDA + private const string LibraryName = "__Internal"; +#elif WHISPER_CUDA + +#if (UNITY_EDITOR && (UNITY_EDITOR_WIN || UNITY_EDITOR_LINUX)) + private const string LibraryName = "libwhisper_cuda"; +#elif (!UNITY_EDITOR && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX)) private const string LibraryName = "libwhisper_cuda"; #else private const string LibraryName = "libwhisper"; #endif + +#else + private const string LibraryName = "libwhisper"; #endif [DllImport(LibraryName)] diff --git a/README.md b/README.md index d5034d5..c6e7738 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ This is Unity3d bindings for the [whisper.cpp](https://github.com/ggerganov/whis **Supported platforms:** - [x] Windows (x86_64, [optional CUDA](#cuda-support)) - [x] MacOS (Intel and ARM) +- [x] Linux (x86_64, [optional CUDA](#cuda-support)) - [x] iOS (Device and Simulator) - [x] Android (ARM64) -- [x] Linux (x86_64, Ubuntu 18.04 and newer) - [ ] WebGL (see [this issue](https://github.com/Macoron/whisper.unity/issues/20)) ## Samples @@ -70,7 +70,7 @@ sh build_cpp.sh path/to/whisper all path/to/ndk/android.toolchain.cmake ``` 6. If you are using **Linux** write ```bash -sh build_cpp_linux.sh path/to/whisper +sh build_cpp_linux.sh path/to/whisper cpu ``` 7. If build was successful compiled libraries should be automatically update package `Plugins` folder. diff --git a/build_cpp_linux.sh b/build_cpp_linux.sh index f541faf..f1548ec 100644 --- a/build_cpp_linux.sh +++ b/build_cpp_linux.sh @@ -11,15 +11,15 @@ clean_build(){ cd "$build_path" } -build_linux() { +build_cpu() { clean_build - echo "Starting building for Linux..." + echo "Starting building for CPU..." cmake -DCMAKE_BUILD_TYPE=Release \ -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF ../ make - echo "Build for Linux complete!" + echo "Build for CPU complete!" artifact_path="$build_path/libwhisper.so" target_path="$unity_project/Packages/com.whisper.unity/Plugins/Linux/libwhisper.so" @@ -28,4 +28,30 @@ build_linux() { echo "Build files copied to $target_path" } -build_linux \ No newline at end of file +build_cuda() { + clean_build + echo "Starting building for CUDA..." + + cmake -DWHISPER_CUBLAS=ON -DCMAKE_BUILD_TYPE=Release \ + -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF ../ + make + + echo "Build for CUDA complete!" + + artifact_path="$build_path/libwhisper.so" + target_path="$unity_project/Packages/com.whisper.unity/Plugins/Linux/libwhisper_cuda.so" + cp "$artifact_path" "$target_path" + + echo "Build files copied to $target_path" +} + +if [ "$targets" = "all" ]; then + build_cpu + build_cuda +elif [ "$targets" = "cpu" ]; then + build_cpu +elif [ "$targets" = "cuda" ]; then + build_cuda +else + echo "Unknown targets: $targets" +fi