Simplify mono entry-point computation for GPU Offload - #162279
Open
ZuseZ4 wants to merge 1 commit into
Open
Conversation
ZuseZ4
marked this pull request as ready for review
September 4, 2026 06:32
`std::offload` previously compiled too much code for the GPU. We first have a Host (CPU) compilation pass, in which we walk all `offload` intrinsics that launch a Kernel. We create a Manifest, and if we ever launch a generic kernel, than we add the kernel along with it's needed instantiations. If the launched kernel wasn't generic, we would skip it and not add it to the Manifest. During the following Device (GPU) compilation pass, we'd then add add all those generic kernels to the mono collector and force their instantiations. We'd also walk all functions and check if any non-generic functions would have a `rustc_offload_kernel` attribute, in which case we also add them to our collector. We'd also codegen all the other mono roots. After this PR, we simply write all launched Kernels into the Manifest, including the non-generic ones. When compiling for the GPU Device, we now drop all other mono roots and only add the ones from our Manifest. This makes compiling core under build-std extremely fast. To make core usage more reliable, `-Zoffload=Device` now also implies `-Zcross-crate-inline-threshold=always`, so functions will always be available. Our more aggressive mono roots computation makes it cheap.
ZuseZ4
force-pushed
the
offload-device-kernel-roots
branch
from
September 4, 2026 07:23
5a5e62e to
9d291cb
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements the smarter GPU codegen mentioned in #159566 (comment)
It reduced device compile time from 34s to 27s on a codebase where we were already using
#[cfg]a lot to minimize what we compile for the gpu.It still only removes one reason for our ugly
#[cfg(not(target..)]dance. It still needs to type-check, since we don't (yet) have std on the gpu, so some uses remain.I used an LLM for this and some related cleanups, and split this one out since it's the easiest and has the best impact.
I'd also like to test this a bit more (cc @Sa4dUs if you find issues), but let's already
r? bjorn3
This doesn't yet handle a case with multiple crates, in which case the Hostmetadata might get overwritten. That was already broken before, but now it's broken for generic and non-generic kernels. Previously, it was only broken for generic ones. There are a few similar issues to this that I'll address in a follow-up PR. One step at a time :)