From 1aafc99b993b25a83a7d632d8bf47354a95c9fbd Mon Sep 17 00:00:00 2001 From: sgasho Date: Fri, 6 Nov 2026 21:26:57 +0900 Subject: [PATCH 1/2] offload: simplify build commands by removing --emit=llvm-bc,llvm-ir -Csave-temps and pass the linked device image to the host pass --- src/offload/usage.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/offload/usage.md b/src/offload/usage.md index 90e72b9858..1e3a5f41aa 100644 --- a/src/offload/usage.md +++ b/src/offload/usage.md @@ -82,25 +82,24 @@ These are often referred to as "LLVM target names"[^list]. First we generate the manifest from the host code: ``` -RUSTFLAGS="--emit=llvm-bc,llvm-ir -Csave-temps -Zoffload=HostMetadata=/absolute/path/to/offload.manifest -Zunstable-options" cargo +offload build -r +RUSTFLAGS="-Zoffload=HostMetadata=/absolute/path/to/offload.manifest -Zunstable-options" cargo +offload build -r ``` This pass only writes the manifest. Now we generate the device (GPU) code, passing the manifest: ``` -RUSTFLAGS="-Ctarget-cpu=gfx90a --emit=llvm-bc,llvm-ir -Zoffload=Device=/absolute/path/to/offload.manifest -Csave-temps -Zunstable-options" cargo +offload build -Zunstable-options -r -v --target amdgcn-amd-amdhsa -Zbuild-std=core +RUSTFLAGS="-Ctarget-cpu=gfx90a -Zoffload=Device=/absolute/path/to/offload.manifest -Zunstable-options" cargo +offload build -Zunstable-options -r -v --target amdgcn-amd-amdhsa -Zbuild-std=core ``` Next we generate the host (CPU) code. ``` -DEVICE_BC=$(find $PWD/target/amdgcn-amd-amdhsa/release/build -name '.bc') -RUSTFLAGS="-C lto=fat -C embed-bitcode=yes --emit=llvm-bc,llvm-ir -Csave-temps -Zoffload=Host=$DEVICE_BC -Zunstable-options" cargo +offload build -r +RUSTFLAGS="-C lto=fat -C embed-bitcode=yes -Zoffload=Host=$PWD/target/amdgcn-amd-amdhsa/release/.elf -Zunstable-options" cargo +offload build -r ``` In the final step, you can now run your binary ``` -./target/x86_64-unknown-linux-gnu/release/binary-name +./target/release/binary-name all checks passed! ``` From d99a37abe65a5ae3ffdb82c33ebe321079abc48e Mon Sep 17 00:00:00 2001 From: sgasho Date: Sat, 7 Nov 2026 13:37:59 +0900 Subject: [PATCH 2/2] offload: update compile instructions and warning on usage.md --- src/offload/usage.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/offload/usage.md b/src/offload/usage.md index 1e3a5f41aa..b308ceeab3 100644 --- a/src/offload/usage.md +++ b/src/offload/usage.md @@ -61,11 +61,6 @@ fn main() { ``` ## Compile instructions -It is important to use a clang compiler build on the same LLVM as rustc. -Just calling clang without the full path will likely use your system clang, -which probably will be incompatible. -So either substitute clang/lld invocations below with absolute path, or set your `PATH` accordingly. - The compilation runs three passes: 1. `HostMetadata`: compile the host code, writing a manifest that lists the kernel instantiations (including generic ones) required by the host code. @@ -75,8 +70,9 @@ The compilation runs three passes:
-Replace the `target-cpu` (gfx90a) with the right code for your GPU. -These are often referred to as "LLVM target names"[^list]. +The commands below target an AMD GPU. For your GPU, change: +- `-Ctarget-cpu=gfx90a` to your GPU's target CPU (e.g. `sm_86` on NVIDIA)[^list] +- on NVIDIA, `amdgcn-amd-amdhsa` to `nvptx64-nvidia-cuda` (in `--target` and in the `-Zoffload=Host` path), and `.elf` to `.ptx`