about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-02-16 00:51:24 -0500
committerGitHub <noreply@github.com>2025-02-16 00:51:24 -0500
commit20004d4bdd787b3e3b664827acafdd6c2ebfbce3 (patch)
tree7a6ad25a790a57d08fa35f28c28d042267cc4d86 /tests
parentaa37d799fc5e01b4cd5e700d67c10d184ae7d321 (diff)
parent99ec64c34c65630d9a66befa2cbf2faa9478baa0 (diff)
downloadrust-20004d4bdd787b3e3b664827acafdd6c2ebfbce3.tar.gz
rust-20004d4bdd787b3e3b664827acafdd6c2ebfbce3.zip
Rollup merge of #135909 - Flakebi:amdgpu-kd, r=jieyouxu,workingjubilee
Export kernel descriptor for amdgpu kernels

The host runtime (HIP or HSA) expects a kernel descriptor object for each kernel in the ELF file. The amdgpu LLVM backend generates the object. It is created as a symbol with the name of the kernel plus a `.kd` suffix.

Add it to the exported symbols in the linker script, so that it can be found.

For reference, the symbol is created here in LLVM: https://github.com/llvm/llvm-project/blob/d5457e4c1619e5dbeefd49841e284cbc24d35cb4/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp#L966
I wrote [a test](https://github.com/Flakebi/rust/commit/6a9115b121b48a8cd4aaf100551569dc70c6c704) for this as well, I’ll add that once the target is merged and working.
With this, all PRs to get working code for amdgpu are open (this + the target + the two patches adding addrspacecasts for alloca and global variables).

Tracking issue: #135024

r? `@workingjubilee`
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/amdgpu-kd/foo.rs11
-rw-r--r--tests/run-make/amdgpu-kd/rmake.rs20
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/run-make/amdgpu-kd/foo.rs b/tests/run-make/amdgpu-kd/foo.rs
new file mode 100644
index 00000000000..a0d803ab813
--- /dev/null
+++ b/tests/run-make/amdgpu-kd/foo.rs
@@ -0,0 +1,11 @@
+#![allow(internal_features)]
+#![feature(no_core, lang_items, abi_gpu_kernel)]
+#![no_core]
+#![no_std]
+
+// This is needed because of #![no_core]:
+#[lang = "sized"]
+trait Sized {}
+
+#[no_mangle]
+extern "gpu-kernel" fn kernel() {}
diff --git a/tests/run-make/amdgpu-kd/rmake.rs b/tests/run-make/amdgpu-kd/rmake.rs
new file mode 100644
index 00000000000..a787fa1da93
--- /dev/null
+++ b/tests/run-make/amdgpu-kd/rmake.rs
@@ -0,0 +1,20 @@
+// On the amdhsa OS, the host runtime (HIP or HSA) expects a kernel descriptor object for each
+// kernel in the ELF file. The amdgpu LLVM backend generates the object. It is created as a symbol
+// with the name of the kernel plus a .kd suffix.
+// Check that the produced object has the .kd symbol exported.
+
+//@ needs-llvm-components: amdgpu
+//@ needs-rust-lld
+
+use run_make_support::{llvm_readobj, rustc};
+
+fn main() {
+    rustc()
+        .crate_name("foo")
+        .target("amdgcn-amd-amdhsa")
+        .arg("-Ctarget-cpu=gfx900")
+        .crate_type("cdylib")
+        .input("foo.rs")
+        .run();
+    llvm_readobj().input("foo.elf").symbols().run().assert_stdout_contains("kernel.kd");
+}