Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub(crate) fn expand_kernel(
span,
ecx.path_global(
span,
[sym::std, sym::unimplemented].map(|s| Ident::new(s, span)).to_vec(),
[sym::core, sym::unimplemented].map(|s| Ident::new(s, span)).to_vec(),

@Sa4dUs Sa4dUs Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not necessary if we compile the host with std, but ig it's still better to use core

View changes since the review

),
Delimiter::Parenthesis,
TokenStream::default(),
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ impl Linker {
// any more, we can finalize it (which involves renaming it)
rustc_incremental::finalize_session_directory(sess, incr_comp_session, self.crate_hash);

// The `HostMetadata` offload pass only writes the kernel manifest.
// Codegen was already skipped so there are no files to link.
if sess
.opts
.unstable_opts
.offload
.iter()
.any(|o| matches!(o, config::Offload::HostMetadata(_)))
{
return;
}

if !sess
.opts
.output_types
Expand Down
22 changes: 22 additions & 0 deletions tests/run-make/offload-host-std-device-nostd/example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(gpu_offload, rustc_attrs)]
#![allow(internal_features)]
#![cfg_attr(device, no_std)]
#![cfg_attr(device, no_main)]

#[cfg(device)]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}

#[rustc_offload_kernel]
fn kernel() {}

#[cfg(not(device))]
fn main() {
core::offload::offload! {
kernel = kernel,
args = (),
}
println!("Hello from Host with std");
}
40 changes: 40 additions & 0 deletions tests/run-make/offload-host-std-device-nostd/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//@ needs-offload

// Tests offload with no-std in device and std in host

use run_make_support::{cwd, rfs, rustc};

fn main() {
rustc()
.input("example.rs")
.arg("-Zunstable-options")
.arg("-Zoffload=HostMetadata=example.manifest")
.arg("-Csymbol-mangling-version=v0")
.arg("-Clto=fat")
.emit("metadata")
.run();

rustc()
.input("example.rs")
.cfg("device")
.arg("-Zunstable-options")
.arg("-Zoffload=Device=example.manifest")
.arg("-Csymbol-mangling-version=v0")
.arg("-Clto=fat")
.arg("-Cpanic=abort")
.emit("obj")
.run();

rfs::write(cwd().join("device.bin"), [0u8; 8]);

rustc()
.input("example.rs")
.arg("-Zunstable-options")
.arg(format!("-Zoffload=Host={}", cwd().join("device.bin").display()))
.arg("-Csymbol-mangling-version=v0")
.arg("-Clto=fat")
.emit("obj")
.run();

assert!(cwd().join("host.o").exists());
}
4 changes: 2 additions & 2 deletions tests/ui/offload/duplicate_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// An offload kernel whose mangled symbol collides with another item in the
// same crate must be rejected, just like any other symbol collision.

#![feature(core_intrinsics, rustc_attrs)]
#![feature(rustc_attrs, gpu_offload)]
#![allow(internal_features)]

#[allow(non_snake_case)]
Expand All @@ -18,5 +18,5 @@ fn kernel(_x: f32) {}

fn main() {
_RNvC19collision_kernels_a6kernel(0.0);
core::intrinsics::offload::<_, _, ()>(kernel, [1, 1, 1], [1, 1, 1], 0, -1, (0.0f32,));
core::offload::offload! { kernel = kernel, args = (0.0f32,) }
}
4 changes: 2 additions & 2 deletions tests/ui/offload/non_tuple_args.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//@ compile-flags: -Zunstable-options -Zoffload=Device -Clto=fat

#![feature(core_intrinsics)]
#![feature(gpu_offload)]

fn main() {
// args_ty is not a tuple
core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, -1, 42);
core::offload::offload! { kernel = kernel_0, args = 42 }
//~^ ERROR `{integer}` is not a tuple
}

Expand Down
7 changes: 4 additions & 3 deletions tests/ui/offload/non_tuple_args.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
error[E0277]: `{integer}` is not a tuple
--> $DIR/non_tuple_args.rs:7:36
--> $DIR/non_tuple_args.rs:7:5
|
LL | core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, -1, 42);
| ^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}`
LL | core::offload::offload! { kernel = kernel_0, args = 42 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}`
|
note: required by a bound in `offload`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
= note: this error originates in the macro `$crate::offload` which comes from the expansion of the macro `core::offload::offload` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

Expand Down
Loading