Skip to content

Commit

Permalink
Merge pull request #6 from locaal-ai/roy.bump_whisper_cpp_add_vulkan
Browse files Browse the repository at this point in the history
Update build scripts to include Vulkan SDK installation for Linux and…
  • Loading branch information
royshil authored Oct 10, 2024
2 parents 77e8a07 + fa96845 commit 1708140
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 20 deletions.
36 changes: 29 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ jobs:
path: "*.tar.gz"

BuildLinux:
if: false
runs-on: "ubuntu-22.04"

strategy:
matrix:
config:
- "Release"
accel: [cpu, vulkan]

defaults:
run:
Expand All @@ -78,12 +78,25 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Install Vulkan SDK"
if: ${{ matrix.accel == 'vulkan' }}
run: |
sudo apt-get update
sudo apt-get install -y wget
wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list http://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
sudo apt update
sudo apt install vulkan-sdk
- name: "Run build-linux.sh"
run: "./build-linux.sh ${{ matrix.config }} ${{ steps.get-version.outputs.version }}"
run: "chmod +x build-linux.sh && ./build-linux.sh ${{ matrix.config }} ${{ steps.get-version.outputs.version }}"
env:
BUILD_WITH_ACCEL: ${{ matrix.accel }}
LINUX_ARCH: "x86_64"

- uses: "actions/upload-artifact@v4"
with:
name: "whispercpp-linux-${{ matrix.config }}"
name: "whispercpp-linux-${{ matrix.config }}-${{ matrix.accel }}"
path: "*.tar.gz"

BuildWindows:
Expand All @@ -93,7 +106,7 @@ jobs:
matrix:
config:
- "Release"
accel: [cpu, cuda, hipblas]
accel: [cpu, cuda, vulkan, hipblas]

steps:
- name: "Get version"
Expand Down Expand Up @@ -145,6 +158,16 @@ jobs:
run: |
"HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)" >> $env:GITHUB_ENV
- name: "Install Vulkan SDK"
if: ${{ matrix.accel == 'vulkan' }}
run: |
$ErrorActionPreference = "Stop"
write-host "Downloading Vulkan SDK"
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/1.3.296.0/windows/VulkanSDK-1.3.296.0-Installer.exe" -OutFile "${env:RUNNER_TEMP}\VulkanSDK-1.3.296.0-Installer.exe"
write-host "Installing Vulkan SDK"
Start-Process "${env:RUNNER_TEMP}\VulkanSDK-1.3.296.0-Installer.exe" -ArgumentList '--accept-licenses --default-answer --confirm-command install' -NoNewWindow -Wait
write-host "Completed Vulkan SDK installation"
- name: "Run Build-Windows.ps1"
run: "./Build-Windows.ps1 -Version ${{ steps.get-version.outputs.version }}"
env:
Expand All @@ -157,12 +180,11 @@ jobs:

Release:
runs-on: "ubuntu-22.04"

if: "github.event_name == 'push' && contains(github.ref, 'refs/tags/')"
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')

needs:
- "BuildMac"
# - "BuildLinux"
- "BuildLinux"
- "BuildWindows"

permissions:
Expand Down
42 changes: 30 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option(WHISPERCPP_WITH_HIPBLAS "Build Whisper with hipBLAS support" OFF)

set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}")

set(Whispercpp_Build_GIT_TAG "c4e1861d2c24b186cbbac6c07480aaa298b0e6d9")
set(Whispercpp_Build_GIT_TAG "fdbfb460ed546452a5d53611bba66d10d842e719")

if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL
RelWithDebInfo)
Expand All @@ -22,7 +22,11 @@ endif()
if(UNIX AND NOT APPLE)
# On linux add the `-fPIC` flag to the compiler
set(WHISPER_EXTRA_CXX_FLAGS "-fPIC")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=OFF)
if(WHISPERCPP_WITH_VULKAN)
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=OFF -DGGML_VULKAN=ON)
else()
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=OFF)
endif()
endif()
if(APPLE)
# check the "MACOS_ARCH" env var to figure out if this is x86_64 or arm64
Expand All @@ -45,6 +49,17 @@ if(WIN32)
set(WHISPER_ADDITIONAL_ENV "")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON)
set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR})
elseif(WHISPERCPP_WITH_VULKAN)
if(NOT DEFINED ENV{VULKAN_SDK_PATH})
message(
FATAL_ERROR
"VULKAN_SDK_PATH is not set. Please set it to the root directory of your VulkanSDK installation, e.g. `C:/VulkanSDK/1.3.296.0`"
)
endif()
# Build with VULKAN
set(WHISPER_ADDITIONAL_ENV "VULKAN_SDK=$ENV{VULKAN_SDK_PATH}")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_VULKAN=ON)
set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR})
elseif(WHISPERCPP_WITH_HIPBLAS)
# Build with hipBLAS
if(NOT DEFINED ENV{HIP_PATH})
Expand Down Expand Up @@ -150,22 +165,16 @@ if(WIN32)
DESTINATION ${CMAKE_SOURCE_DIR}/release)
install(DIRECTORY ${INSTALL_DIR}/bin DESTINATION ${CMAKE_SOURCE_DIR}/release)

if(NOT WHISPERCPP_WITH_CUDA AND NOT WHISPERCPP_WITH_HIPBLAS)
# add openblas to the link line
install(DIRECTORY ${OpenBLAS_DIR}/lib
DESTINATION ${CMAKE_SOURCE_DIR}/release)
install(DIRECTORY ${OpenBLAS_DIR}/include
DESTINATION ${CMAKE_SOURCE_DIR}/release)
install(DIRECTORY ${OpenBLAS_DIR}/bin
DESTINATION ${CMAKE_SOURCE_DIR}/release)
elseif(WHISPERCPP_WITH_HIPBLAS)
if(WHISPERCPP_WITH_HIPBLAS)
message(STATUS "Setup HIP DLLs installation")
set(HIPBLAS_DLLS
"${HIP_PATH_STR}/bin/hipblas.dll" "${HIP_PATH_STR}/bin/rocblas.dll"
"${HIP_PATH_STR}/bin/amdhip64_6.dll"
"${HIP_PATH_STR}/bin/amd_comgr_2.dll")
install(FILES ${HIPBLAS_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin)
else()
elseif(WHISPERCPP_WITH_VULKAN)
message(STATUS "Vulkan does not require DLLs copy")
elseif(WHISPERCPP_WITH_CUDA)
# Check that CUDA_TOOLKIT_ROOT_DIR is set
if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR)
message(
Expand Down Expand Up @@ -196,6 +205,15 @@ if(WIN32)
# copy the DLLs to the OBS plugin directory
install(FILES ${CUBLAS_DLLS} ${CUBLASLT_DLLS} ${CUDART_DLLS}
DESTINATION ${CMAKE_SOURCE_DIR}/release/bin)
else()
message(STATUS "Install OpenBLAS DLLs")
# add openblas to the link line
install(DIRECTORY ${OpenBLAS_DIR}/lib
DESTINATION ${CMAKE_SOURCE_DIR}/release)
install(DIRECTORY ${OpenBLAS_DIR}/include
DESTINATION ${CMAKE_SOURCE_DIR}/release)
install(DIRECTORY ${OpenBLAS_DIR}/bin
DESTINATION ${CMAKE_SOURCE_DIR}/release)
endif()
else()
# copy lib/ include/ and bin/ from ${INSTALL_DIR} to the release directory in
Expand Down
24 changes: 24 additions & 0 deletions build-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Description: Build script for linux
#!/bin/bash

# get version from first argument
version=$1

# check env var BUILD_WITH_ACCEL
if [ "$BUILD_WITH_ACCEL" = "vulkan" ]; then
echo "Building with acceleration"
export CMAKE_ARGS="$CMAKE_ARGS -DWHISPERCPP_WITH_VULKAN=ON"
else
echo "Building without acceleration"
fi

# configure
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release $CMAKE_ARGS

cmake --build build --config Release

# install
cmake --install build

# compress the release folder
tar -czvf whispercpp-linux-$LINUX_ARCH-$version.tar.gz release
11 changes: 10 additions & 1 deletion build-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Param(

# check env var BUILD_WITH_ACCEL
if ($env:BUILD_WITH_ACCEL -eq $null) {
Write-Host "Please set env var BUILD_WITH_ACCEL to 'cpu', 'cuda' or 'hipblas'."
Write-Host "Please set env var BUILD_WITH_ACCEL to 'cpu', 'cuda', 'vulkan' or 'hipblas'."
exit
}

Expand All @@ -23,6 +23,15 @@ if ($env:BUILD_WITH_ACCEL -eq "cpu") {
"-DCMAKE_CXX_COMPILER='$env:HIP_PATH\bin\clang++.exe'")
$zipFileName = "whispercpp-windows-hipblas-$Version.zip"
$env:HIP_PLATFORM="amd"
} elseif ($env:BUILD_WITH_ACCEL -eq "vulkan") {
$cmakeArgs += (
"-DWHISPERCPP_WITH_VULKAN=ON",
"-DCMAKE_GENERATOR=Visual Studio 17 2022"
)
$zipFileName = "whispercpp-windows-vulkan-$Version.zip"
# find the Vulkan SDK version path in C:\VulkanSDK\
$vulkanSdkPath = Get-ChildItem -Path "C:\VulkanSDK" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$env:VULKAN_SDK_PATH="$vulkanSdkPath"
} else {
$cmakeArgs += (
"-DWHISPERCPP_WITH_CUDA=ON",
Expand Down

0 comments on commit 1708140

Please sign in to comment.