diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c452ab..0a20868 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,9 @@ jobs: - name: "Checkout" uses: "actions/checkout@v4" + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + - name: "Run build-macos.sh" run: "./build-macos.sh ${{ steps.get-version.outputs.version }}" env: @@ -78,6 +81,9 @@ jobs: - name: "Checkout" uses: "actions/checkout@v4" + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + - name: "Install Vulkan SDK" if: ${{ matrix.accel == 'vulkan' }} run: | @@ -106,7 +112,7 @@ jobs: matrix: config: - "Release" - accel: [cpu, cuda, vulkan, hipblas] + accel: [cpu, cuda, vulkan, hipblas, mkl] steps: - name: "Get version" @@ -122,6 +128,9 @@ jobs: - name: "Checkout" uses: "actions/checkout@v4" + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + - name: Install CUDA Toolkit if: ${{ matrix.accel == 'cuda' }} id: cuda-toolkit @@ -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: diff --git a/CMakeLists.txt b/CMakeLists.txt index 365ea38..025fca7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 @@ -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) diff --git a/README.md b/README.md index 706b867..0bc3d6e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build-windows.ps1 b/build-windows.ps1 index 056f062..fa6dd99 100644 --- a/build-windows.ps1 +++ b/build-windows.ps1 @@ -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 } @@ -13,11 +13,20 @@ $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'") @@ -25,20 +34,44 @@ if ($env:BUILD_WITH_ACCEL -eq "cpu") { $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