Skip to content

Offload: support launch in lib - #166576

Open
kjetilkjeka wants to merge 2 commits into
rust-lang:mainfrom
kjetilkjeka:offload-launch-in-lib
Open

kjetilkjeka wants to merge 2 commits into
rust-lang:mainfrom
kjetilkjeka:offload-launch-in-lib

Conversation

@kjetilkjeka

@kjetilkjeka kjetilkjeka commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

This solves another one of the blockers for using offload kernels (tracking issue #131513) with cargo dependencies. This makes it possible to launch kernels from dependencies. The test shows that the kernels are generated in the appropriate device compilations. My local tests also include linking by running on my cargo fork with offload support and it links and runs correctly.

This does not change anything related to the crate loading limitation

The first part of allowing to launch kernels in a lib is to call -Zoffload=Host without providing a device image when building an rlib. The device part of the library is not bundled into the host .rlib, they're instead kept separate until linking. With these changes we don't even need to have the device image when building for Host, and since the normal Host stage now also produce the offload manifest we don't need to run the -Zoffload=HostMetadata at all if we compile device after host when not linking.

The second part is not requiring -Clto=fat when building an .rlib. Cargo doesn't pass it to rustc when building an .rlib and doing so wouldn't make much sense (it's called link-time for a reason). This PR makes the change to only require it when there's anything else than an .rlib being produced.

There's also a change here that is not strictly required. Instead of allowing to pass -Zoffload=Host with an optional path I instead added the -Zoffload=DeviceImage=<path> that must be used when linking. This is to make the two things (1. is this an offload host compile, and 2. does this invocation include linking) additive instead of having to change a Host to a Host=<path>. The name is also a bit more self-documenting. I believe it to be a positive UI change, but it's easy to get rid of if it's not welcome.

To make the UI even cleaner and close to what cargo already deals with there's a follow up Draft MR (#166585). That one adds the offload manifest in an --emit so the names needs some extra scrutiny and an MCP.

@rustbot label +F-gpu_offload

r? @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. F-gpu_offload `#![feature(gpu_offload)]` labels Nov 25, 2026
 - Makes it possible to pass `-Zoffload=Host` without path, we don't embed device code in host libs
 - Don't require `lto=fat` when building rlibs
 - Host emits offload manifest in out-dir
 - Separate DeviceImage flag when the device image should be embedded
 - No need for Test flag due to the more modular system
@kjetilkjeka
kjetilkjeka force-pushed the offload-launch-in-lib branch from 16abe35 to 552ea74 Compare November 26, 2026 07:59
@kjetilkjeka
kjetilkjeka marked this pull request as ready for review November 26, 2026 08:04
@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 Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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