Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: hermetic CUDA clang support #360

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

udaya2899
Copy link
Contributor

Partially part of #283

This PR adds the missing piece of hermetic CUDA compilation with clang. The provided compiler_deps repo (alias cuda_nvcc) wasn't enough for clang to infer everything from. Typically, it's documented in multiple places ((1), (2)) that clang expects the entire CUDA toolkit and there is no recommended "minimal" CUDA setup. Nevertheless, I found that cccl, nvcc, cudart, nvvm components were enough.

Surprisingly, I didn't need the version.json or version.txt file anymore so I removed the logic to generate the root version.json file.

In config_clang we create a new folder called clang_compiler_deps where we collect bin, lib, include files from the required components and place in a single collected folder.

We've been using this implementation for more than a month now with over 20+ cuda_library usages and cc_tests that run on NVIDIA GPU hermetically in RBE with CUDA 12.3 and LLVM 19.1.0

@udaya2899 udaya2899 force-pushed the udaya2899/clang-cuda-path branch from 9400206 to 8039d7b Compare April 29, 2025 11:42
cccl_repo = components_mapping_compat.repo_str(repository_ctx.attr.components_mapping["cccl"])

clang_cuda_path = repository_ctx.path("clang_compiler_deps")
repository_ctx.execute(["mkdir", "-p", "clang_compiler_deps"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy that this is not hermetic. It uses native mkdir which will not work on windows. I'm going to try using rules_coreutils with toolchain_utils as suggested in the rules_coreutils README here. We can use hermetic mkdir and cp from there then.

@cloudhan would you be okay to adding these two dependencies (rules_coreutils and toolchain_utils)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to create a new repo call minimal_ctk with nvcc, cudart and cccl (and maybe curand if you need it). Duplicate all the files to minimal_ctk (instead of symlink) will solve you a lot of headache.

@udaya2899 udaya2899 force-pushed the udaya2899/clang-cuda-path branch 2 times, most recently from 465f868 to 217a96b Compare April 29, 2025 12:32
…on.json and version.txt unnecessary

Signed-off-by: udayaprakash <[email protected]>
@udaya2899 udaya2899 force-pushed the udaya2899/clang-cuda-path branch from 217a96b to b44e39d Compare April 29, 2025 12:36
"%{clang_path}": clang_path_for_subst, # Will be empty if label is used
"%{clang_label}": clang_label_for_subst, # Will be empty if path is used
"%{cuda_path}": _to_forward_slash(cuda.path) if cuda.path else "cuda-not-found",
"%{cuda_path}": _to_forward_slash(cuda.path) if cuda.path else "external/rules_cuda++toolchain+cuda/clang_compiler_deps", # needs to be relative to work in RBE.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot hard code +, the encoding is bazel version specific, they previously used ~ but find + to be much faster (suprise!) so they switched.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants