Repository navigation
Conversation
|
Thank you for also solving the fixme along the way. I'm at the llvm dev till wednesday, but I'll try to test it a bit in between. @kjetilkjeka you had some ideas on how to configure cpu vs gpu builds, right? fyi @xkevio |
|
For my cargo experiment with offload support this is a step in the right direction, with a little regression. It fits well within the model of building a single "cdylib" (ptx/elf) for the device compilation per binary (as opposed to one per crate). The unfortunate regression is of course that a crate with a single I checked out your PR and added a mapping in I haven't got far enough to test |
This comment has been minimized.
This comment has been minimized.
|
Thanks. I agree that independently of the final design we almost never want to compile the GPU code as a normal binary, even if libc-for-gpu might allow us to do such cursed/funny things. So for now mapping the GPU cratetype seems like the right call, @sgasho can you try to add that? I'd expect that if we remap it early enough it should be unproblematic |
0d7ede9 to
4e185cd
Compare
|
Thanks both. I added the Executable → Cdylib mapping in |
| // GPU code is never run as a binary; the offload runtime looks up kernels by | ||
| // name, and only cdylibs export their symbols. | ||
| if session.opts.unstable_opts.offload.iter().any(|o| matches!(o, Offload::Device(_))) { | ||
| for crate_type in &mut base { |
There was a problem hiding this comment.
If a user already requests both the executable and the cdylib, this would end up with two cdylib requests. Can you sort and dedup again?
There was a problem hiding this comment.
I noticed that we cannot sort + dedup them. It breaks the device build.
error: output of --print=file-names missing when learning about target-specific information from rustc
command was: `/w/333/shotasugano/rust-env/rustup/toolchains/offload-local/bin/rustc - --crate-name ___ --print=file-names -Ctarget-cpu=sm_86 -Zoffload=Device -Zunstable-options --target nvptx64-nvidia-cuda --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg -Wwarnings`
--- stdout
lib___.rlib
lib___.a
___.ptx
It seems that cargo reads the file names in the order of --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro , and sort + dedup broke the correspondence between crate types and file names.
|
Thanks, another hundred lines saved. I tested it on an AMD igpu, where it also works. |
Closes #164057
Follow-up to: #164455
The host pass now takes the linked device output (
<crate>.ptxfor NVPTX,<crate>.elffor AMDGPU) instead of the device bitcode.The device crate must now be built as a cdylib. rustc only passes --export-symbol to llvm-bitcode-linker for cdylibs, so a bin would lose its kernels to internalization.
I had to add [lib] in Cargo.toml
Without it, the runtime fails at startup
I’m not sure whether bin device crates should export their kernels too, so I left the linker untouched for now.
The second commit fixes another runtime error without
--emit=llvm-bc/llvm-ir. (my understanding is that we should not have to set these after this PR, because no device.bc anymore)The “already wrapped” check in handle_offload relied on a value name, which LLVM drops unless --emit=llvm-bc/llvm-ir is given, so the kernel got wrapped twice.
I verified on UofT nvidia gpunode (amdgpunodes was not available for my account).
r? ZuseZ4