Skip to content

Commit 2456df1

Browse files
Rollup merge of #156941 - ZuseZ4:update-offload-file-naming, r=oli-obk
Offload: Update confusing and outdated file name We swapped the order in which we do host and device compilations. The file getting renamed is effectively the output of the clang-offload-packager, the first magic bytes (`00000000 10 ff 10 ad`) confirm it. I was just creating a figure to visualize and noticed that the name is off. cc @kevinsala @jdoerfert is there any naming convention? r? oli-obk
2 parents fdf56d2 + 1ffcca7 commit 2456df1

4 files changed

Lines changed: 22 additions & 20 deletions

File tree

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -805,10 +805,10 @@ pub(crate) unsafe fn llvm_optimize(
805805
if cgcx.target_is_like_gpu && config.offload.contains(&config::Offload::Device) {
806806
let device_path = cgcx.output_filenames.path(OutputType::Object);
807807
let device_dir = device_path.parent().unwrap();
808-
let device_out = device_dir.join("host.out");
808+
let device_out = device_dir.join("device.bin");
809809
let device_out_c = path_to_c_string(device_out.as_path());
810810
unsafe {
811-
// 1) Bundle device module into offload image host.out (device TM)
811+
// 1) Bundle device module into offload image device.bin (device TM)
812812
let ok = llvm::LLVMRustBundleImages(
813813
module.module_llvm.llmod(),
814814
module.module_llvm.tm.raw(),
@@ -821,7 +821,7 @@ pub(crate) unsafe fn llvm_optimize(
821821
}
822822

823823
// This assumes that we previously compiled our kernels for a gpu target, which created a
824-
// `host.out` artifact. The user is supposed to provide us with a path to this artifact, we
824+
// `device.bin` artifact. The user is supposed to provide us with a path to this artifact, we
825825
// don't need any other artifacts from the previous run. We will embed this artifact into our
826826
// LLVM-IR host module, to create a `host.o` ObjectFile, which we will write to disk.
827827
// The last, not yet automated steps uses the `clang-linker-wrapper` to process `host.o`.
@@ -837,7 +837,7 @@ pub(crate) unsafe fn llvm_optimize(
837837
} else if device_pathbuf
838838
.file_name()
839839
.and_then(|n| n.to_str())
840-
.is_some_and(|n| n != "host.out")
840+
.is_some_and(|n| n != "device.bin")
841841
{
842842
dcx.emit_err(crate::errors::OffloadWrongFileName);
843843
} else if !device_pathbuf.exists() {
@@ -846,14 +846,14 @@ pub(crate) unsafe fn llvm_optimize(
846846
let host_path = cgcx.output_filenames.path(OutputType::Object);
847847
let host_dir = host_path.parent().unwrap();
848848
let out_obj = host_dir.join("host.o");
849-
let host_out_c = path_to_c_string(device_pathbuf.as_path());
849+
let device_bin_c = path_to_c_string(device_pathbuf.as_path());
850850

851-
// 2) Finalize host: lib.bc + host.out -> host.o (host TM)
851+
// 2) Finalize host: lib.bc + device.bin -> host.o (host TM)
852852
// We create a full clone of our LLVM host module, since we will embed the device IR
853853
// into it, and this might break caching or incremental compilation otherwise.
854854
let llmod2 = llvm::LLVMCloneModule(module.module_llvm.llmod());
855855
let ok =
856-
unsafe { llvm::LLVMRustOffloadEmbedBufferInModule(llmod2, host_out_c.as_ptr()) };
856+
unsafe { llvm::LLVMRustOffloadEmbedBufferInModule(llmod2, device_bin_c.as_ptr()) };
857857
if !ok {
858858
dcx.emit_err(crate::errors::OffloadEmbedFailed);
859859
}
@@ -868,7 +868,7 @@ pub(crate) unsafe fn llvm_optimize(
868868
prof,
869869
true,
870870
);
871-
// We ignore cgcx.save_temps here and unconditionally always keep our `host.out` artifact.
871+
// We ignore cgcx.save_temps here and unconditionally always keep our `device.bin` artifact.
872872
// Otherwise, recompiling the host code would fail since we deleted that device artifact
873873
// in the previous host compilation, which would be confusing at best.
874874
}

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,33 @@ pub(crate) struct AutoDiffWithoutLto;
5858
pub(crate) struct AutoDiffWithoutEnable;
5959

6060
#[derive(Diagnostic)]
61-
#[diag("using the offload feature requires -Z offload=<Device or Host=/absolute/path/to/host.out>")]
61+
#[diag(
62+
"using the offload feature requires -Z offload=<Device or Host=/absolute/path/to/device.bin>"
63+
)]
6264
pub(crate) struct OffloadWithoutEnable;
6365

6466
#[derive(Diagnostic)]
6567
#[diag("using the offload feature requires -C lto=fat")]
6668
pub(crate) struct OffloadWithoutFatLTO;
6769

6870
#[derive(Diagnostic)]
69-
#[diag("using the `-Z offload=Host=/absolute/path/to/host.out` flag requires an absolute path")]
71+
#[diag("using the `-Z offload=Host=/absolute/path/to/device.bin` flag requires an absolute path")]
7072
pub(crate) struct OffloadWithoutAbsPath;
7173

7274
#[derive(Diagnostic)]
7375
#[diag(
74-
"using the `-Z offload=Host=/absolute/path/to/host.out` flag must point to a `host.out` file"
76+
"using the `-Z offload=Host=/absolute/path/to/device.bin` flag must point to a `device.bin` file"
7577
)]
7678
pub(crate) struct OffloadWrongFileName;
7779

7880
#[derive(Diagnostic)]
7981
#[diag(
80-
"the given path/file to `host.out` does not exist. Did you forget to run the device compilation first?"
82+
"the given path/file to `device.bin` does not exist. Did you forget to run the device compilation first?"
8183
)]
8284
pub(crate) struct OffloadNonexistingPath;
8385

8486
#[derive(Diagnostic)]
85-
#[diag("call to BundleImages failed, `host.out` was not created")]
87+
#[diag("call to BundleImages failed, `device.bin` was not created")]
8688
pub(crate) struct OffloadBundleImagesFailed;
8789

8890
#[derive(Diagnostic)]

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,15 +1693,15 @@ pub(crate) use self::Offload::*;
16931693
mod Offload {
16941694
use super::*;
16951695
unsafe extern "C" {
1696-
/// Processes the module and writes it in an offload compatible way into a "host.out" file.
1696+
/// Processes the module and writes it in an offload compatible way into a "device.bin" file.
16971697
pub(crate) fn LLVMRustBundleImages<'a>(
16981698
M: &'a Module,
16991699
TM: &'a TargetMachine,
1700-
host_out: *const c_char,
1700+
device_bin: *const c_char,
17011701
) -> bool;
17021702
pub(crate) unsafe fn LLVMRustOffloadEmbedBufferInModule<'a>(
17031703
_M: &'a Module,
1704-
_host_out: *const c_char,
1704+
_device_bin: *const c_char,
17051705
) -> bool;
17061706
pub(crate) fn LLVMRustOffloadMapper<'a>(
17071707
OldFn: &'a Value,
@@ -1717,19 +1717,19 @@ pub(crate) use self::Offload_fallback::*;
17171717
#[cfg(not(feature = "llvm_offload"))]
17181718
mod Offload_fallback {
17191719
use super::*;
1720-
/// Processes the module and writes it in an offload compatible way into a "host.out" file.
1720+
/// Processes the module and writes it in an offload compatible way into a "device.bin" file.
17211721
/// Marked as unsafe to match the real offload wrapper which is unsafe due to FFI.
17221722
#[allow(unused_unsafe)]
17231723
pub(crate) unsafe fn LLVMRustBundleImages<'a>(
17241724
_M: &'a Module,
17251725
_TM: &'a TargetMachine,
1726-
_host_out: *const c_char,
1726+
_device_bin: *const c_char,
17271727
) -> bool {
17281728
unimplemented!("This rustc version was not built with LLVM Offload support!");
17291729
}
17301730
pub(crate) unsafe fn LLVMRustOffloadEmbedBufferInModule<'a>(
17311731
_M: &'a Module,
1732-
_host_out: *const c_char,
1732+
_device_bin: *const c_char,
17331733
) -> bool {
17341734
unimplemented!("This rustc version was not built with LLVM Offload support!");
17351735
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static Error writeFile(StringRef Filename, StringRef Data) {
178178

179179
// This is the first of many steps in creating a binary using llvm offload,
180180
// to run code on the gpu. Concrete, it replaces the following binary use:
181-
// clang-offload-packager -o host.out
181+
// clang-offload-packager -o device.bin
182182
// --image=file=device.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp
183183
// The input module is the rust code compiled for a gpu target like amdgpu.
184184
// Based on clang/tools/clang-offload-packager/ClangOffloadPackager.cpp

0 commit comments

Comments
 (0)