diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c452ab..f3b3907 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ concurrency: jobs: BuildMac: - runs-on: "macos-13" + runs-on: "macos-latest" strategy: matrix: @@ -38,6 +38,11 @@ jobs: printf "version=%s" "$version" > "$GITHUB_OUTPUT" id: "get-version" + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ github.job }}-MacOS-${{ matrix.architecture }} + - name: "Checkout" uses: "actions/checkout@v4" @@ -122,13 +127,21 @@ jobs: - name: "Checkout" uses: "actions/checkout@v4" - - name: Install CUDA Toolkit + # - name: Install CUDA Toolkit + # if: ${{ matrix.accel == 'cuda' }} + # id: cuda-toolkit + # uses: Jimver/cuda-toolkit@v0.2.21 + # with: + # cuda: '12.5.1' + # sub-packages: '["cudart", "nvcc", "cublas", "cublas_dev", "visual_studio_integration"]' + # method: 'network' + - name: Setup CUDA Toolkit if: ${{ matrix.accel == 'cuda' }} id: cuda-toolkit - uses: Jimver/cuda-toolkit@v0.2.16 - with: - cuda: '12.5.0' - sub-packages: '["cudart", "nvcc", "cublas", "cublas_dev", "visual_studio_integration"]' + shell: pwsh + run: ./setup_cuda.ps1 + env: + INPUT_CUDA_VERSION: '12.5.1' - name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed if: ${{ matrix.accel == 'cuda' }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 365ea38..74f16c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,14 @@ 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) set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}") -set(Whispercpp_Build_GIT_TAG "fdbfb460ed546452a5d53611bba66d10d842e719") +set(Whispercpp_Build_GIT_TAG "8a9ad7844d6e2a10cddf4b92de4089d7ac2b14a9") if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL - RelWithDebInfo) + RelWithDebInfo) set(Whispercpp_BUILD_TYPE Release) else() set(Whispercpp_BUILD_TYPE Debug) @@ -22,24 +23,27 @@ endif() if(UNIX AND NOT APPLE) # On linux add the `-fPIC` flag to the compiler set(WHISPER_EXTRA_CXX_FLAGS "-fPIC") + 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 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`" + "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) + -DWHISPER_COREML_ALLOW_FALLBACK=ON -DGGML_NATIVE=OFF) 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() @@ -47,15 +51,16 @@ if(WIN32) if(WHISPERCPP_WITH_CUDA) # Build with CUDA set(WHISPER_ADDITIONAL_ENV "") - set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON) + set(WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=all) 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`" + "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) @@ -65,23 +70,24 @@ 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`" + "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) + -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" + "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.26/OpenBLAS-0.3.26-x64.zip" ) set(OpenBLAS_SHA256 - "859C510A962A30EF1B01AA93CDE26FDB5FB1050F94AD5AB2802EBA3731935E06") + "859C510A962A30EF1B01AA93CDE26FDB5FB1050F94AD5AB2802EBA3731935E06") FetchContent_Declare( OpenBLAS URL ${OpenBLAS_URL} @@ -92,9 +98,9 @@ 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/libopenblas.lib - -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) + -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() @@ -104,25 +110,25 @@ if(WIN32) 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 + ${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} + /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} + ${Whispercpp_BUILD_TYPE} 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( @@ -131,26 +137,26 @@ else() GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git GIT_TAG ${Whispercpp_Build_GIT_TAG} BUILD_COMMAND ${CMAKE_COMMAND} --build --config - ${Whispercpp_BUILD_TYPE} + ${Whispercpp_BUILD_TYPE} BUILD_BYPRODUCTS - /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} + /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 + ${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=15.2 + -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) @@ -162,15 +168,15 @@ if(WIN32) # 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) + DESTINATION ${CMAKE_SOURCE_DIR}/release) install(DIRECTORY ${INSTALL_DIR}/bin DESTINATION ${CMAKE_SOURCE_DIR}/release) 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") + "${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) elseif(WHISPERCPP_WITH_VULKAN) message(STATUS "Vulkan does not require DLLs copy") @@ -179,55 +185,62 @@ if(WIN32) 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`" + "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) # 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 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") + # find cudart DLL, e.g. cudart64_110.dll file(GLOB CUDART_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cudart64_*.dll") + # if any of the files cannot be found, abort if(NOT CUBLAS_DLLS - OR NOT CUBLASLT_DLLS - OR NOT CUDART_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" + "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) + 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) + DESTINATION ${CMAKE_SOURCE_DIR}/release) install(DIRECTORY ${OpenBLAS_DIR}/include - DESTINATION ${CMAKE_SOURCE_DIR}/release) + DESTINATION ${CMAKE_SOURCE_DIR}/release) install(DIRECTORY ${OpenBLAS_DIR}/bin - DESTINATION ${CMAKE_SOURCE_DIR}/release) + DESTINATION ${CMAKE_SOURCE_DIR}/release) endif() else() # 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) + DESTINATION ${CMAKE_SOURCE_DIR}/release) + if(APPLE) # copy the Metal shader library to the release directory install(DIRECTORY ${INSTALL_DIR}/bin - DESTINATION ${CMAKE_SOURCE_DIR}/release) + DESTINATION ${CMAKE_SOURCE_DIR}/release) install( FILES - ${BINARY_DIR}/src/${CMAKE_STATIC_LIBRARY_PREFIX}whisper.coreml${CMAKE_STATIC_LIBRARY_SUFFIX} + ${BINARY_DIR}/src/${CMAKE_STATIC_LIBRARY_PREFIX}whisper.coreml${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION ${CMAKE_SOURCE_DIR}/release/lib) endif() endif(WIN32) diff --git a/setup_cuda.ps1 b/setup_cuda.ps1 new file mode 100644 index 0000000..af2691f --- /dev/null +++ b/setup_cuda.ps1 @@ -0,0 +1,157 @@ +# From: https://github.com/thewh1teagle/vibe/blob/main/scripts/setup_cuda.ps1 +# Rendered here under the MIT License +# Copyright (c) 2024 thewh1teagle + +$CUDA_VERSION_FULL = $env:INPUT_CUDA_VERSION # v12.5.0 or v11.8.0 + +# Make sure CUDA_VERSION_FULL is set and valid, otherwise error. +# Validate CUDA version, extracting components via regex +$cuda_ver_matched = $CUDA_VERSION_FULL -match "^(?[1-9][0-9]*)\.(?[0-9]+)\.(?[0-9]+)$" +if (-not $cuda_ver_matched) { + Write-Output "Invalid CUDA version specified, .. required. '$CUDA_VERSION_FULL'." + exit 1 +} +$CUDA_MAJOR = $Matches.major +$CUDA_MINOR = $Matches.minor +$CUDA_PATCH = $Matches.patch + +Write-Output "Selected CUDA version: $CUDA_VERSION_FULL" + +$src = "cuda" +$dst = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$($CUDA_MAJOR).$($CUDA_MINOR)" +$installer = "cuda.exe" + +$cudaVersions = @{ + '12.8.0' = 'https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda_12.8.0_571.96_windows.exe' + '12.6.3' = 'https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda_12.6.3_561.17_windows.exe' + '12.6.2' = 'https://developer.download.nvidia.com/compute/cuda/12.6.2/local_installers/cuda_12.6.2_560.94_windows.exe' + '12.6.1' = 'https://developer.download.nvidia.com/compute/cuda/12.6.1/local_installers/cuda_12.6.1_560.94_windows.exe' + '12.6.0' = 'https://developer.download.nvidia.com/compute/cuda/12.6.0/local_installers/cuda_12.6.0_560.76_windows.exe' + '12.5.1' = 'https://developer.download.nvidia.com/compute/cuda/12.5.1/local_installers/cuda_12.5.1_555.85_windows.exe' + '12.5.0' = 'https://developer.download.nvidia.com/compute/cuda/12.5.0/local_installers/cuda_12.5.0_555.85_windows.exe' + '12.4.1' = 'https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_551.78_windows.exe' + '12.4.0' = 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe' + '12.3.2' = 'https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/cuda_12.3.2_546.12_windows.exe' + '12.3.1' = 'https://developer.download.nvidia.com/compute/cuda/12.3.1/local_installers/cuda_12.3.1_546.12_windows.exe' + '12.3.0' = 'https://developer.download.nvidia.com/compute/cuda/12.3.0/local_installers/cuda_12.3.0_545.84_windows.exe' + '12.2.2' = 'https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_537.13_windows.exe' + '12.2.1' = 'https://developer.download.nvidia.com/compute/cuda/12.2.1/local_installers/cuda_12.2.1_536.67_windows.exe' + '12.2.0' = 'https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_536.25_windows.exe' + '12.1.1' = 'https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_531.14_windows.exe' + '12.1.0' = 'https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_531.14_windows.exe' + '12.0.1' = 'https://developer.download.nvidia.com/compute/cuda/12.0.1/local_installers/cuda_12.0.1_528.33_windows.exe' + '12.0.0' = 'https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_527.41_windows.exe' + '11.8.0' = 'https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_522.06_windows.exe' + '11.7.1' = 'https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_516.94_windows.exe' + '11.7.0' = 'https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_516.01_windows.exe' + '11.6.2' = 'https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_511.65_windows.exe' + '11.6.1' = 'https://developer.download.nvidia.com/compute/cuda/11.6.1/local_installers/cuda_11.6.1_511.65_windows.exe' + '11.6.0' = 'https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_511.23_windows.exe' + '11.5.2' = 'https://developer.download.nvidia.com/compute/cuda/11.5.2/local_installers/cuda_11.5.2_496.13_windows.exe' + '11.5.1' = 'https://developer.download.nvidia.com/compute/cuda/11.5.1/local_installers/cuda_11.5.1_496.13_windows.exe' + '11.5.0' = 'https://developer.download.nvidia.com/compute/cuda/11.5.0/local_installers/cuda_11.5.0_496.13_win10.exe' + '11.4.4' = 'https://developer.download.nvidia.com/compute/cuda/11.4.4/local_installers/cuda_11.4.4_472.50_windows.exe' + '11.4.3' = 'https://developer.download.nvidia.com/compute/cuda/11.4.3/local_installers/cuda_11.4.3_472.50_win10.exe' + '11.4.2' = 'https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_471.41_win10.exe' + '11.4.1' = 'https://developer.download.nvidia.com/compute/cuda/11.4.1/local_installers/cuda_11.4.1_471.41_win10.exe' + '11.4.0' = 'https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda_11.4.0_471.11_win10.exe' + '11.3.1' = 'https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.89_win10.exe' + '11.3.0' = 'https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda_11.3.0_465.89_win10.exe' + '11.2.2' = 'https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda_11.2.2_461.33_win10.exe' + '11.2.1' = 'https://developer.download.nvidia.com/compute/cuda/11.2.1/local_installers/cuda_11.2.1_461.09_win10.exe' + '11.2.0' = 'https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.89_win10.exe' + '11.1.1' = 'https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_456.81_win10.exe' + '11.0.3' = 'https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_451.82_win10.exe' + '11.0.2' = 'https://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_451.48_win10.exe' + '11.0.1' = 'https://developer.download.nvidia.com/compute/cuda/11.0.1/local_installers/cuda_11.0.1_451.22_win10.exe' + '10.2.89' = 'https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_441.22_win10.exe' + '10.1.243' = 'https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_426.00_win10.exe' + '10.0.130' = 'https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_411.31_win10' + '9.2.148' = 'https://developer.nvidia.com/compute/cuda/9.2/Prod2/local_installers2/cuda_9.2.148_win10' + '8.0.61' = 'https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_win10-exe' +} + +if ($cudaVersions.ContainsKey($CUDA_VERSION_FULL)) { + $cudaInstallerUrl = $cudaVersions[$CUDA_VERSION_FULL] + Write-Output "CUDA version $CUDA_VERSION_FULL found. Downloading from $cudaInstallerUrl" + # Add your download and installation logic here + $downloadUrl = $cudaInstallerUrl +} +else { + Write-Output "CUDA version $CUDA_VERSION_FULL not found." + exit 1 +} + +# Download cuda +Write-Output "Downloading CUDA from: $downloadUrl" +if (-not (Test-Path -Path $installer)) { + Write-Output "Downloading CUDA installer..." + # If the file does not exist, download it + & "C:\msys64\usr\bin\wget" $downloadUrl -O $installer -q +} + +# Extract cuda +if (-not (Test-Path -Path $src -Type Container)) { + # Extract CUDA using 7-Zip + Write-Output "Extracting CUDA using 7-Zip..." + mkdir "$src" + & 'C:\Program Files\7-Zip\7z' x $installer -o"$src" +} + +# Create destination directory if it doesn't exist +if (-Not (Test-Path -Path $dst)) { + Write-Output "Creating destination directory: $dst" + New-Item -Path $dst -ItemType Directory +} + +# Get directories to process from the source path +$directories = Get-ChildItem -Directory -Path $src +$whitelist = @("CUDA_Toolkit_Release_Notes.txt", "DOCS", "EULA.txt", "LICENSE", "README", "version.json") + +foreach ($dir in $directories) { + # Get all subdirectories and files in the current directory + $items = Get-ChildItem -Path (Join-Path $src $dir.Name) + + foreach ($item in $items) { + if ($item.PSIsContainer) { + # If the item is a directory, copy its contents + Write-Output "Copying contents of directory $($item.FullName) to $dst" + Copy-Item -Path "$($item.FullName)\*" -Destination $dst -Recurse -Force + } + else { + if ($whitelist -contains $item.Name) { + Write-Output "Copying file $($item.FullName) to $dst" + Copy-Item -Path $item.FullName -Destination $dst -Force + } + } + } +} + +# Add msbuild cuda extensions +$msBuildExtensions = (Get-ChildItem "$src\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions").fullname +(Get-ChildItem 'C:\Program Files\Microsoft Visual Studio\2022\*\MSBuild\Microsoft\VC\*\BuildCustomizations').FullName | ForEach-Object { + $destination = $_ + $msBuildExtensions | ForEach-Object { + $extension = $_ + Copy-Item $extension -Destination $destination -Force + Write-Output "Copied $extension to $destination" + } +} + +# Add to Github env +Write-Output "Setting environment variables for GitHub Actions..." + +Write-Output "CUDA_PATH=$dst" +Write-Output "CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)=$dst" +Write-Output "CUDA_PATH_VX_Y=CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)" +Write-Output "CUDA_VERSION=$CUDA_VERSION_FULL" + +Write-Output "CUDA_PATH=$dst" >> $env:GITHUB_ENV +Write-Output "CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)=$dst" >> $env:GITHUB_ENV +Write-Output "CUDA_PATH_VX_Y=CUDA_PATH_V$($CUDA_MAJOR)_$($CUDA_MINOR)" >> $env:GITHUB_ENV +Write-Output "CudaToolkitDir=$dst" >> $env:GITHUB_ENV +Write-Output "CMAKE_CUDA_COMPILER=$dst\bin\nvcc.exe" >> $env:GITHUB_ENV +Write-Output "NVCC_APPEND_FLAGS=-allow-unsupported-compiler" >> $env:GITHUB_ENV + +Write-Output "CUDA_VERSION=$CUDA_VERSION_FULL" >> $env:GITHUB_ENV +Write-Output "Setup completed."