Skip to content

Commit 0cee58b

Browse files
committed
Update rustc-dev-guide
1 parent a4c3e6c commit 0cee58b

File tree

2 files changed

+14
-2
lines changed
  • library/core/src/intrinsics
  • src/doc/rustc-dev-guide/src/offload

2 files changed

+14
-2
lines changed

library/core/src/intrinsics/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,9 @@ pub const fn autodiff<F, G, T: crate::marker::Tuple, R>(f: F, df: G, args: T) ->
33293329
/// unsafe { (*x)[0] = 21.0 };
33303330
/// }
33313331
/// ```
3332+
///
3333+
/// For reference, see the Clang documentation on offloading:
3334+
/// <https://clang.llvm.org/docs/OffloadingDesign.html>.
33323335
#[rustc_nounwind]
33333336
#[rustc_intrinsic]
33343337
pub const fn offload<F, T: crate::marker::Tuple, R>(f: F, args: T) -> R;

src/doc/rustc-dev-guide/src/offload/usage.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ We currently work on launching the following Rust kernel on the GPU. To follow a
55

66
```rust
77
#![feature(abi_gpu_kernel)]
8+
#![feature(rustc_attrs)]
9+
#![feature(core_intrinsics)]
810
#![no_std]
911

1012
#[cfg(target_os = "linux")]
1113
extern crate libc;
1214
#[cfg(target_os = "linux")]
1315
use libc::c_char;
1416

17+
#[cfg(target_os = "linux")]
1518
use core::mem;
1619

1720
#[panic_handler]
@@ -38,7 +41,7 @@ fn main() {
3841
}
3942

4043
unsafe {
41-
kernel_1(array_c);
44+
kernel(array_c);
4245
}
4346
core::hint::black_box(&array_c);
4447
unsafe {
@@ -52,6 +55,11 @@ fn main() {
5255
}
5356
}
5457

58+
#[inline(never)]
59+
unsafe fn kernel(x: *mut [f64; 256]) {
60+
core::intrinsics::offload(kernel_1, (x,))
61+
}
62+
5563
#[cfg(target_os = "linux")]
5664
unsafe extern "C" {
5765
pub fn kernel_1(array_b: *mut [f64; 256]);
@@ -60,6 +68,7 @@ unsafe extern "C" {
6068
#[cfg(not(target_os = "linux"))]
6169
#[unsafe(no_mangle)]
6270
#[inline(never)]
71+
#[rustc_offload_kernel]
6372
pub extern "gpu-kernel" fn kernel_1(x: *mut [f64; 256]) {
6473
unsafe { (*x)[0] = 21.0 };
6574
}
@@ -76,7 +85,7 @@ rustc +offload --edition 2024 src/lib.rs -g --crate-type cdylib -C opt-level=3 -
7685

7786
Now we generate the device code. Replace the target-cpu with the right code for your gpu.
7887
```
79-
RUSTFLAGS="-Ctarget-cpu=gfx90a --emit=llvm-bc,llvm-ir" cargo +offload build -Zunstable-options -r -v --target amdgcn-amd-amdhsa -Zbuild-std=core
88+
RUSTFLAGS="-Ctarget-cpu=gfx90a --emit=llvm-bc,llvm-ir -Zoffload=Enable -Zunstable-options" cargo +offload build -Zunstable-options -r -v --target amdgcn-amd-amdhsa -Zbuild-std=core
8089
```
8190

8291
Now find the `<libname>.ll` under target/amdgcn-amd-amdhsa folder and copy it to a device.ll file (or adjust the file names below).

0 commit comments

Comments
 (0)