Skip to content

Commit 970f1b1

Browse files
committed
doc update and better error
1 parent 3abf2a2 commit 970f1b1

File tree

2 files changed

+14
-8
lines changed
  • compiler/rustc_codegen_llvm/src/back
  • src/doc/rustc-dev-guide/src/offload

2 files changed

+14
-8
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,18 @@ pub(crate) unsafe fn llvm_optimize(
799799
let device_pathbuf = PathBuf::from(device_path);
800800
if device_pathbuf.is_relative() {
801801
panic!("Absolute path is needed");
802+
} else if device_pathbuf
803+
.file_name()
804+
.and_then(|n| n.to_str())
805+
.is_some_and(|n| n != "host.out")
806+
{
807+
panic!("Need path to the host.out file");
802808
}
803809
assert!(device_pathbuf.exists());
804810
let host_dir = device_pathbuf.parent().unwrap();
805-
let host_out = host_dir.join("host.out");
811+
//let host_out = host_dir.join("host.out");
806812
let out_obj = host_dir.join("host.o");
807-
let host_out_c = path_to_c_string(host_out.as_path());
813+
let host_out_c = path_to_c_string(device_pathbuf.as_path());
808814

809815
// 2) Finalize host: lib.bc + host.out -> host.offload.o (host TM created in C++)
810816
let llmod2 = llvm::LLVMCloneModule(module.module_llvm.llmod());

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,25 @@ pub extern "gpu-kernel" fn kernel_1(x: *mut [f64; 256]) {
7777
## Compile instructions
7878
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.
7979

80-
First we generate the host (cpu) code.
80+
First we generate the device (gpu) code. Replace the target-cpu with the right code for your gpu.
8181
```
82-
RUSTFLAGS="--emit=llvm-bc -Zoffload=Enable -Zunstable-options" cargo +offload build -r
82+
RUSTFLAGS="-Ctarget-cpu=gfx90a --emit=llvm-bc,llvm-ir -Zoffload=Device -Csave-temps -Zunstable-options" cargo +offload build -Zunstable-options -r -v --target amdgcn-amd-amdhsa -Zbuild-std=core
8383
```
8484
You might afterwards need to copy your target/release/deps/<lib_name>.bc to lib.bc for now, before the next step.
8585

86-
Now we generate the device code. Replace the target-cpu with the right code for your gpu.
86+
Now we generate the host (cpu) code.
8787
```
88-
RUSTFLAGS="-Ctarget-cpu=gfx90a -Zoffload=Enable -Zunstable-options" cargo +offload build -Zunstable-options -r --target amdgcn-amd-amdhsa -Zbuild-std=core
88+
RUSTFLAGS="--emit=llvm-bc,llvm-ir -Csave-temps -Zoffload=Host=/p/lustre1/drehwald1/prog/offload/r/target/amdgcn-amd-amdhsa/release/deps/host.out -Zunstable-options" cargo +offload build -r
8989
```
9090
This call also does a lot of work and generates multiple intermediate files for llvm offload.
9191
While we integrated most offload steps into rustc by now, one binary invocation still remains for now:
9292

9393
```
94-
"clang-linker-wrapper" "--should-extract=gfx90a" "--device-compiler=amdgcn-amd-amdhsa=-g" "--device-compiler=amdgcn-amd-amdhsa=-save-temps=cwd" "--device-linker=amdgcn-amd-amdhsa=-lompdevice" "--host-triple=x86_64-unknown-linux-gnu" "--save-temps" "--linker-path=/ABSOlUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/lld/bin/ld.lld" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-pie" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "bare" "/lib/../lib64/Scrt1.o" "/lib/../lib64/crti.o" "/ABSOLUTE_PATH_TO/crtbeginS.o" "-L/ABSOLUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/llvm/bin/../lib/x86_64-unknown-linux-gnu" "-L/ABSOLUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/llvm/lib/clang/21/lib/x86_64-unknown-linux-gnu" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "host.o" "-lstdc++" "-lm" "-lomp" "-lomptarget" "-L/ABSOLUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/llvm/lib" "-lgcc_s" "-lgcc" "-lpthread" "-lc" "-lgcc_s" "-lgcc" "/ABSOLUTE_PATH_TO/crtendS.o" "/lib/../lib64/crtn.o"
94+
"clang-linker-wrapper" "--should-extract=gfx90a" "--device-compiler=amdgcn-amd-amdhsa=-g" "--device-compiler=amdgcn-amd-amdhsa=-save-temps=cwd" "--device-linker=amdgcn-amd-amdhsa=-lompdevice" "--host-triple=x86_64-unknown-linux-gnu" "--save-temps" "--linker-path=/ABSOlUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/lld/bin/ld.lld" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-pie" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "bare" "/lib/../lib64/Scrt1.o" "/lib/../lib64/crti.o" "/ABSOLUTE_PATH_TO/crtbeginS.o" "-L/ABSOLUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/llvm/bin/../lib/x86_64-unknown-linux-gnu" "-L/ABSOLUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/llvm/lib/clang/21/lib/x86_64-unknown-linux-gnu" "-L/lib/../lib64" "-L/usr/lib64" "-L/lib" "-L/usr/lib" "target/<GPU_DIR>/release/host.o" "-lstdc++" "-lm" "-lomp" "-lomptarget" "-L/ABSOLUTE_PATH_TO/rust/build/x86_64-unknown-linux-gnu/llvm/lib" "-lgcc_s" "-lgcc" "-lpthread" "-lc" "-lgcc_s" "-lgcc" "/ABSOLUTE_PATH_TO/crtendS.o" "/lib/../lib64/crtn.o"
9595
```
9696

9797
You can try to find the paths to those files on your system. However, I recommend to not fix the paths, but rather just re-generate them by copying a bare-mode openmp example and compiling it with your clang. By adding `-###` to your clang invocation, you can see the invidual steps.
98-
It will show multiple steps, just look for the clang-linker-wrapper example. Make sure to still include the `host.o` file, and not whatever tmp file you got when compiling your c++ example with the following call.
98+
It will show multiple steps, just look for the clang-linker-wrapper example. Make sure to still include the path to the `host.o` file, and not whatever tmp file you got when compiling your c++ example with the following call.
9999
```
100100
myclang++ -fuse-ld=lld -O3 -fopenmp -fopenmp-offload-mandatory --offload-arch=gfx90a omp_bare.cpp -o main -###
101101
```

0 commit comments

Comments
 (0)