From 88be92c6033ad578c9b43aaa5b91e3d7a600cd92 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Thu, 25 Jul 2024 21:26:46 -0700 Subject: [PATCH 01/15] bump whisper.cpp version --- CMakeLists.txt | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 597982d..f9501b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ option(WHISPERCPP_WITH_CLBLAST "Build Whisper with CLBlast support" OFF) set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}") -set(Whispercpp_Build_GIT_TAG "v1.6.2") +set(Whispercpp_Build_GIT_TAG "f68298ce06ca3edd6e6f3f21c3d0bb5f073942c3") if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) set(Whispercpp_BUILD_TYPE Release) @@ -21,21 +21,14 @@ 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 -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF -DWHISPER_NO_AVX=ON - -DWHISPER_NO_AVX2=ON) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=OFF) endif() if(APPLE) - # check the "MACOS_ARCH" env var to figure out if this is x86 or arm64 + # check the "MACOS_ARCH" env var to figure out if this is x86_64 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`") + message(FATAL_ERROR "The MACOS_ARCH environment variable is not set. Please set it to either `x86_64` or `arm64`") endif(NOT DEFINED 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_ADDITIONAL_CMAKE_ARGS -DGGML_METAL=ON -DWHISPER_COREML=ON -DWHISPER_COREML_ALLOW_FALLBACK=ON) set(WHISPER_EXTRA_CXX_FLAGS "-Wno-shorten-64-to-32 -Wno-unused-parameter -Wno-unused-function -Wno-unguarded-availability-new") endif() @@ -49,7 +42,7 @@ if(WIN32) endif(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=ON -DWHISPER_OPENBLAS=OFF + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) elseif(WHISPERCPP_WITH_CLBLAST) # Build with CLBlast @@ -130,7 +123,8 @@ if(WIN32) -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF - -DWHISPER_BUILD_EXAMPLES=OFF -DCMAKE_MODULE_PATH=${CMAKE_SOURCE_DIR}/cmake ${WHISPER_ADDITIONAL_CMAKE_ARGS}) + -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_SERVER=OFF + -DCMAKE_MODULE_PATH=${CMAKE_SOURCE_DIR}/cmake ${WHISPER_ADDITIONAL_CMAKE_ARGS}) else() # On Linux and MacOS build a static Whisper library ExternalProject_Add( @@ -142,14 +136,14 @@ else() BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} CMAKE_GENERATOR ${CMAKE_GENERATOR} INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E - copy /ggml.h /include + copy /ggml/include/ggml.h /include CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF - -DWHISPER_BUILD_EXAMPLES=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) + -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_SERVER=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) endif(WIN32) ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR) From f5e797c5e1c8b51d011cc7d2ea32e405aceb33c9 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 01:38:48 -0400 Subject: [PATCH 02/15] Update CUDA Toolkit version and sub-packages in build workflow --- .github/workflows/build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2667ab0..06f5f24 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: matrix: config: - "Release" - cublas: [cpu, 12.2.0, 11.8.0, clblast] + cublas: [cpu, 12.2.0, hipblas] steps: - name: "Get version" @@ -110,14 +110,15 @@ jobs: uses: "actions/checkout@v4" - name: Install CUDA Toolkit - if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'clblast' }} + if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'hipblas' }} id: cuda-toolkit - uses: Jimver/cuda-toolkit@v0.2.15 + uses: Jimver/cuda-toolkit@v0.2.16 with: cuda: '${{ matrix.cublas }}' + sub-packages: '["compiler", "cublas", "cublas_dev"]' - name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed - if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'clblast' }} + if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'hipblas' }} run: | "CUDA_TOOLKIT_ROOT_DIR=$env:CUDA_PATH" >> $env:GITHUB_ENV From 7028e949812d7204d58ff456716ab937f2818ff5 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 01:41:12 -0400 Subject: [PATCH 03/15] Update cublas configuration in build workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 06f5f24..74545cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: matrix: config: - "Release" - cublas: [cpu, 12.2.0, hipblas] + cublas: [cpu, 12.2.0] steps: - name: "Get version" From 831b4df7fb6ffffb7b6dbc6175536eb0ceae5766 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 01:51:34 -0400 Subject: [PATCH 04/15] Update sub-packages in build workflow to include cudart, nvcc, cublas, and cublas_dev --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74545cd..68fa513 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,7 +115,7 @@ jobs: uses: Jimver/cuda-toolkit@v0.2.16 with: cuda: '${{ matrix.cublas }}' - sub-packages: '["compiler", "cublas", "cublas_dev"]' + sub-packages: '["cudart", "nvcc", "cublas", "cublas_dev"]' - name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'hipblas' }} From 9320526396f6c88a7f42a30839b86b886be3f9c9 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 01:56:21 -0400 Subject: [PATCH 05/15] Update sub-packages in build workflow to include visual_studio_integration --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68fa513..65d7ab8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,7 +115,7 @@ jobs: uses: Jimver/cuda-toolkit@v0.2.16 with: cuda: '${{ matrix.cublas }}' - sub-packages: '["cudart", "nvcc", "cublas", "cublas_dev"]' + sub-packages: '["cudart", "nvcc", "cublas", "cublas_dev", "visual_studio_integration"]' - name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'hipblas' }} From f9a2abb44fe77981cb5682a771e7fd3bd55ec521 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 02:22:54 -0400 Subject: [PATCH 06/15] Update build workflow to support CPU, CUDA, and HIPBLAS acceleration options --- .github/workflows/build.yml | 34 +++++++++++--- CMakeLists.txt | 94 ++++++++++++------------------------- build-windows.ps1 | 16 +++---- 3 files changed, 65 insertions(+), 79 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65d7ab8..e2315ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: matrix: config: - "Release" - cublas: [cpu, 12.2.0] + accel: [cpu, cuda, hipblas] steps: - name: "Get version" @@ -110,26 +110,48 @@ jobs: uses: "actions/checkout@v4" - name: Install CUDA Toolkit - if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'hipblas' }} + if: ${{ matrix.accel == 'cuda' }} id: cuda-toolkit uses: Jimver/cuda-toolkit@v0.2.16 with: - cuda: '${{ matrix.cublas }}' + cuda: '12.5.0' sub-packages: '["cudart", "nvcc", "cublas", "cublas_dev", "visual_studio_integration"]' - name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed - if: ${{ matrix.cublas != 'cpu' && matrix.cublas != 'hipblas' }} + if: ${{ matrix.accel == 'cuda' }} run: | "CUDA_TOOLKIT_ROOT_DIR=$env:CUDA_PATH" >> $env:GITHUB_ENV + - name: Install hipBLAS + id: depends-hipblas + if: ${{ matrix.accel == 'hipblas' }} + run: | + $ErrorActionPreference = "Stop" + write-host "Downloading AMD HIP SDK Installer" + Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-23.Q4-WinSvr2022-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe" + write-host "Installing AMD HIP SDK" + Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait + write-host "Completed AMD HIP SDK installation" + + - name: Verify ROCm + id: verify-hipblas + if: ${{ matrix.accel == 'hipblas' }} + run: | + & 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version + + - name: Prepare hipBLAS environment + id: prepare-hipblas + run: | + "HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)" >> $env:GITHUB_ENV + - name: "Run Build-Windows.ps1" run: "./Build-Windows.ps1 -Version ${{ steps.get-version.outputs.version }}" env: - CPU_OR_CUDA: ${{ matrix.cublas }} + BUILD_WITH_ACCEL: ${{ matrix.accel }} - uses: "actions/upload-artifact@v4" with: - name: "whispercpp-windows-${{ matrix.cublas }}" + name: "whispercpp-windows-${{ matrix.accel }}" path: "*.zip" Release: diff --git a/CMakeLists.txt b/CMakeLists.txt index f9501b4..81ec76f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ include(ExternalProject) include(FetchContent) option(WHISPERCPP_WITH_CUDA "Build Whisper with CUDA support" OFF) -option(WHISPERCPP_WITH_CLBLAST "Build Whisper with CLBlast support" OFF) +option(WHISPERCPP_WITH_HIPBLAS "Build Whisper with hipBLAS support" OFF) set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}") @@ -44,46 +44,10 @@ if(WIN32) set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) - elseif(WHISPERCPP_WITH_CLBLAST) - # Build with CLBlast - set(CLBLAST_URL "https://github.com/CNugteren/CLBlast/releases/download/1.6.2/CLBlast-1.6.2-windows-x64.zip") - set(CLBLAST_SHA256 "09776AFACF89A960C59A0F072FE8595D8F49593B343E25C901F357DAC680018F") - FetchContent_Declare( - CLBlast - DOWNLOAD_EXTRACT_TIMESTAMP true - URL ${CLBLAST_URL} - URL_HASH SHA256=${CLBLAST_SHA256}) - FetchContent_MakeAvailable(CLBlast) - find_program(SEVEN_ZIP_EXECUTABLE 7z) - if(NOT SEVEN_ZIP_EXECUTABLE) - message(FATAL_ERROR "7z executable not found!") - endif() - execute_process( - COMMAND ${SEVEN_ZIP_EXECUTABLE} x -y ${clblast_SOURCE_DIR}/CLBlast-1.6.2-windows-x64.7z - WORKING_DIRECTORY ${clblast_SOURCE_DIR} - RESULT_VARIABLE SEVEN_ZIP_RESULT - OUTPUT_QUIET - ) - if(NOT SEVEN_ZIP_RESULT EQUAL 0) - message(FATAL_ERROR "Failed to extract CLBlast: ${SEVEN_ZIP_ERROR}") - endif() - set(clblast_SOURCE_DIR ${clblast_SOURCE_DIR}/CLBlast-1.6.2-windows-x64) - - set(OPENCL_SDK_URL "https://github.com/KhronosGroup/OpenCL-SDK/releases/download/v2023.12.14/OpenCL-SDK-v2023.12.14-Win-x64.zip") - set(OPENCL_SDK_SHA256 "4C49F37A97B1B6D191B076C1E5D095B180E44BDC72DB32EC8B9748FF6ECFAEB6") - FetchContent_Declare( - OpenCL_SDK - DOWNLOAD_EXTRACT_TIMESTAMP true - URL ${OPENCL_SDK_URL} - URL_HASH SHA256=${OPENCL_SDK_SHA256}) - FetchContent_MakeAvailable(OpenCL_SDK) - - message(STATUS "clblast_SOURCE_DIR: ${clblast_SOURCE_DIR}") - set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) - find_package(CLBlast REQUIRED) - - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF - -DWHISPER_CLBLAST=ON -Dclblast_SOURCE_DIR=${clblast_SOURCE_DIR} -Dopencl_sdk_SOURCE_DIR=${opencl_sdk_SOURCE_DIR}) + elseif(WHISPERCPP_WITH_HIPBLAS) + # Build with hipBLAS + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER="${env:HIP_PATH}/bin/clang.exe" + -DCMAKE_CXX_COMPILER="${env:HIP_PATH}/bin/clang++.exe" -DGGML_HIPBLAS=ON) else() # Build with OpenBLAS set(OpenBLAS_URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip") @@ -98,8 +62,7 @@ if(WIN32) set(OpenBLAS_DIR ${openblas_SOURCE_DIR}) message(STATUS "OpenBLAS_DIR: ${OpenBLAS_DIR}") set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${openblas_SOURCE_DIR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=ON -DWHISPER_OPENBLAS=ON -DWHISPER_CUBLAS=OFF - -DWHISPER_CLBLAST=OFF) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=ON -DWHISPER_OPENBLAS=ON -DGGML_CUDA=OFF) endif() ExternalProject_Add( @@ -155,32 +118,33 @@ if(WIN32) install(DIRECTORY ${INSTALL_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) install(DIRECTORY ${INSTALL_DIR}/bin DESTINATION ${CMAKE_SOURCE_DIR}/release) - if(NOT WHISPERCPP_WITH_CUDA AND NOT WHISPERCPP_WITH_CLBLAST) + 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_CLBLAST) - file(TO_CMAKE_PATH ${clblast_SOURCE_DIR} clblast_SOURCE_DIR) - # find the clblast DLLs in the bin directory of the CLBlast installation - file(GLOB CLBLAST_DLLS "${clblast_SOURCE_DIR}/bin/clblast.dll") - # if the files cannot be found, abort - if(NOT CLBLAST_DLLS) - message(FATAL_ERROR "Could not find CLBlast DLLs in ${clblast_SOURCE_DIR}/bin") - endif() - # copy the DLLs to the OBS plugin directory - install(FILES ${CLBLAST_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) - install(DIRECTORY ${clblast_SOURCE_DIR}/include ${opencl_sdk_SOURCE_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) - - file(TO_CMAKE_PATH ${opencl_sdk_SOURCE_DIR} opencl_sdk_SOURCE_DIR) - # find the opencl SDK DLLs in the bin directory of the OpenCL SDK installation - file(GLOB OPENCL_SDK_DLLS "${opencl_sdk_SOURCE_DIR}/bin/OpenCL.dll") - # if the files cannot be found, abort - if(NOT OPENCL_SDK_DLLS) - message(FATAL_ERROR "Could not find OpenCL SDK DLLs in ${opencl_sdk_SOURCE_DIR}/bin") - endif() - # copy the DLLs to the OBS plugin directory - install(FILES ${OPENCL_SDK_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) + elseif(WHISPERCPP_WITH_HIPBLAS) + message(STATUS "Copying HIP DLLs") + # file(TO_CMAKE_PATH ${clblast_SOURCE_DIR} clblast_SOURCE_DIR) + # # find the clblast DLLs in the bin directory of the CLBlast installation + # file(GLOB CLBLAST_DLLS "${clblast_SOURCE_DIR}/bin/clblast.dll") + # # if the files cannot be found, abort + # if(NOT CLBLAST_DLLS) + # message(FATAL_ERROR "Could not find CLBlast DLLs in ${clblast_SOURCE_DIR}/bin") + # endif() + # # copy the DLLs to the OBS plugin directory + # install(FILES ${CLBLAST_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) + # install(DIRECTORY ${clblast_SOURCE_DIR}/include ${opencl_sdk_SOURCE_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) + + # file(TO_CMAKE_PATH ${opencl_sdk_SOURCE_DIR} opencl_sdk_SOURCE_DIR) + # # find the opencl SDK DLLs in the bin directory of the OpenCL SDK installation + # file(GLOB OPENCL_SDK_DLLS "${opencl_sdk_SOURCE_DIR}/bin/OpenCL.dll") + # # if the files cannot be found, abort + # if(NOT OPENCL_SDK_DLLS) + # message(FATAL_ERROR "Could not find OpenCL SDK DLLs in ${opencl_sdk_SOURCE_DIR}/bin") + # endif() + # # copy the DLLs to the OBS plugin directory + # install(FILES ${OPENCL_SDK_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) else() # normalize CUDA path with file(TO_CMAKE_PATH) file(TO_CMAKE_PATH ${CUDA_TOOLKIT_ROOT_DIR} CUDA_TOOLKIT_ROOT_DIR) diff --git a/build-windows.ps1 b/build-windows.ps1 index 31bd002..6a52648 100644 --- a/build-windows.ps1 +++ b/build-windows.ps1 @@ -2,25 +2,25 @@ Param( [string]$Version ) -# check env var CPU_OR_CUDA -if ($env:CPU_OR_CUDA -eq $null) { - Write-Host "Please set env var CPU_OR_CUDA to 'cpu', 'clblast' or the CUDA version you want to use" +# 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'." exit } $cmakeArgs = @() -if ($env:CPU_OR_CUDA -eq "cpu") { +if ($env:BUILD_WITH_ACCEL -eq "cpu") { $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF") $zipFileName = "whispercpp-windows-cpu-$Version.zip" -} elseif ($env:CPU_OR_CUDA -eq "clblast") { - $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF", "-DWHISPERCPP_WITH_CLBLAST=ON") - $zipFileName = "whispercpp-windows-clblast-$Version.zip" +} elseif ($env:BUILD_WITH_ACCEL -eq "hipblas") { + $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF", "-DWHISPERCPP_WITH_HIPBLAS=ON") + $zipFileName = "whispercpp-windows-hipblas-$Version.zip" } else { $cmakeArgs += ( "-DWHISPERCPP_WITH_CUDA=ON", "-DCUDA_TOOLKIT_ROOT_DIR=$env:CUDA_TOOLKIT_ROOT_DIR" ) - $zipFileName = "whispercpp-windows-cuda$env:CPU_OR_CUDA-$Version.zip" + $zipFileName = "whispercpp-windows-cuda-$Version.zip" } # configure From e4685d635931f721876ffb2ba9e6df83bc12a1bd Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 02:24:04 -0400 Subject: [PATCH 07/15] Update hipBLAS environment preparation in build workflow --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e2315ca..da1fb83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -141,6 +141,7 @@ jobs: - name: Prepare hipBLAS environment id: prepare-hipblas + if: ${{ matrix.accel == 'hipblas' }} run: | "HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)" >> $env:GITHUB_ENV From cef3faeed8e2422e67ce4d9a5d98e2afb4184597 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 02:30:08 -0400 Subject: [PATCH 08/15] Update OpenBLAS version in CMakeLists.txt --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81ec76f..84dd29e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,8 +46,8 @@ if(WIN32) -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) elseif(WHISPERCPP_WITH_HIPBLAS) # Build with hipBLAS - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER="${env:HIP_PATH}/bin/clang.exe" - -DCMAKE_CXX_COMPILER="${env:HIP_PATH}/bin/clang++.exe" -DGGML_HIPBLAS=ON) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER="$ENV{HIP_PATH}/bin/clang.exe" + -DCMAKE_CXX_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" -DGGML_HIPBLAS=ON) else() # Build with OpenBLAS set(OpenBLAS_URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip") @@ -62,7 +62,8 @@ if(WIN32) set(OpenBLAS_DIR ${openblas_SOURCE_DIR}) message(STATUS "OpenBLAS_DIR: ${OpenBLAS_DIR}") set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${openblas_SOURCE_DIR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=ON -DWHISPER_OPENBLAS=ON -DGGML_CUDA=OFF) + # -DBLAS_INCLUDE_DIRS="$env:RUNNER_TEMP/openblas/include" -DBLAS_LIBRARIES="$env:RUNNER_TEMP/openblas/lib/openblas.lib" + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF) endif() ExternalProject_Add( From 8d5232e989aec79bae2c666892edc6a8dec778a1 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 02:38:38 -0400 Subject: [PATCH 09/15] Update CMakeLists.txt to include additional environment variable for hipBLAS --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84dd29e..290f1b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ if(WIN32) -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) elseif(WHISPERCPP_WITH_HIPBLAS) # Build with hipBLAS + set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=$ENV{HIP_PATH}") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER="$ENV{HIP_PATH}/bin/clang.exe" -DCMAKE_CXX_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" -DGGML_HIPBLAS=ON) else() @@ -62,8 +63,8 @@ if(WIN32) set(OpenBLAS_DIR ${openblas_SOURCE_DIR}) message(STATUS "OpenBLAS_DIR: ${OpenBLAS_DIR}") set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${openblas_SOURCE_DIR}") - # -DBLAS_INCLUDE_DIRS="$env:RUNNER_TEMP/openblas/include" -DBLAS_LIBRARIES="$env:RUNNER_TEMP/openblas/lib/openblas.lib" - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF + -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/openblas.lib -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) endif() ExternalProject_Add( @@ -80,7 +81,7 @@ if(WIN32) INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy /${Whispercpp_BUILD_TYPE}/whisper.lib /lib && ${CMAKE_COMMAND} -E copy - /ggml.h /include + /ggml/include/ggml.h /include CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} From b2535f873bcbff8d1a49a93f46193d0682e64007 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 02:42:26 -0400 Subject: [PATCH 10/15] Update OpenBLAS library path in CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 290f1b8..a1f03e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ if(WIN32) message(STATUS "OpenBLAS_DIR: ${OpenBLAS_DIR}") set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${openblas_SOURCE_DIR}") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF - -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/openblas.lib -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) + -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/libopenblas.lib -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) endif() ExternalProject_Add( From 8b4bdc683610b39057a3ff6a25ed210490bb719f Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 07:51:19 -0400 Subject: [PATCH 11/15] Update CMakeLists.txt to include additional environment variable for hipBLAS --- CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1f03e1..e47777d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,11 +44,18 @@ if(WIN32) set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) + set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) elseif(WHISPERCPP_WITH_HIPBLAS) # Build with hipBLAS - set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=$ENV{HIP_PATH}") + if (NOT DEFINED ENV{HIP_PATH}) + message(FATAL_ERROR "HIP_PATH is not set. Please set it to the root directory of your HIP installation, e.g. `C:/Program Files/ROCm`") + endif(NOT DEFINED ENV{HIP_PATH}) + set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=$ENV{HIP_PATH} CC=$ENV{HIP_PATH}/bin/clang.exe CXX=$ENV{HIP_PATH}/bin/clang++.exe") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER="$ENV{HIP_PATH}/bin/clang.exe" - -DCMAKE_CXX_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" -DGGML_HIPBLAS=ON) + -DCMAKE_CXX_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" + -DCMAKE_HIP_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" + -DGGML_HIPBLAS=ON) + set(WHISPER_CMAKE_GENERATOR "Unix Makefiles") else() # Build with OpenBLAS set(OpenBLAS_URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip") @@ -65,6 +72,7 @@ if(WIN32) set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${openblas_SOURCE_DIR}") set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/libopenblas.lib -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) + set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) endif() ExternalProject_Add( @@ -84,9 +92,8 @@ if(WIN32) /ggml/include/ggml.h /include CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G - ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} - -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 - -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} + ${WHISPER_CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_SERVER=OFF -DCMAKE_MODULE_PATH=${CMAKE_SOURCE_DIR}/cmake ${WHISPER_ADDITIONAL_CMAKE_ARGS}) From 6813a791464bd55298e4b7bb431a46f1a2ed7fd2 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 09:35:50 -0400 Subject: [PATCH 12/15] Update CMakeLists.txt to include additional environment variable for hipBLAS --- CMakeLists.txt | 11 +++++------ build-windows.ps1 | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e47777d..dfec0c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,12 +50,11 @@ if(WIN32) if (NOT DEFINED ENV{HIP_PATH}) message(FATAL_ERROR "HIP_PATH is not set. Please set it to the root directory of your HIP installation, e.g. `C:/Program Files/ROCm`") endif(NOT DEFINED ENV{HIP_PATH}) - set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=$ENV{HIP_PATH} CC=$ENV{HIP_PATH}/bin/clang.exe CXX=$ENV{HIP_PATH}/bin/clang++.exe") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER="$ENV{HIP_PATH}/bin/clang.exe" - -DCMAKE_CXX_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" - -DCMAKE_HIP_COMPILER="$ENV{HIP_PATH}/bin/clang++.exe" - -DGGML_HIPBLAS=ON) - set(WHISPER_CMAKE_GENERATOR "Unix Makefiles") + cmake_path(SET HIP_PATH_STR NORMALIZE "$ENV{HIP_PATH}") + set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=${HIP_PATH_STR}") + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER='${HIP_PATH_STR}/bin/clang.exe' + -DCMAKE_CXX_COMPILER='${HIP_PATH_STR}/bin/clang++.exe' -DGGML_HIPBLAS=ON -DGGML_CUDA=OFF) + set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) else() # Build with OpenBLAS set(OpenBLAS_URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip") diff --git a/build-windows.ps1 b/build-windows.ps1 index 6a52648..2512ccc 100644 --- a/build-windows.ps1 +++ b/build-windows.ps1 @@ -13,7 +13,7 @@ if ($env:BUILD_WITH_ACCEL -eq "cpu") { $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF") $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", "-DCMAKE_GENERATOR=Unix Makefiles") $zipFileName = "whispercpp-windows-hipblas-$Version.zip" } else { $cmakeArgs += ( From 8754b6e6f297e314d40c7de5ff91b8f5e3365ffd Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 10:16:00 -0400 Subject: [PATCH 13/15] Update CMakeLists.txt to include additional environment variable for hipBLAS --- CMakeLists.txt | 4 ++-- build-windows.ps1 | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfec0c5..06d920f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,8 @@ if(WIN32) endif(NOT DEFINED ENV{HIP_PATH}) cmake_path(SET HIP_PATH_STR NORMALIZE "$ENV{HIP_PATH}") set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=${HIP_PATH_STR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER='${HIP_PATH_STR}/bin/clang.exe' - -DCMAKE_CXX_COMPILER='${HIP_PATH_STR}/bin/clang++.exe' -DGGML_HIPBLAS=ON -DGGML_CUDA=OFF) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DGGML_HIPBLAS=ON -DGGML_CUDA=OFF) set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) else() # Build with OpenBLAS diff --git a/build-windows.ps1 b/build-windows.ps1 index 2512ccc..bc475f4 100644 --- a/build-windows.ps1 +++ b/build-windows.ps1 @@ -13,7 +13,11 @@ if ($env:BUILD_WITH_ACCEL -eq "cpu") { $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF") $zipFileName = "whispercpp-windows-cpu-$Version.zip" } elseif ($env:BUILD_WITH_ACCEL -eq "hipblas") { - $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF", "-DWHISPERCPP_WITH_HIPBLAS=ON", "-DCMAKE_GENERATOR=Unix Makefiles") + $cmakeArgs += ("-DWHISPERCPP_WITH_CUDA=OFF", + "-DWHISPERCPP_WITH_HIPBLAS=ON", + "-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" } else { $cmakeArgs += ( From a35202ed9a61b59139708c7304138b4607796be4 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 10:34:51 -0400 Subject: [PATCH 14/15] Update AMD HIP SDK version to 24.Q3 in build workflow --- .github/workflows/build.yml | 2 +- build-windows.ps1 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da1fb83..9eb8a32 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,7 +128,7 @@ jobs: run: | $ErrorActionPreference = "Stop" write-host "Downloading AMD HIP SDK Installer" - Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-23.Q4-WinSvr2022-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe" + Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-Win10-Win11-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe" write-host "Installing AMD HIP SDK" Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait write-host "Completed AMD HIP SDK installation" diff --git a/build-windows.ps1 b/build-windows.ps1 index bc475f4..df39d81 100644 --- a/build-windows.ps1 +++ b/build-windows.ps1 @@ -19,6 +19,7 @@ if ($env:BUILD_WITH_ACCEL -eq "cpu") { "-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" } else { $cmakeArgs += ( "-DWHISPERCPP_WITH_CUDA=ON", From 6e978f46ff0ee7c986a464c8f2e08a1c8c99b52e Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Fri, 26 Jul 2024 12:37:26 -0400 Subject: [PATCH 15/15] chore: Update build workflow to include AMD HIP SDK version 24.Q3 --- CMakeLists.txt | 169 +++++++++++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d920f..1ba614f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,8 @@ set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}") set(Whispercpp_Build_GIT_TAG "f68298ce06ca3edd6e6f3f21c3d0bb5f073942c3") -if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) +if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL + RelWithDebInfo) set(Whispercpp_BUILD_TYPE Release) else() set(Whispercpp_BUILD_TYPE Debug) @@ -26,51 +27,68 @@ endif() if(APPLE) # check the "MACOS_ARCH" env var to figure out if this is x86_64 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_64` or `arm64`") + message( + FATAL_ERROR + "The MACOS_ARCH environment variable is not set. Please set it to either `x86_64` or `arm64`" + ) endif(NOT DEFINED ENV{MACOS_ARCH}) - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_METAL=ON -DWHISPER_COREML=ON -DWHISPER_COREML_ALLOW_FALLBACK=ON) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_METAL=ON -DWHISPER_COREML=ON + -DWHISPER_COREML_ALLOW_FALLBACK=ON) set(WHISPER_EXTRA_CXX_FLAGS - "-Wno-shorten-64-to-32 -Wno-unused-parameter -Wno-unused-function -Wno-unguarded-availability-new") + "-Wno-shorten-64-to-32 -Wno-unused-parameter -Wno-unused-function -Wno-unguarded-availability-new" + ) endif() if(WIN32) if(WHISPERCPP_WITH_CUDA) # Build with CUDA Check that CUDA_TOOLKIT_ROOT_DIR is set if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) - message(FATAL_ERROR "CUDA_TOOLKIT_ROOT_DIR is not set. Please set it to the root directory of your CUDA " - "installation, e.g. `C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4`") + message( + FATAL_ERROR + "CUDA_TOOLKIT_ROOT_DIR is not set. Please set it to the root directory of your CUDA " + "installation, e.g. `C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4`" + ) endif(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON - -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) + set(WHISPER_ADDITIONAL_CMAKE_ARGS + -DGGML_CUDA=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) elseif(WHISPERCPP_WITH_HIPBLAS) # Build with hipBLAS - if (NOT DEFINED ENV{HIP_PATH}) - message(FATAL_ERROR "HIP_PATH is not set. Please set it to the root directory of your HIP installation, e.g. `C:/Program Files/ROCm`") + if(NOT DEFINED ENV{HIP_PATH}) + message( + FATAL_ERROR + "HIP_PATH is not set. Please set it to the root directory of your HIP installation, e.g. `C:/Program Files/ROCm`" + ) endif(NOT DEFINED ENV{HIP_PATH}) cmake_path(SET HIP_PATH_STR NORMALIZE "$ENV{HIP_PATH}") set(WHISPER_ADDITIONAL_ENV "CMAKE_PREFIX_PATH=${HIP_PATH_STR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DGGML_HIPBLAS=ON -DGGML_CUDA=OFF) + set(WHISPER_ADDITIONAL_CMAKE_ARGS + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DGGML_HIPBLAS=ON + -DGGML_CUDA=OFF) set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) else() # Build with OpenBLAS - set(OpenBLAS_URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip") - set(OpenBLAS_SHA256 "859C510A962A30EF1B01AA93CDE26FDB5FB1050F94AD5AB2802EBA3731935E06") + set(OpenBLAS_URL + "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip" + ) + set(OpenBLAS_SHA256 + "859C510A962A30EF1B01AA93CDE26FDB5FB1050F94AD5AB2802EBA3731935E06") FetchContent_Declare( OpenBLAS URL ${OpenBLAS_URL} URL_HASH SHA256=${OpenBLAS_SHA256} - DOWNLOAD_EXTRACT_TIMESTAMP true - ) + DOWNLOAD_EXTRACT_TIMESTAMP true) FetchContent_MakeAvailable(OpenBLAS) set(OpenBLAS_DIR ${openblas_SOURCE_DIR}) message(STATUS "OpenBLAS_DIR: ${OpenBLAS_DIR}") set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${openblas_SOURCE_DIR}") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF - -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/libopenblas.lib -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) + set(WHISPER_ADDITIONAL_CMAKE_ARGS + -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF + -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/libopenblas.lib + -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) set(WHISPER_CMAKE_GENERATOR ${CMAKE_GENERATOR}) endif() @@ -79,23 +97,30 @@ if(WIN32) DOWNLOAD_EXTRACT_TIMESTAMP true GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git GIT_TAG ${Whispercpp_Build_GIT_TAG} - BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Whispercpp_BUILD_TYPE} --verbose + BUILD_COMMAND ${CMAKE_COMMAND} --build --config + ${Whispercpp_BUILD_TYPE} --verbose BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} /bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} /lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX} CMAKE_GENERATOR ${CMAKE_GENERATOR} INSTALL_COMMAND - ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy - /${Whispercpp_BUILD_TYPE}/whisper.lib /lib && ${CMAKE_COMMAND} -E copy - /ggml/include/ggml.h /include + ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} + && ${CMAKE_COMMAND} -E copy + /${Whispercpp_BUILD_TYPE}/whisper.lib /lib && + ${CMAKE_COMMAND} -E copy /ggml/include/ggml.h + /include CONFIGURE_COMMAND - ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G - ${WHISPER_CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} - -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} - -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF - -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_SERVER=OFF - -DCMAKE_MODULE_PATH=${CMAKE_SOURCE_DIR}/cmake ${WHISPER_ADDITIONAL_CMAKE_ARGS}) + ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} + -B -G ${WHISPER_CMAKE_GENERATOR} + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} + -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON + -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF + -DWHISPER_BUILD_SERVER=OFF -DCMAKE_MODULE_PATH=${CMAKE_SOURCE_DIR}/cmake + ${WHISPER_ADDITIONAL_CMAKE_ARGS}) else() # On Linux and MacOS build a static Whisper library ExternalProject_Add( @@ -103,60 +128,60 @@ else() DOWNLOAD_EXTRACT_TIMESTAMP true GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git GIT_TAG ${Whispercpp_Build_GIT_TAG} - BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Whispercpp_BUILD_TYPE} - BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} + BUILD_COMMAND ${CMAKE_COMMAND} --build --config + ${Whispercpp_BUILD_TYPE} + BUILD_BYPRODUCTS + /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} CMAKE_GENERATOR ${CMAKE_GENERATOR} - INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E - copy /ggml/include/ggml.h /include + INSTALL_COMMAND + ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} + && ${CMAKE_COMMAND} -E copy /ggml/include/ggml.h + /include CONFIGURE_COMMAND - ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G - ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} - -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 - -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} - -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF - -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_SERVER=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) + ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} + -B -G ${CMAKE_GENERATOR} + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} + -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} + -DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF + -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF + -DWHISPER_BUILD_SERVER=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) endif(WIN32) ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR) # add the Whisper library to the link line if(WIN32) - # copy lib/ include/ and bin/ from ${INSTALL_DIR} to the release directory in the root of the project + # copy lib/ include/ and bin/ from ${INSTALL_DIR} to the release directory in + # the root of the project install(DIRECTORY ${INSTALL_DIR}/lib DESTINATION ${CMAKE_SOURCE_DIR}/release) - install(DIRECTORY ${INSTALL_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) + install(DIRECTORY ${INSTALL_DIR}/include + 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) + 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) - message(STATUS "Copying HIP DLLs") - # file(TO_CMAKE_PATH ${clblast_SOURCE_DIR} clblast_SOURCE_DIR) - # # find the clblast DLLs in the bin directory of the CLBlast installation - # file(GLOB CLBLAST_DLLS "${clblast_SOURCE_DIR}/bin/clblast.dll") - # # if the files cannot be found, abort - # if(NOT CLBLAST_DLLS) - # message(FATAL_ERROR "Could not find CLBlast DLLs in ${clblast_SOURCE_DIR}/bin") - # endif() - # # copy the DLLs to the OBS plugin directory - # install(FILES ${CLBLAST_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) - # install(DIRECTORY ${clblast_SOURCE_DIR}/include ${opencl_sdk_SOURCE_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) - - # file(TO_CMAKE_PATH ${opencl_sdk_SOURCE_DIR} opencl_sdk_SOURCE_DIR) - # # find the opencl SDK DLLs in the bin directory of the OpenCL SDK installation - # file(GLOB OPENCL_SDK_DLLS "${opencl_sdk_SOURCE_DIR}/bin/OpenCL.dll") - # # if the files cannot be found, abort - # if(NOT OPENCL_SDK_DLLS) - # message(FATAL_ERROR "Could not find OpenCL SDK DLLs in ${opencl_sdk_SOURCE_DIR}/bin") - # endif() - # # copy the DLLs to the OBS plugin directory - # install(FILES ${OPENCL_SDK_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) + 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() # normalize CUDA path with file(TO_CMAKE_PATH) file(TO_CMAKE_PATH ${CUDA_TOOLKIT_ROOT_DIR} CUDA_TOOLKIT_ROOT_DIR) - # find the CUDA DLLs for cuBLAS in the bin directory of the CUDA installation e.g. cublas64_NN.dll + # find the CUDA DLLs for cuBLAS in the bin directory of the CUDA + # installation e.g. cublas64_NN.dll file(GLOB CUBLAS_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cublas64_*.dll") # find cublasLt DLL, e.g. cublasLt64_11.dll file(GLOB CUBLASLT_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cublasLt64_*.dll") @@ -166,13 +191,19 @@ if(WIN32) if(NOT CUBLAS_DLLS OR NOT CUBLASLT_DLLS OR NOT CUDART_DLLS) - message(FATAL_ERROR "Could not find cuBLAS, cuBLASLt or cuDART DLLs in ${CUDA_TOOLKIT_ROOT_DIR}/bin") + message( + FATAL_ERROR + "Could not find cuBLAS, cuBLASLt or cuDART DLLs in ${CUDA_TOOLKIT_ROOT_DIR}/bin" + ) endif() # copy the DLLs to the OBS plugin directory - install(FILES ${CUBLAS_DLLS} ${CUBLASLT_DLLS} ${CUDART_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) + install(FILES ${CUBLAS_DLLS} ${CUBLASLT_DLLS} ${CUDART_DLLS} + DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) endif() else() - # copy lib/ include/ and bin/ from ${INSTALL_DIR} to the release directory in the root of the project + # copy lib/ include/ and bin/ from ${INSTALL_DIR} to the release directory in + # the root of the project install(DIRECTORY ${INSTALL_DIR}/lib DESTINATION ${CMAKE_SOURCE_DIR}/release) - install(DIRECTORY ${INSTALL_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) + install(DIRECTORY ${INSTALL_DIR}/include + DESTINATION ${CMAKE_SOURCE_DIR}/release) endif(WIN32)