diff --git a/.github/actions/build-plugin/action.yaml b/.github/actions/build-plugin/action.yaml index aeede62..03e0e20 100644 --- a/.github/actions/build-plugin/action.yaml +++ b/.github/actions/build-plugin/action.yaml @@ -8,6 +8,10 @@ inputs: description: 'Build configuration' required: false default: 'RelWithDebInfo' + cublas: + description: 'Enable cuBLAS' + required: false + default: 'cpu' codesign: description: 'Enable codesigning (macOS only)' required: false @@ -78,6 +82,7 @@ runs: $BuildArgs = @{ Target = '${{ inputs.target }}' Configuration = '${{ inputs.config }}' + Cublas = '${{ inputs.cublas }}' } .github/scripts/Build-Windows.ps1 @BuildArgs diff --git a/.github/actions/package-plugin/action.yaml b/.github/actions/package-plugin/action.yaml index 5d31e66..d955c37 100644 --- a/.github/actions/package-plugin/action.yaml +++ b/.github/actions/package-plugin/action.yaml @@ -8,6 +8,10 @@ inputs: description: 'Build configuration' required: false default: 'RelWithDebInfo' + cublas: + description: 'Enable cuBLAS' + required: false + default: 'cpu' codesign: description: 'Enable codesigning (macOS only)' required: false @@ -108,6 +112,7 @@ runs: $PackageArgs = @{ Target = '${{ inputs.target }}' Configuration = '${{ inputs.config }}' + Cublas = '${{ inputs.cublas }}' } if ( '${{ inputs.package }}' -eq 'true' ) { diff --git a/.github/scripts/.build.zsh b/.github/scripts/.build.zsh index 708fdcf..f3c3588 100755 --- a/.github/scripts/.build.zsh +++ b/.github/scripts/.build.zsh @@ -230,7 +230,15 @@ ${_usage_host:-}" -DCODESIGN_IDENTITY=${CODESIGN_IDENT:--} ) - cmake_build_args+=(--preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=NO -arch arm64 -arch x86_64) + cmake_build_args+=(--preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=YES) + # check the MACOS_ARCH env var to determine the build architecture + if [[ -n ${MACOS_ARCH} ]] { + cmake_build_args+=(-arch ${MACOS_ARCH}) + } else { + # error out + log_error "No MACOS_ARCH environment variable set. Please set it to the desired architecture." + exit 2 + } cmake_install_args+=(build_macos --config ${config} --prefix "${project_root}/release/${config}") local -a xcbeautify_opts=() diff --git a/.github/scripts/.package.zsh b/.github/scripts/.package.zsh index 076d897..cefb007 100755 --- a/.github/scripts/.package.zsh +++ b/.github/scripts/.package.zsh @@ -168,8 +168,10 @@ ${_usage_host:-}" if [[ ${host_os} == macos ]] { autoload -Uz check_packages read_codesign read_codesign_installer read_codesign_pass + # get the arch from MACOS_ARCH env var + local -r macos_arch=${MACOS_ARCH:-$(uname -m)} - local output_name="${product_name}-${product_version}-${host_os}-universal" + local output_name="${product_name}-${product_version}-${host_os}-${macos_arch}" if [[ ! -d ${project_root}/release/${config}/${product_name}.plugin ]] { log_error 'No release artifact found. Run the build script or the CMake install procedure first.' diff --git a/.github/scripts/Build-Windows.ps1 b/.github/scripts/Build-Windows.ps1 index 2d4c4ca..875ea0a 100644 --- a/.github/scripts/Build-Windows.ps1 +++ b/.github/scripts/Build-Windows.ps1 @@ -4,6 +4,8 @@ param( [string] $Target = 'x64', [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')] [string] $Configuration = 'RelWithDebInfo', + [ValidateSet('cpu', '12.2.0', '11.8.0')] + [string] $Cublas = 'cpu', [switch] $SkipAll, [switch] $SkipBuild, [switch] $SkipDeps, @@ -77,6 +79,13 @@ function Build { '--preset', $Preset ) + if ( $Cublas -ne 'cpu' ) { + $CmakeArgs += @( + '-DLOCALVOCAL_WITH_CUDA=ON', + "-DCUDA_TOOLKIT_ROOT_DIR=$Env:CUDA_TOOLKIT_ROOT_DIR" + ) + } + $CmakeBuildArgs += @( '--build' '--preset', $Preset diff --git a/.github/scripts/Package-Windows.ps1 b/.github/scripts/Package-Windows.ps1 index 52317be..a09f54a 100644 --- a/.github/scripts/Package-Windows.ps1 +++ b/.github/scripts/Package-Windows.ps1 @@ -4,6 +4,8 @@ param( [string] $Target = 'x64', [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')] [string] $Configuration = 'RelWithDebInfo', + [ValidateSet('cpu', '12.2.0', '11.8.0')] + [string] $Cublas = 'cpu', [switch] $BuildInstaller, [switch] $SkipDeps ) @@ -47,8 +49,9 @@ function Package { $BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json $ProductName = $BuildSpec.name $ProductVersion = $BuildSpec.version + $CudaName = "cuda${Cublas}" - $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}" + $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}-${CudaName}" if ( ! $SkipDeps ) { Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile" diff --git a/.github/workflows/build-project.yaml b/.github/workflows/build-project.yaml index c5fc116..d554e05 100644 --- a/.github/workflows/build-project.yaml +++ b/.github/workflows/build-project.yaml @@ -60,6 +60,9 @@ jobs: name: Build for macOS 🍏 runs-on: macos-13 needs: check-event + strategy: + matrix: + architecture: [x86_64, arm64] defaults: run: shell: zsh --no-rcs --errexit --pipefail {0} @@ -114,15 +117,17 @@ jobs: - name: Build Plugin 🧱 uses: ./.github/actions/build-plugin with: - target: macos-universal + target: macos-${{ matrix.architecture }} config: ${{ needs.check-event.outputs.config }} codesign: ${{ fromJSON(needs.check-event.outputs.codesign) }} codesignIdent: ${{ steps.codesign.outputs.codesignIdent }} + env: + MACOS_ARCH: ${{ matrix.architecture }} - name: Package Plugin 📀 uses: ./.github/actions/package-plugin with: - target: macos-universal + target: macos-${{ matrix.architecture }} config: ${{ needs.check-event.outputs.config }} package: ${{ fromJSON(needs.check-event.outputs.package) }} codesign: ${{ fromJSON(needs.check-event.outputs.codesign) && fromJSON(steps.codesign.outputs.haveCodesignIdent) }} @@ -132,19 +137,21 @@ jobs: notarize: ${{ fromJSON(needs.check-event.outputs.notarize) && fromJSON(steps.codesign.outputs.haveNotarizationUser) }} codesignUser: ${{ secrets.MACOS_NOTARIZATION_USERNAME }} codesignPass: ${{ secrets.MACOS_NOTARIZATION_PASSWORD }} + env: + MACOS_ARCH: ${{ matrix.architecture }} - name: Upload Artifacts 📡 uses: actions/upload-artifact@v3 with: - name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-universal-${{ needs.check-event.outputs.commitHash }} - path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-universal.* + name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-${{ matrix.architecture }}-${{ needs.check-event.outputs.commitHash }} + path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-${{ matrix.architecture }}.* - name: Upload Debug Symbol Artifacts 🪲 uses: actions/upload-artifact@v3 if: ${{ needs.check-event.outputs.config == 'Release' }} with: - name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-universal-${{ needs.check-event.outputs.commitHash }}-dSYMs - path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-universal-dSYMs.* + name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-${{ matrix.architecture }}-${{ needs.check-event.outputs.commitHash }}-dSYMs + path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-macos-${{ matrix.architecture }}-dSYMs.* ubuntu-build: name: Build for Ubuntu 🐧 @@ -218,6 +225,9 @@ jobs: name: Build for Windows 🪟 runs-on: windows-2022 needs: check-event + strategy: + matrix: + cublas: [cpu, 12.2.0, 11.8.0] defaults: run: shell: pwsh @@ -227,6 +237,20 @@ jobs: submodules: recursive fetch-depth: 0 + - name: Install CUDA Toolkit + if: ${{ matrix.cublas != 'cpu' }} + id: cuda-toolkit + uses: Jimver/cuda-toolkit@v0.2.11 + with: + cuda: '${{ matrix.cublas }}' + + - name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed + if: ${{ matrix.cublas != 'cpu' }} + run: | + ls "$env:CUDA_PATH\bin" + ls -d 2 "$env:CUDA_PATH\lib" + "CUDA_TOOLKIT_ROOT_DIR=$env:CUDA_PATH" >> $env:GITHUB_ENV + - name: Set Up Environment 🔧 id: setup run: | @@ -247,6 +271,7 @@ jobs: with: target: x64 config: ${{ needs.check-event.outputs.config }} + cublas: ${{ matrix.cublas }} - name: Package Plugin 📀 uses: ./.github/actions/package-plugin @@ -254,9 +279,10 @@ jobs: target: x64 config: ${{ needs.check-event.outputs.config }} package: ${{ fromJSON(needs.check-event.outputs.package) }} + cublas: ${{ matrix.cublas }} - name: Upload Artifacts 📡 uses: actions/upload-artifact@v3 with: - name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-windows-x64-${{ needs.check-event.outputs.commitHash }} + name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-windows-x64-${{ matrix.cublas }}-${{ needs.check-event.outputs.commitHash }} path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-windows-x64*.* diff --git a/cmake/BuildWhispercpp.cmake b/cmake/BuildWhispercpp.cmake index c18a8ca..31e83d0 100644 --- a/cmake/BuildWhispercpp.cmake +++ b/cmake/BuildWhispercpp.cmake @@ -17,8 +17,20 @@ if(UNIX AND NOT APPLE) -DWHISPER_NO_AVX2=ON) endif() if(APPLE) - # disable Metal on MacOS as it hurts performance right now - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_METAL=OFF) + # check the "MACOS_ARCH" env var to figure out if this is x86 or arm64 + if(NOT DEFINED ENV{MACOS_ARCH}) + message(FATAL_ERROR "The MACOS_ARCH environment variable is not set. Please set it to either `x86` or `arm64`") + endif(NOT DEFINED ENV{MACOS_ARCH}) + set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}") + if($ENV{MACOS_ARCH} STREQUAL "x86_64") + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_METAL=OFF -DWHISPER_COREML=OFF -DWHISPER_NO_AVX=OFF + -DWHISPER_NO_AVX2=OFF -DWHISPER_NO_F16C=OFF) + else() + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_METAL=OFF -DWHISPER_COREML=OFF -DWHISPER_NO_AVX=ON -DWHISPER_NO_AVX2=ON + -DWHISPER_NO_F16C=ON -DWHISPER_NO_FMA=ON) + endif() + set(WHISPER_EXTRA_CXX_FLAGS + "-Wno-shorten-64-to-32 -Wno-unused-parameter -Wno-unused-function -Wno-unguarded-availability-new") endif() if(WIN32)