Skip to content

offload: remove device.bin and pass device bitcode directly - #164455

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
sgasho:offload-cleanup-1
Oct 18, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
sgasho:offload-cleanup-1

Conversation

@sgasho

@sgasho sgasho commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

related: #164057

Since #162309 removed the clang-linker-wrapper step, nothing reads device.bin
anymore, and its triple/arch are already in the bitcode.

So, as the first step, I removed steps generating and extracting device.bin, instead we're going to use the device bitcode.

As a next step, the host pass could take the linked device output(.ptx for NVPTX, .elf for AMDGPU) instead, which
would remove the second codegen. I'd like to do that in a separate PR.

I'll update rustc-dev-guide in a follow-up PR in their repo.

I verified that this change works by running offload sample code on UofT gpunode.

r? ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. labels Oct 17, 2026
@ZuseZ4

ZuseZ4 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Iterating over all functions to get a target-cpu doesn't seem great, but should work for now and become unnecessary with the follow-up PR, so lgtm. Thanks!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 80d95cc has been approved by ZuseZ4

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 17, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 18, 2026
offload: remove device.bin and pass device bitcode directly

related: #164057

Since #162309 removed the `clang-linker-wrapper` step, nothing reads `device.bin`
anymore, and its triple/arch are already in the bitcode.

So, as the first step, I removed steps generating and extracting device.bin, instead we're going to use the device bitcode.

As a next step, the host pass could take the linked device output(`.ptx` for NVPTX, `.elf` for AMDGPU) instead, which
would remove the second codegen. I'd like to do that in a separate PR.

I'll update rustc-dev-guide in a follow-up PR in their repo.

I verified that this change works by running offload sample code on UofT gpunode.

r? ZuseZ4
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-aarch64-msvc-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [run-make] tests\run-make\clear-error-blank-output stdout ----

error: rmake recipe failed to complete
status: exit code: 101
command: "C:\\a\\rust\\rust\\build\\aarch64-pc-windows-msvc\\test\\run-make\\clear-error-blank-output\\rmake.exe"
stdout: none
--- stderr -------------------------------

thread 'main' (4436) panicked at C:\a\rust\rust\tests\run-make\clear-error-blank-output\rmake.rs:11:64:
called `Result::unwrap()` on an `Err` value: Os { code: 232, kind: BrokenPipe, message: "The pipe is being closed." }
---
Currently active steps:
test::RunMake { test_compiler: Compiler { stage: 2, host: aarch64-pc-windows-msvc, forced_compiler: false }, target: aarch64-pc-windows-msvc } at src\bootstrap\src\core\build_steps\test.rs:2108
test::Compiletest { test_compiler: Compiler { stage: 2, host: aarch64-pc-windows-msvc, forced_compiler: false }, target: aarch64-pc-windows-msvc, mode: run-make, suite: "run-make", path: "tests/run-make", compare_mode: None } at src\bootstrap\src\core\build_steps\test.rs:2108
Build completed unsuccessfully in 1:59:49
make: *** [Makefile:115: ci-msvc-py] Error 1
  local time: Sat Oct 17 21:27:48 PDT 2026
  network time: Sun, 18 Oct 2026 04:27:48 GMT
##[error]Process completed with exit code 2.
##[group]Run echo "disk usage:"
echo "disk usage:"

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 18, 2026
@rust-bors

rust-bors Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 42d559d failed: CI. Failed job:

@ZuseZ4

ZuseZ4 commented Oct 18, 2026

Copy link
Copy Markdown
Member

spurious

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 80d95cc has been approved by ZuseZ4

It is now in the queue for this repository.

A failed build status on this PR was cleared due to the approval.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 18, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 18, 2026
@rust-bors

rust-bors Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: ZuseZ4
Duration: 2h 51m 55s
Pushing 33295d7 to main...

@rust-bors
rust-bors Bot merged commit 33295d7 into rust-lang:main Oct 18, 2026
15 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 02fb0a1 (parent) -> 33295d7 (this PR)

Test differences

Show 2 test diffs

2 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 33295d734447c7a2c22c44190f11bce6164a035a --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-i686-linux: 1h 11m -> 1h 57m (+63.4%)
  2. dist-arm-linux-gnueabi: 1h -> 1h 36m (+59.6%)
  3. dist-various-2: 33m 38s -> 51m 24s (+52.8%)
  4. test-x86_64-rust-for-linux: 34m 32s -> 52m 29s (+52.0%)
  5. dist-aarch64-apple: 1h 38m -> 2h 25m (+48.4%)
  6. dist-powerpc64-linux-gnu: 1h 6m -> 1h 36m (+45.6%)
  7. dist-ohos-x86_64: 56m 46s -> 1h 20m (+41.7%)
  8. test-x86_64-msvc-ext1: 2h 11m -> 1h 19m (-39.7%)
  9. test-i686-gnu-nopt-1: 1h 22m -> 1h 53m (+38.9%)
  10. test-x86_64-gnu-debug: 2h 2m -> 1h 15m (-38.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (33295d7): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (secondary -3.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-4.4%, -2.0%] 4
All ❌✅ (primary) - - 0

Cycles

Results (secondary 5.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.0% [5.0%, 5.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 489.75s -> 488.147s (-0.33%)
Artifact size: 409.00 MiB -> 408.98 MiB (-0.00%)

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 5, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 5, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 5, 2026
offload: pass the linked device image to the host pass

Closes rust-lang#164057
Follow-up to: rust-lang#164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
Rollup merge of #164896 - sgasho:offload-cleanup-2, r=ZuseZ4

offload: pass the linked device image to the host pass

Closes #164057
Follow-up to: #164455

The host pass now takes the linked device output (`<crate>.ptx` for NVPTX, `<crate>.elf` for 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

```toml
[lib]
name = "sample_offload"
path = "src/main.rs"
crate-type = ["cdylib"]
```

Without it, the runtime fails at startup

```
PluginInterface error: Failure to init kernel: "requested object was not found in the binary image" error in cuModuleGetFunction('_RNvC14sample_offload6kernel'): named symbol not found
omptarget error: Failed to load kernel _RNvC14sample_offload6kernel
```

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
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. merged-by-bors This PR was explicitly merged by bors. 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.

5 participants