diff --git a/src/offload/usage.md b/src/offload/usage.md index 90e72b9858..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,32 +70,32 @@ 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`
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! ```