Repository navigation
Build HPX with CUDA on Windows using clang (experimental) #8150
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
11d507d
Build HPX on Windows with clang as the CUDA compiler
hkaiser 4d713cf
Add a toolchain file, a preset and documentation for CUDA on Windows
hkaiser 0016a6b
Add a Windows CI job building the CUDA tests with clang
hkaiser 35b67f4
Print the configure log of the clang CUDA CI job if it fails
hkaiser 744f188
Install curand for the clang CUDA CI job
hkaiser fe02d99
Build the clang CUDA CI job with the standard library of Visual Studi…
hkaiser 48cc3ac
Install CUDA 13.5 in the clang CUDA CI job and require CCCL 3.4
hkaiser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Copyright (c) 2026 The STE||AR Group | ||
| # | ||
| # SPDX-License-Identifier: BSL-1.0 | ||
| # Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| name: Windows CI (Release, clang, CUDA) | ||
|
|
||
| on: [pull_request] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| # the standard library of Visual Studio 2022 (MSVC 14.44) doesn't compile | ||
| # with clang in CUDA mode: std::lerp(long double) calls an fma() that is | ||
| # ambiguous in the device compilation | ||
| runs-on: windows-2025-vs2026 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - uses: lukka/get-cmake@v4.5.0 | ||
|
|
||
| - name: Install dependencies | ||
| uses: ./.github/actions/setup-vcpkg | ||
| # the runner has no GPU, so this job only builds the CUDA code, with clang | ||
| # as the C++ and CUDA compiler (cmake/toolchains/Windows-Clang-CUDA.cmake); | ||
| # clang needs the CUDA headers (including the curand ones its CUDA runtime | ||
| # wrapper includes), libraries, libdevice and ptxas, and CCCL 3.4 or newer | ||
| # (CUDA 13.4 or newer); the components are unpacked from NVIDIA's | ||
| # redistributable archives, which have the layout of a CUDA installation | ||
| - name: Install CUDA | ||
| shell: python | ||
| run: | | ||
| import hashlib, json, os, shutil, urllib.request, zipfile | ||
|
|
||
| base = "https://developer.download.nvidia.com/compute/cuda/redist/" | ||
| components = ["cuda_nvcc", "cuda_cudart", "cuda_crt", "libnvvm", | ||
| "cccl", "libcurand", "libcublas"] | ||
| temp = os.environ["RUNNER_TEMP"] | ||
| root = os.path.join(temp, "cuda").replace("\\", "/") | ||
|
|
||
| with urllib.request.urlopen(base + "redistrib_13.5.0.json") as r: | ||
| manifest = json.load(r) | ||
| for component in components: | ||
| entry = manifest[component]["windows-x86_64"] | ||
| archive = os.path.join(temp, component + ".zip") | ||
| urllib.request.urlretrieve(base + entry["relative_path"], archive) | ||
| sha256 = hashlib.sha256() | ||
| with open(archive, "rb") as f: | ||
| for chunk in iter(lambda: f.read(1 << 20), b""): | ||
| sha256.update(chunk) | ||
| if sha256.hexdigest() != entry["sha256"]: | ||
| raise SystemExit(f"{component}: checksum mismatch") | ||
| # strip the archive's top-level directory | ||
| with zipfile.ZipFile(archive) as z: | ||
| for member in z.infolist(): | ||
| path = member.filename.split("/", 1) | ||
| if member.is_dir() or len(path) < 2: | ||
| continue | ||
| target = os.path.join(root, path[1]) | ||
| os.makedirs(os.path.dirname(target), exist_ok=True) | ||
| with z.open(member) as src, open(target, "wb") as dst: | ||
| shutil.copyfileobj(src, dst) | ||
| os.remove(archive) | ||
| print(component, manifest[component]["version"]) | ||
| with open(os.environ["GITHUB_ENV"], "a") as f: | ||
| f.write(f"CUDA_PATH={root}\n") | ||
| # a fixed clang, independent of the runner image: unpack the LLVM | ||
| # release archive (a .tar.xz) so that bin is directly in LLVM_PATH | ||
| - name: Install clang | ||
| shell: bash | ||
| run: | | ||
| llvm="$(cygpath -m "$RUNNER_TEMP")/llvm" | ||
| mkdir -p "$llvm" | ||
| curl -fsSL https://github.com/llvm/llvm-project/releases/download/llvmorg-22.1.8/clang+llvm-22.1.8-x86_64-pc-windows-msvc.tar.xz | tar -xJ --strip-components=1 -C "$llvm" | ||
| "$llvm/bin/clang.exe" --version | ||
| echo "LLVM_PATH=$llvm" >> "$GITHUB_ENV" | ||
| # the standard library and the Windows SDK for clang and Ninja | ||
| - uses: ./.github/actions/msvc-dev-env | ||
|
|
||
| - name: Configure | ||
| shell: bash | ||
| run: | | ||
| cmake . -Bbuild -GNinja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_TOOLCHAIN_FILE='C:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake' \ | ||
| -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="$(cygpath -m "$PWD")/cmake/toolchains/Windows-Clang-CUDA.cmake" \ | ||
| -DHPX_CLANG_ROOT="$(cygpath -m "$LLVM_PATH")" \ | ||
| -DCUDAToolkit_ROOT="$(cygpath -m "$CUDA_PATH")" \ | ||
| -DCMAKE_CUDA_ARCHITECTURES=89 \ | ||
| -DHPX_WITH_CUDA=ON \ | ||
| -DHPX_WITH_FETCH_ASIO=ON \ | ||
| -DHPX_WITH_EXAMPLES=OFF \ | ||
| -DHPX_WITH_TESTS=ON \ | ||
| -DHPX_WITH_TESTS_UNIT=ON \ | ||
| -DHPX_WITH_TESTS_BENCHMARKS=ON \ | ||
| -DHPX_WITH_DEPRECATION_WARNINGS=OFF \ | ||
| -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On | ||
| # what the compiler checks (e.g. the CUDA compiler identification) printed | ||
| - name: Print the configure log | ||
| if: failure() | ||
| shell: bash | ||
| run: | | ||
| cat build/CMakeFiles/CMakeConfigureLog.yaml || true | ||
| # build the CUDA tests (and everything they depend on), including the | ||
| # stdexec based ones, which nvcc can't compile with an MSVC host compiler | ||
| - name: Build | ||
| shell: bash | ||
| run: | | ||
| cmake --build build --target \ | ||
| stdexec_cuda_test algorithm_sender_cuda_test \ | ||
| cuda_future_test cuda_multi_device_polling_test \ | ||
| transform_stream_test synchronize_test \ | ||
| cuda_executor_throughput_test \ | ||
| thrust_policy_traits_test thrust_policy_test_test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # Copyright (c) 2026 Hartmut Kaiser | ||
| # | ||
| # SPDX-License-Identifier: BSL-1.0 | ||
| # Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| # Builds HPX on Windows with clang as the CUDA compiler (instead of nvcc, which | ||
| # can't compile stdexec with MSVC as the host compiler). CMake requires the same | ||
| # clang front end for all languages, so C and C++ are compiled by clang/clang++ | ||
| # too (GNU-like command line, MSVC ABI and standard library). | ||
| # | ||
| # Use it with the Ninja generator from a Visual Studio developer prompt (for the | ||
| # MSVC standard library and the Windows SDK): | ||
| # | ||
| # ~~~ | ||
| # cmake -G Ninja | ||
| # -DCMAKE_TOOLCHAIN_FILE=<hpx>/cmake/toolchains/Windows-Clang-CUDA.cmake | ||
| # -DHPX_WITH_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=<arch> ... | ||
| # ~~~ | ||
| # | ||
| # HPX_CLANG_ROOT selects the clang installation (the directory containing | ||
| # bin/clang.exe), the default is the newest clang of an LLVM installation or a | ||
| # Visual Studio installation, otherwise the one on the PATH. The CUDA toolkit is | ||
| # taken from CUDAToolkit_ROOT or the CUDA_PATH environment variable. | ||
|
|
||
| set(HPX_CLANG_ROOT | ||
| "" | ||
| CACHE PATH "The clang installation to use (containing bin/clang.exe)" | ||
| ) | ||
|
|
||
| if(HPX_CLANG_ROOT) | ||
| # only the clang of the given installation | ||
| set(_hpx_clang_search PATHS "${HPX_CLANG_ROOT}/bin" NO_DEFAULT_PATH) | ||
| else() | ||
| # the newest clang of an LLVM or a Visual Studio installation | ||
| file( | ||
| GLOB | ||
| _hpx_clang_candidates | ||
| "$ENV{ProgramFiles}/LLVM/bin/clang.exe" | ||
| "$ENV{ProgramFiles}/Microsoft Visual Studio/*/*/VC/Tools/Llvm/x64/bin/clang.exe" | ||
| ) | ||
| set(_hpx_clang_hints) | ||
| set(_hpx_clang_newest 0) | ||
| foreach(_hpx_clang IN LISTS _hpx_clang_candidates) | ||
| execute_process( | ||
| COMMAND "${_hpx_clang}" -dumpversion | ||
| OUTPUT_VARIABLE _hpx_clang_version | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| RESULT_VARIABLE _hpx_clang_result | ||
| ) | ||
| if(_hpx_clang_result EQUAL 0 AND _hpx_clang_version VERSION_GREATER | ||
| _hpx_clang_newest | ||
| ) | ||
| set(_hpx_clang_newest "${_hpx_clang_version}") | ||
| get_filename_component(_hpx_clang_hints "${_hpx_clang}" DIRECTORY) | ||
| endif() | ||
| endforeach() | ||
| unset(_hpx_clang) | ||
| unset(_hpx_clang_candidates) | ||
| unset(_hpx_clang_newest) | ||
| unset(_hpx_clang_result) | ||
| unset(_hpx_clang_version) | ||
| set(_hpx_clang_search HINTS ${_hpx_clang_hints}) | ||
| unset(_hpx_clang_hints) | ||
| endif() | ||
|
|
||
| find_program( | ||
| HPX_CLANG_EXECUTABLE clang.exe ${_hpx_clang_search} | ||
| DOC "The clang executable used for C, C++ and CUDA" | ||
| ) | ||
| find_program( | ||
| HPX_CLANGXX_EXECUTABLE clang++.exe ${_hpx_clang_search} | ||
| DOC "The clang++ executable used for C++" | ||
| ) | ||
| unset(_hpx_clang_search) | ||
|
|
||
| if(NOT HPX_CLANG_EXECUTABLE OR NOT HPX_CLANGXX_EXECUTABLE) | ||
| message(FATAL_ERROR "clang was not found, set HPX_CLANG_ROOT") | ||
| endif() | ||
|
|
||
| # an older clang doesn't know the CUDA versions HPX requires, and CMake would | ||
| # fail on it with less helpful errors (see also cmake/HPX_SetupCUDA.cmake) | ||
| execute_process( | ||
| COMMAND "${HPX_CLANG_EXECUTABLE}" -dumpversion | ||
| OUTPUT_VARIABLE _hpx_clang_version | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ) | ||
| if(_hpx_clang_version VERSION_LESS 22.1) | ||
| message( | ||
| FATAL_ERROR | ||
| "Building HPX with CUDA on Windows requires clang 22.1 or newer, found ${_hpx_clang_version} (${HPX_CLANG_EXECUTABLE}), set HPX_CLANG_ROOT" | ||
| ) | ||
| endif() | ||
| unset(_hpx_clang_version) | ||
|
|
||
| set(CMAKE_C_COMPILER "${HPX_CLANG_EXECUTABLE}") | ||
| set(CMAKE_CXX_COMPILER "${HPX_CLANGXX_EXECUTABLE}") | ||
| set(CMAKE_CUDA_COMPILER "${HPX_CLANG_EXECUTABLE}") | ||
|
|
||
| if(NOT CUDAToolkit_ROOT AND DEFINED ENV{CUDA_PATH}) | ||
| file(TO_CMAKE_PATH "$ENV{CUDA_PATH}" CUDAToolkit_ROOT) | ||
| endif() | ||
|
|
||
| if(CUDAToolkit_ROOT) | ||
| set(CUDAToolkit_ROOT | ||
| "${CUDAToolkit_ROOT}" | ||
| CACHE PATH "The CUDA toolkit to use" | ||
| ) | ||
| # clang finds the CUDA toolkit in the standard locations only | ||
| string(APPEND CMAKE_CUDA_FLAGS_INIT " \"--cuda-path=${CUDAToolkit_ROOT}\"") | ||
| endif() | ||
|
|
||
| # clang supports a CUDA toolkit newer than it knows about for most uses | ||
| string(APPEND CMAKE_CUDA_FLAGS_INIT " -Wno-unknown-cuda-version") | ||
|
|
||
| # the compiler checks (try_compile) load this file again: they must select the | ||
| # same clang and CUDA toolkit | ||
| list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES HPX_CLANG_ROOT | ||
| CUDAToolkit_ROOT | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve compiler selection in
try_compileprojects.If clang 22.1 is installed only under a custom
HPX_CLANG_ROOT, the main configure finds it. Compiler-check projects reload this toolchain without that custom variable. Discovery can then select an older Visual Studio clang and stop configuration at Line 87. CMake requires explicit propagation of custom toolchain variables. (cmake.org)Add
HPX_CLANG_ROOTand the executable overrides toCMAKE_TRY_COMPILE_PLATFORM_VARIABLES. This preserves explicit selection without changing default discovery.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 667c93d:
HPX_CLANG_ROOTandCUDAToolkit_ROOTare added toCMAKE_TRY_COMPILE_PLATFORM_VARIABLES, so the compiler checks select the same clang and CUDA toolkit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysis chain
Script executed:
Length of output: 5897
Script executed:
Length of output: 2251
web_search executed:
CMake 3.18 official documentation or source: in source-file try_compile projects, are custom toolchain cache variables created by find_program automatically propagated, or must they be listed in CMAKE_TRY_COMPILE_PLATFORM_VARIABLES? Does the nested project reload the toolchain file?Length of output: 10859
@hkaiserThe customHPX_CLANG_ROOTcase is addressed. However, the toolchain does not propagateHPX_CLANG_EXECUTABLEorHPX_CLANGXX_EXECUTABLE. If either is set directly, atry_compileproject can rediscover a different compiler.Please add both variables to
CMAKE_TRY_COMPILE_PLATFORM_VARIABLES. I could not run a CMake check because CMake is not installed in the inspection environment. I’m not marking the finding as addressed yet.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
You are interacting with an AI system.