Skip to content

Commit efaa0c0

Browse files
committed
Improve amdgpu docs: Mention device-libs and xnack
Mention amdgpu-device-libs for allocator and println support and mention the necessary target flag for GPUs from some some series without xnack support. For the last half year, there were no major changes in the amdgpu-device-libs crate (in fact, there was no need to update the crate), so I believe it is stable enough to mention it here. The xnack-support flag is something I stumbled upon recently, when more complex printlns failed on a certain GPU.
1 parent 83e49b7 commit efaa0c0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/doc/rustc/src/platform-support/amdgcn-amd-amdhsa.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ The format of binaries is a linked ELF.
2020

2121
Binaries must be built with no-std.
2222
They can use `core` and `alloc` (`alloc` only if an allocator is supplied).
23-
At least one function needs to use the `"gpu-kernel"` calling convention and should be marked with `no_mangle` for simplicity.
24-
Functions using the `"gpu-kernel"` calling convention are kernel entrypoints and can be used from the host runtime.
23+
At least one function should use the `"gpu-kernel"` calling convention and should be marked with `no_mangle` or `export_name`.
24+
Functions using the `"gpu-kernel"` calling convention are kernel entrypoints and can be launched from the host runtime.
2525

2626
## Building the target
2727

@@ -34,6 +34,9 @@ The generations are exposed as different target-cpus in the backend.
3434
As there are many, Rust does not ship pre-compiled libraries for this target.
3535
Therefore, you have to build your own copy of `core` by using `cargo -Zbuild-std=core` or similar.
3636

37+
An allocator and `println!()` support is provided by the [`amdgpu-device-libs`] crate.
38+
Both features rely on the [HIP] runtime.
39+
3740
To build a binary, create a no-std library:
3841
```rust,ignore (platform-specific)
3942
// src/lib.rs
@@ -65,13 +68,16 @@ lto = true
6568

6669
The target-cpu must be from the list [supported by LLVM] (or printed with `rustc --target amdgcn-amd-amdhsa --print target-cpus`).
6770
The GPU version on the current system can be found e.g. with [`rocminfo`].
71+
For a GPU series that has xnack support but the target GPU has not, the `-xnack-support` target-feature needs to be enabled.
72+
I.e. if the ISA info as printed with [`rocminfo`] says something about `xnack-`, e.g. `gfx1010:xnack-`, add `-Ctarget-feature=-xnack-support` to the rustflags.
6873

6974
Example `.cargo/config.toml` file to set the target and GPU generation:
7075
```toml
7176
# .cargo/config.toml
7277
[build]
7378
target = "amdgcn-amd-amdhsa"
7479
rustflags = ["-Ctarget-cpu=gfx1100"]
80+
# Add "-Ctarget-feature=-xnack-support" for xnack- GPUs (see above)
7581

7682
[unstable]
7783
build-std = ["core"] # Optional: "alloc"
@@ -85,8 +91,6 @@ Example code on how to load a compiled binary and run it is available in [ROCm e
8591

8692
On Linux, binaries can also run through the HSA runtime as implemented in [ROCR-Runtime].
8793

88-
<!-- Mention an allocator once a suitable one exists for amdgpu -->
89-
9094
<!--
9195
## Testing
9296
@@ -109,3 +113,4 @@ More information can be found on the [LLVM page for amdgpu].
109113
[LLVM page for amdgpu]: https://llvm.org/docs/AMDGPUUsage.html
110114
[`rocminfo`]: https://github.com/ROCm/rocminfo
111115
[ROCm examples]: https://github.com/ROCm/rocm-examples/tree/ca8ef5b6f1390176616cd1c18fbc98785cbc73f6/HIP-Basic/module_api
116+
[`amdgpu-device-libs`]: https://crates.io/crates/amdgpu-device-libs

0 commit comments

Comments
 (0)