Skip to content

Commit b93277e

Browse files
authored
Acceleration improvements and fixes (#241)
* Update Whisper.cpp and add Linux acceleration (source builds only) Update Whisper.cpp from v1.6.2 to v1.8.1 Supported Linux acceleration methods: * CUDA * hipblas * Vulkan * OpenCL If suitable development libraries are installed for any of the above when building from source, then support for them will be built into both whisper.cpp and the LocalVocal plugin * Test behaviour with combinations of multiple backends * Use found dependencies to decide which acceleration features to enable Also try to build Whispercpp from source on Windows with acceleration (not working) * Add GPU device selection option in plugin settings Allows the selection of which GPU backend to use if more than one is available, as well as disabling GPU backends in case the only available ones don't work or are somehow slower than the CPU alone * Add OpenCL support for Linux source build * Comment out seemingly unused DISABLE_ONNX_RUNTIME_GPU option * Update prebuilt Whisper deps to 0.0.9 (Whisper 1.8.2) and refactor cmake file * Handle new GGML IGPU device type * Bump whisper deps to 0.0.9-1 to fix hipblas * Try to avoid running apt in CI when packages are cached * Add option to enable/disable flash attention * Install Vulkan SDK properly for CI build and try adding OpenCL and hip dev libs * Build with shared libs on linux and allow use of dynamic backends * Update deps to 0.0.10 (runtime module linking/importing is likely broken) * Update deps to 0.0.10-2; try to fix linking & other platform specific issues * Bump version number to 0.5.0 * Fix Ubuntu packaging * Fix dynamic linking on MacOS * Update README * Cleanup CMake files a bit and make prebuilt build on Linux the default over full source build * Fix Linux full source build
1 parent c8dbe1c commit b93277e

37 files changed

Lines changed: 1045 additions & 298 deletions

.github/actions/build-plugin/action.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ inputs:
1111
acceleration:
1212
description: 'Enable acceleration'
1313
required: false
14-
default: 'cpu'
14+
default: 'generic'
1515
codesign:
1616
description: 'Enable codesigning (macOS only)'
1717
required: false
@@ -59,6 +59,8 @@ runs:
5959
if: runner.os == 'Linux'
6060
shell: zsh --no-rcs --errexit --pipefail {0}
6161
working-directory: ${{ inputs.workingDirectory }}
62+
env:
63+
ACCELERATION: ${{ inputs.acceleration }}
6264
run: |
6365
: Run Ubuntu Build
6466

.github/scripts/.Aptfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package 'libicu-dev'
77
package 'libopenblas-dev'
88
package 'libopenblas-openmp-dev'
99
package 'libsimde-dev'
10-
package 'libvulkan-dev'
1110
package 'ninja-build', bin: 'ninja'
11+
package 'nvidia-opencl-dev'
12+
package 'ocl-icd-opencl-dev'
13+
package 'opencl-headers'
1214
package 'pkg-config'

.github/scripts/.build.zsh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ build() {
6565
linux-aarch64
6666
)
6767
local target
68-
local config='RelWithDebInfo'
68+
if [[ "${+ACCELERATION}" == "amd" ]]
69+
then
70+
local config='Release'
71+
else
72+
local config='RelWithDebInfo'
73+
fi
6974
local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel)
7075
local -i codesign=0
7176

@@ -184,7 +189,7 @@ ${_usage_host:-}"
184189
setup_ccache
185190
}
186191

187-
if [[ ${host_os} == linux ]] {
192+
if [[ ${host_os} == linux && ("$(lsb_release -i)" == "Distributor ID: Ubuntu") ]] {
188193
autoload -Uz setup_linux && setup_linux
189194
}
190195

@@ -230,7 +235,7 @@ ${_usage_host:-}"
230235
-DCODESIGN_IDENTITY=${CODESIGN_IDENT:--}
231236
)
232237
233-
cmake_build_args+=(--preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=YES)
238+
cmake_build_args+=(--verbose --preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=YES)
234239
# check the MACOS_ARCH env var to determine the build architecture
235240
if [[ -n ${MACOS_ARCH} ]] {
236241
cmake_build_args+=(-arch ${MACOS_ARCH})

.github/scripts/.package.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ ${_usage_host:-}"
256256
popd
257257
} else {
258258
log_group "Archiving ${product_name}..."
259-
local output_name="${product_name}-${product_version}-${target##*-}-linux-gnu"
259+
local output_name="${product_name}-${product_version}-${target##*-}-${+ACCELERATION}-linux-gnu"
260260
local _tarflags='cJf'
261261
if (( _loglevel > 1 || ${+CI} )) _tarflags="v${_tarflags}"
262262

.github/scripts/Package-Windows.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ param(
44
[string] $Target = 'x64',
55
[ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
66
[string] $Configuration = 'RelWithDebInfo',
7-
[ValidateSet('cpu', 'hipblas', 'vulkan', 'cuda')]
8-
[string] $Acceleration = 'cpu',
7+
[ValidateSet('generic', 'nvidia', 'amd')]
8+
[string] $Acceleration = 'generic',
99
[switch] $BuildInstaller,
1010
[switch] $SkipDeps
1111
)

.github/scripts/utils.zsh/check_linux

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,42 @@ if [[ -f /etc/os_release ]] {
1818

1919
log_debug 'Checking for apt-get...'
2020
if (( ! ${+commands[apt-get]} )) {
21-
log_error 'No apt-get command found. Please install apt'
22-
return 2
21+
log_warning 'No apt-get command found. Please ensure all dependencies are correctly installed'
2322
} else {
2423
log_debug "Apt-get located at ${commands[apt-get]}"
25-
}
2624

27-
local -a dependencies=("${(fA)$(<${SCRIPT_HOME}/.Aptfile)}")
28-
local -a install_list
29-
local binary
25+
local -a dependencies=("${(fA)$(<${SCRIPT_HOME}/.Aptfile)}")
26+
local -a install_list
27+
local binary
3028

31-
sudo apt-get update -qq
29+
sudo apt-get update -qq
3230

33-
for dependency (${dependencies}) {
34-
local -a tokens=(${=dependency//(,|:|\')/})
31+
for dependency (${dependencies}) {
32+
local -a tokens=(${=dependency//(,|:|\')/})
3533

36-
if [[ ! ${tokens[1]} == 'package' ]] continue
34+
if [[ ! ${tokens[1]} == 'package' ]] continue
3735

38-
if [[ ${#tokens} -gt 2 && ${tokens[3]} == 'bin' ]] {
39-
binary=${tokens[4]}
40-
} else {
41-
binary=${tokens[2]}
42-
}
36+
if [[ ${#tokens} -gt 2 && ${tokens[3]} == 'bin' ]] {
37+
binary=${tokens[4]}
38+
} else {
39+
binary=${tokens[2]}
40+
}
4341

44-
if (( ! ${+commands[${binary}]} )) install_list+=(${tokens[2]})
45-
}
42+
if (( ! ${+commands[${binary}]} )) install_list+=(${tokens[2]})
43+
}
4644

47-
log_debug "List of dependencies to install: ${install_list}"
48-
if (( ${#install_list} )) {
49-
if (( ! ${+CI} )) log_warning 'Dependency installation via apt may require elevated privileges'
45+
log_debug "List of dependencies to install: ${install_list}"
46+
if (( ${#install_list} )) {
47+
if (( ! ${+CI} )) log_warning 'Dependency installation via apt may require elevated privileges'
5048

51-
local -a apt_args=(
52-
${CI:+-y}
53-
--no-install-recommends
54-
)
55-
if (( _loglevel == 0 )) apt_args+=(--quiet)
49+
local -a apt_args=(
50+
${CI:+-y}
51+
--no-install-recommends
52+
)
53+
if (( _loglevel == 0 )) apt_args+=(--quiet)
5654

57-
sudo apt-get ${apt_args} install ${install_list}
55+
sudo apt-get ${apt_args} install ${install_list}
56+
}
5857
}
5958

6059
rehash

.github/workflows/build-project.yaml

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,42 @@ jobs:
202202
name: Build for Ubuntu 🐧
203203
runs-on: ubuntu-22.04
204204
needs: check-event
205+
strategy:
206+
matrix:
207+
acceleration: [generic, nvidia, amd]
205208
defaults:
206209
run:
207210
shell: bash
211+
env:
212+
CI: 1
208213
steps:
214+
- name: Free Disk Space (Ubuntu)
215+
if: ${{ matrix.acceleration == 'amd' || matrix.acceleration == 'nvidia' }}
216+
uses: jlumbroso/free-disk-space@main
217+
with:
218+
# this might remove tools that are actually needed,
219+
# if set to "true" but frees about 6 GB
220+
tool-cache: false
221+
# Needs to be false to prevent running out of memory
222+
swap-storage: false
223+
# large-packages takes a long time so don't remove them unless we need to
224+
large-packages: false
225+
226+
android: true
227+
dotnet: true
228+
haskell: true
229+
docker-images: true
230+
209231
- uses: actions/checkout@v4
210232
with:
211233
submodules: recursive
212234
fetch-depth: 0
235+
236+
- name: "Setup additional apt repos, keys and pre-requisites"
237+
run: |
238+
wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
239+
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list http://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
240+
sudo apt update
213241
214242
- uses: awalsh128/cache-apt-pkgs-action@v1.6.0
215243
with:
@@ -218,17 +246,25 @@ jobs:
218246
libcurl4-openssl-dev
219247
libicu-dev
220248
libgles2-mesa-dev
249+
libopenblas0
250+
libopenblas0-openmp
251+
libopenblas0-pthread
221252
libopenblas-dev
222253
libopenblas-openmp-dev
223254
libqt6svg6-dev
224255
libsimde-dev
225-
libvulkan-dev
256+
nvidia-opencl-dev
226257
obs-studio
258+
ocl-icd-opencl-dev
227259
pkg-config
260+
python3-setuptools
261+
python3-wheel
228262
qt6-base-dev
229263
qt6-base-private-dev
264+
vulkan-sdk
230265
add-repository: ppa:obsproject/obs-studio
231266
version: 1.0
267+
execute_install_scripts: true
232268

233269
- name: Set Up Environment 🔧
234270
id: setup
@@ -244,6 +280,29 @@ jobs:
244280
245281
- uses: actions-rust-lang/setup-rust-toolchain@v1
246282

283+
# CUDA toolkit needed for linking against so it can be found when looking up package dependencies
284+
- name: "Install CUDA toolkit 12.8"
285+
if: ${{ matrix.acceleration == 'nvidia' }}
286+
run: |
287+
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
288+
sudo dpkg -i cuda-keyring_1.1-1_all.deb
289+
sudo apt update
290+
sudo apt -y install cuda-12-8
291+
export PATH=/usr/local/cuda-12.8/bin${PATH:+:${PATH}}
292+
export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
293+
294+
# hip SDK needed for linking against so it can be found when looking up package dependencies
295+
- name: "Install AMD hip SDK v6.4.2"
296+
if: ${{ matrix.acceleration == 'amd' }}
297+
run: |
298+
wget https://repo.radeon.com/amdgpu-install/6.4.2/ubuntu/jammy/amdgpu-install_6.4.60402-1_all.deb
299+
sudo apt install ./amdgpu-install_6.4.60402-1_all.deb
300+
sudo apt update
301+
sudo apt install python3-setuptools python3-wheel
302+
sudo usermod -a -G render,video $LOGNAME # Add the current user to the render and video groups
303+
sudo apt install rocm
304+
sudo apt update && sudo apt install hipblas
305+
247306
- uses: actions/cache@v4
248307
id: ccache-cache
249308
with:
@@ -260,6 +319,7 @@ jobs:
260319
with:
261320
target: x86_64
262321
config: ${{ needs.check-event.outputs.config }}
322+
acceleration: ${{ matrix.acceleration }}
263323

264324
- name: Package Plugin 📀
265325
uses: ./.github/actions/package-plugin
@@ -271,29 +331,29 @@ jobs:
271331
- name: Upload Source Tarball 🗜️
272332
uses: actions/upload-artifact@v4
273333
with:
274-
name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-sources-${{ needs.check-event.outputs.commitHash }}
275-
path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-source.*
334+
name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-${{ matrix.acceleration }}-sources-${{ needs.check-event.outputs.commitHash }}
335+
path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-${{ matrix.acceleration }}-source.*
276336

277337
- name: Upload Artifacts 📡
278338
uses: actions/upload-artifact@v4
279339
with:
280-
name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-ubuntu-22.04-x86_64-${{ needs.check-event.outputs.commitHash }}
281-
path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-x86_64*.*
340+
name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-${{ matrix.acceleration }}-ubuntu-22.04-x86_64-${{ needs.check-event.outputs.commitHash }}
341+
path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-${{ matrix.acceleration }}-x86_64*.*
282342

283343
- name: Upload debug symbol artifacts 🪲
284344
uses: actions/upload-artifact@v4
285-
if: ${{ fromJSON(needs.check-event.outputs.package) }}
345+
if: ${{ fromJSON(needs.check-event.outputs.package) && (matrix.acceleration != 'amd') }}
286346
with:
287-
name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-ubuntu-22.04-x86_64-${{ needs.check-event.outputs.commitHash }}-dbgsym
288-
path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-x86_64*-dbgsym.ddeb
347+
name: ${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-${{ matrix.acceleration }}-ubuntu-22.04-x86_64-${{ needs.check-event.outputs.commitHash }}-dbgsym
348+
path: ${{ github.workspace }}/release/${{ steps.setup.outputs.pluginName }}-${{ steps.setup.outputs.pluginVersion }}-${{ matrix.acceleration }}-x86_64*-dbgsym.ddeb
289349

290350
windows-build:
291351
name: Build for Windows 🪟
292352
runs-on: windows-2022
293353
needs: check-event
294354
strategy:
295355
matrix:
296-
acceleration: [cpu, cuda, vulkan, hipblas]
356+
acceleration: [generic, nvidia, amd]
297357
defaults:
298358
run:
299359
shell: pwsh

0 commit comments

Comments
 (0)