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

Add support for Intel MKL in build scripts and CMake configuration #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: ccache
uses: hendrikmuhs/[email protected]

- name: "Run build-macos.sh"
run: "./build-macos.sh ${{ steps.get-version.outputs.version }}"
env:
Expand Down Expand Up @@ -78,6 +81,9 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: ccache
uses: hendrikmuhs/[email protected]

- name: "Install Vulkan SDK"
if: ${{ matrix.accel == 'vulkan' }}
run: |
Expand Down Expand Up @@ -106,7 +112,7 @@ jobs:
matrix:
config:
- "Release"
accel: [cpu, cuda, vulkan, hipblas]
accel: [cpu, cuda, vulkan, hipblas, mkl]

steps:
- name: "Get version"
Expand All @@ -122,6 +128,9 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: ccache
uses: hendrikmuhs/[email protected]

- name: Install CUDA Toolkit
if: ${{ matrix.accel == 'cuda' }}
id: cuda-toolkit
Expand Down Expand Up @@ -168,6 +177,16 @@ jobs:
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: "Install Intel MKL"
if: ${{ matrix.accel == 'mkl' }}
run: |
$ErrorActionPreference = "Stop"
write-host "Downloading Intel MKL"
Invoke-WebRequest -Uri "https://registrationcenter-download.intel.com/akdlm/IRC_NAS/bcb40b43-4ca9-4725-9749-4f9fc1e9b97f/intel-onemkl-2025.0.1.15_offline.exe" -OutFile "${env:RUNNER_TEMP}\mkl.exe"
write-host "Installing Intel MKL"
Start-Process "${env:RUNNER_TEMP}\mkl.exe" -ArgumentList '/S' -NoNewWindow -Wait
write-host "Completed Intel MKL installation"

- name: "Run Build-Windows.ps1"
run: "./Build-Windows.ps1 -Version ${{ steps.get-version.outputs.version }}"
env:
Expand Down
31 changes: 30 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ include(FetchContent)

option(WHISPERCPP_WITH_CUDA "Build Whisper with CUDA support" OFF)
option(WHISPERCPP_WITH_HIPBLAS "Build Whisper with hipBLAS support" OFF)
option(WHISPERCPP_WITH_VULKAN "Build Whisper with Vulkan support" OFF)
option(WHISPERCPP_WITH_MKL "Build Whisper with MKL support" OFF)

set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}")

set(Whispercpp_Build_GIT_TAG "fdbfb460ed546452a5d53611bba66d10d842e719")
set(Whispercpp_Build_GIT_TAG "8c6a9b8bb6a0273cc0b5915903ca1ff9206c6285")

if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL
RelWithDebInfo)
Expand Down Expand Up @@ -75,6 +77,31 @@ if(WIN32)
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DGGML_HIPBLAS=ON
-DGGML_CUDA=OFF)
set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR})
elseif(WHISPERCPP_WITH_MKL)
# Build with MKL
if(NOT DEFINED ENV{MKL_PATH})
message(
FATAL_ERROR
"MKL_PATH is not set. Please set it to the root directory of your MKL installation, e.g. `C:/Program Files (x86)/Intel/oneAPI/mkl/latest`"
)
endif(NOT DEFINED ENV{MKL_PATH})
cmake_path(SET MKL_PATH_STR NORMALIZE "$ENV{MKL_PATH}")
set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=${MKL_PATH_STR}/lib/cmake/mkl WHISPER_MKL=1")
set(MKL_BLAS_LIBRARIES
"${MKL_PATH_STR}/lib/mkl_intel_lp64.lib;${MKL_PATH_STR}/lib/mkl_sequential.lib;${MKL_PATH_STR}/lib/mkl_core.lib"
# ${MKL_PATH_STR}/lib/mkl_blas95_lp64.lib
# ${MKL_PATH_STR}/lib/mkl_blacs_intelmpi_lp64.lib
# ${MKL_PATH_STR}/lib/mkl_lapack95_lp64.lib
# ${MKL_PATH_STR}/lib/mkl_scalapack95_lp64.lib
)
cmake_path(SET MKL_PATH_INCLUDE_STR NORMALIZE "${MKL_PATH_STR}/include")
set(WHISPER_ADDITIONAL_CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DGGML_BLAS_VENDOR=Intel -DGGML_BLAS=ON -DGGML_CUDA=OFF
"-DBLAS_LIBRARIES=${MKL_BLAS_LIBRARIES}"
-DBLAS_INCLUDE_DIRS=${MKL_PATH_INCLUDE_STR})
set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR})
else()
# Build with OpenBLAS
set(OpenBLAS_URL
Expand Down Expand Up @@ -174,6 +201,8 @@ if(WIN32)
install(FILES ${HIPBLAS_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin)
elseif(WHISPERCPP_WITH_VULKAN)
message(STATUS "Vulkan does not require DLLs copy")
elseif(WHISPERCPP_WITH_MKL)
message(STATUS "MKL does not require DLLs copy")
elseif(WHISPERCPP_WITH_CUDA)
# Check that CUDA_TOOLKIT_ROOT_DIR is set
if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ Set up environment variables, e.g.:
> $env:CUDA_TOOLKIT_ROOT_DIR="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5"
```

Acceleration options: `cpu`, `cuda` and `hipblas`
Acceleration options: `cpu`, `cuda`, `vulkan`, `mkl` and `hipblas`

For `hipblas` make sure `$env:HIP_PATH` points to the HIP installation folder, e.g. where `$env:HIP_PATH\bin\clang.exe` would be located.

The HIP installer can be downloaded from https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-Win10-Win11-For-HIP.exe.

The Vulkan installer can be found in https://sdk.lunarg.com/sdk/download/1.3.296.0/windows/VulkanSDK-1.3.296.0-Installer.exe.

The MKL installer can be found in https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-download.html.

Run the build script:

```powershell
Expand Down
47 changes: 40 additions & 7 deletions build-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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', 'vulkan' or 'hipblas'."
if ($null -eq $env:BUILD_WITH_ACCEL) {
Write-Host "Please set env var BUILD_WITH_ACCEL to 'cpu', 'cuda', 'vulkan', `mkl` or 'hipblas'."
exit
}

Expand All @@ -13,32 +13,65 @@ $env:VCPKG_ROOT=""

$cmakeArgs = @()
if ($env:BUILD_WITH_ACCEL -eq "cpu") {
$cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF")
$cmakeArgs += (
"-DWHISPERCPP_WITH_CUDA=OFF",
"-DWHISPERCPP_WITH_HIPBLAS=OFF",
"-DWHISPERCPP_WITH_VULKAN=OFF",
"-DWHISPERCPP_WITH_MKL=OFF",
"-DCMAKE_GENERATOR=Visual Studio 17 2022"
)
$zipFileName = "whispercpp-windows-cpu-$Version.zip"
} elseif ($env:BUILD_WITH_ACCEL -eq "hipblas") {
$cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF",
"-DWHISPERCPP_WITH_HIPBLAS=ON",
$cmakeArgs += (
"-DWHISPERCPP_WITH_CUDA=OFF",
"-DWHISPERCPP_WITH_HIPBLAS=ON",
"-DWHISPERCPP_WITH_VULKAN=OFF",
"-DWHISPERCPP_WITH_MKL=OFF",
"-DCMAKE_GENERATOR=Unix Makefiles",
"-DCMAKE_C_COMPILER='$env:HIP_PATH\bin\clang.exe'",
"-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_CUDA=OFF",
"-DWHISPERCPP_WITH_HIPBLAS=OFF",
"-DWHISPERCPP_WITH_VULKAN=ON",
"-DWHISPERCPP_WITH_MKL=OFF",
"-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 {
} elseif ($env:BUILD_WITH_ACCEL -eq "mkl") {
$cmakeArgs += (
"-DWHISPERCPP_WITH_CUDA=OFF",
"-DWHISPERCPP_WITH_HIPBLAS=OFF",
"-DWHISPERCPP_WITH_VULKAN=OFF",
"-DWHISPERCPP_WITH_MKL=ON",
"-DCMAKE_GENERATOR=Visual Studio 17 2022"
)
$zipFileName = "whispercpp-windows-mkl-$Version.zip"
# find the MKL path in C:\Program Files (x86)\Intel\oneAPI
$mklPath = Get-ChildItem -Path "C:\Program Files (x86)\Intel\oneAPI\mkl" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$env:MKL_PATH="$mklPath"
} elseif ($env:BUILD_WITH_ACCEL -eq "cuda") {
$zipFileName = "whispercpp-windows-cuda-$Version.zip"
# find the CUDA path in C:\Program Files\NVIDIA GPU Computing Toolkit
$cudaPath = Get-ChildItem -Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$env:CUDA_TOOLKIT_ROOT_DIR="$cudaPath"
$cmakeArgs += (
"-DWHISPERCPP_WITH_CUDA=ON",
"-DWHISPERCPP_WITH_HIPBLAS=OFF",
"-DWHISPERCPP_WITH_VULKAN=OFF",
"-DWHISPERCPP_WITH_MKL=OFF",
"-DCMAKE_GENERATOR=Visual Studio 17 2022",
"-DCUDA_TOOLKIT_ROOT_DIR=$env:CUDA_TOOLKIT_ROOT_DIR"
)
$zipFileName = "whispercpp-windows-cuda-$Version.zip"
} else {
Write-Host "Invalid BUILD_WITH_ACCEL value. Please set it to 'cpu', 'cuda', 'vulkan', `mkl` or 'hipblas'."
exit
}

# configure
Expand Down
Loading