Skip to content

Simplify mono entry-point computation for GPU Offload - #162279

Open
ZuseZ4 wants to merge 1 commit into
rust-lang:mainfrom
ZuseZ4:offload-device-kernel-roots
Open

Simplify mono entry-point computation for GPU Offload#162279
ZuseZ4 wants to merge 1 commit into
rust-lang:mainfrom
ZuseZ4:offload-device-kernel-roots

Conversation

@ZuseZ4

@ZuseZ4 ZuseZ4 commented Sep 4, 2026

Copy link
Copy Markdown
Member

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 :)

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 4, 2026
@ZuseZ4
ZuseZ4 marked this pull request as ready for review September 4, 2026 06:32
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 4, 2026
@ZuseZ4 ZuseZ4 added the F-gpu_offload `#![feature(gpu_offload)]` label Sep 4, 2026
`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
ZuseZ4 force-pushed the offload-device-kernel-roots branch from 5a5e62e to 9d291cb Compare September 4, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs F-gpu_offload `#![feature(gpu_offload)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants