-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-linker-wrapper] Pass on --cuda-path to child clang processes #149107
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
Conversation
When using clang-linker-wrapper with --cuda-path, it does not get passed on to the child device linking processes. This causes it to fail when cuda linking is involved and nvlink is not in $PATH. This patch lets the child linking process find nvlink through --cuda-path.
|
@llvm/pr-subscribers-clang Author: Ivan R. Ivanov (ivanradanov) ChangesWhen using clang-linker-wrapper with --cuda-path, it does not get passed on to the child device linking processes. This causes it to fail when cuda linking is involved and nvlink is not in $PATH. This patch lets the child linking process find nvlink through --cuda-path. Full diff: https://github.com/llvm/llvm-project/pull/149107.diff 1 Files Affected:
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9d34b62da20f5..b9e20a6534bf6 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -567,6 +567,8 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
CmdArgs.append({"-Xlinker", Args.MakeArgString(Arg)});
for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))
CmdArgs.push_back(Args.MakeArgString(Arg));
+ for (StringRef Arg : Args.getAllArgValues(OPT_cuda_path_EQ))
+ CmdArgs.push_back(Args.MakeArgString("--cuda-path=" + Arg));
if (Error Err = executeCommands(*ClangPath, CmdArgs))
return std::move(Err);
|
jhuber6
left a comment
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.
This is supposed to be handled by the forwarding interface in the Clang toolchain. Doing something like this you should see it.
$ clang input.c -fopenmp --offload-arch=sm_89 --cuda-path=/opt/cuda -###
"clang-linker-wrapper" "--device-compiler=nvptx64-nvidia-cuda=--cuda-path=/opt/cuda"Are you not getting this? That's probably a bug so it'd help to have some examples with how you're invoking this.
|
I see. I was doing this which only passes I suppose under the current infra, all the offloading compilation arguments need to be present when linking as well, so as to invoke the appropriate toolchains, and the above usage is not recommended? |
|
It's passed to the linker wrapper because it needs |
Gives me so the child of |
That's odd, can you give me the full output of |
|
I see, this is because there's no CUDA toolchain that's created in this case. Normally the |
|
passing gives us the appropriate flags. That means the cuda toolchain was created, correct? I wonder if we need a step in clang that looks at all the .o files for sections that need device linking and concats the archs, and reinvokes itself with --offload-arch=<all_collected_arches> (although it is clang-linker-wrapper's job to do the parsing of the .o files for that so kind of weird to have clang do it) But then in theory the appropriate toolchains should be created. Perhaps it can only kick in when -foffload-via-llvm is on, but no --offload-archs are specified, i.e. we are asking clang to figure the appropriate offload archs. That step could actually be handled by clang-offload-wrapper - you would get Pretty convoluted so I don't know if it's appropriate. Anyways, @jhuber6 thank you for taking a look, I think I will close this for now. |
|
Yeah that's definitely not ideal, I'll need to think of a way to handle that more gracefully. |
When using clang-linker-wrapper with --cuda-path, it does not get passed on to the child device linking processes. This causes it to fail when cuda linking is involved and nvlink is not in $PATH. This patch lets the child linking process find nvlink through --cuda-path.