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 crates/cuda_std/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn dynamic_shared_mem<T>() -> *mut T {
#[allow(improper_ctypes)]
// mangle it a bit to make sure nobody makes the same thing
#[link_name = "_Zcuda_std_dyn_shared"]
static DYN_SHARED: ::core::cell::UnsafeCell<u128>;
static DYN_SHARED: ::core::cell::UnsafeCell<[u128; 0]>;
}

// SAFETY: extern statics is how dynamic shared mem is done in CUDA. This will turn into
Expand Down
16 changes: 16 additions & 0 deletions tests/compiletests/ui/dis/dynamic_shared_mem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// build-pass
// compile-flags: -Cllvm-args=--disassemble-globals --error-format=human -Cdebuginfo=0
// normalize-stderr-test "sm_\d+" -> "sm_XX"

// Regression test: the extern behind `dynamic_shared_mem` must be unsized (`[]`) in the PTX,
// like nvcc's `extern __shared__` arrays. A sized one is laid out among the kernel's static
// shared variables, so the dynamic region overlaps them.

use cuda_std::{kernel, shared};

#[kernel]
pub unsafe fn dynamic_shared(out: *mut u32) {
unsafe {
*out = *shared::dynamic_shared_mem::<u32>();
}
}
7 changes: 7 additions & 0 deletions tests/compiletests/ui/dis/dynamic_shared_mem.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.version 8.7
.target sm_XX
.address_size 64
.extern .shared .align 16 .b8 _Zcuda_std_dyn_shared[];
.visible .entry dynamic_shared( { ... }