Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable MacOS ARM64 and Windows CUDA builds #76

Merged
merged 16 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/build-plugin/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,6 +82,7 @@ runs:
$BuildArgs = @{
Target = '${{ inputs.target }}'
Configuration = '${{ inputs.config }}'
Cublas = '${{ inputs.cublas }}'
}

.github/scripts/Build-Windows.ps1 @BuildArgs
Expand Down
5 changes: 5 additions & 0 deletions .github/actions/package-plugin/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +112,7 @@ runs:
$PackageArgs = @{
Target = '${{ inputs.target }}'
Configuration = '${{ inputs.config }}'
Cublas = '${{ inputs.cublas }}'
}

if ( '${{ inputs.package }}' -eq 'true' ) {
Expand Down
10 changes: 9 additions & 1 deletion .github/scripts/.build.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand Down
4 changes: 3 additions & 1 deletion .github/scripts/.package.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
9 changes: 9 additions & 0 deletions .github/scripts/Build-Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/scripts/Package-Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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"
Expand Down
40 changes: 33 additions & 7 deletions .github/workflows/build-project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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) }}
Expand All @@ -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 🐧
Expand Down Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -247,16 +271,18 @@ jobs:
with:
target: x64
config: ${{ needs.check-event.outputs.config }}
cublas: ${{ matrix.cublas }}

- name: Package Plugin 📀
uses: ./.github/actions/package-plugin
with:
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*.*
16 changes: 14 additions & 2 deletions cmake/BuildWhispercpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading