Repository navigation
docs(cuda-oxide): state what sync_threads orders at compile time - #1493
Open
alejandro-soto-franco wants to merge 2 commits into
Open
alejandro-soto-franco wants to merge 2 commits into
alejandro-soto-franco wants to merge 2 commits into
Conversation
The shared-memory chapter explains the hardware rule for sync_threads
and says nothing about what the compiler may move across it. Users
could not tell whether raw-pointer or ptx_asm! shared accesses are
safe to leave visible to the optimiser, and wrapped every access in a
side-effecting ptx_asm!.
Add a table of access forms to the synchronisation section. It covers
SharedArray indexing, raw pointers, DynamicSharedArray, ptx_asm! with
no options, with clobber("memory") and with register_only, cp.async,
and references held across the barrier. Add the cp.async
commit and wait requirement before the barrier. Link the table from
the ptx_asm! row of the feature list.
Closes NVIDIA#1463
Signed-off-by: Alejandro Soto Franco <sotofranco.eng@gmail.com>
Collaborator
|
The table is right. The paragraph about references is not, and I have a kernel that shows it:
#[device]
fn read_twice(r: &u32, p: *mut u32, tid: usize) -> (u32, u32) {
let a = *r;
thread::sync_threads();
unsafe { p.add(tid).write(a + 1) }
thread::sync_threads();
(a, *r) // same value as a
}
To land this: rewrite the "Keep references out of the barrier" paragraph with the rule above and drop the lowering sentence; add the |
nihalpasham
requested changes
Oct 15, 2026
nihalpasham
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed d5bdd5dd: changes requested. The landing list is in #1493 (comment).
rustc merges two reads through a plain &T before either backend runs. The paragraph claiming the compiler reloads was wrong. A test kernel read the stale value in all 128 threads on both routes. &UnsafeCell and BlockAtomicU32 reloaded. Adds the as_raw_mut_ptr example from NVIDIA#1463: write your own slot, call sync_threads(), read a neighbour's. It passes on both backends. Lists as_raw_mut_ptr in the API block. register_only may move across memory operations. The default ptx_asm! row names the PTX as what keeps the snippet. The verification paragraph names the rows it covers.
Contributor
Author
|
Addressed in ea51cc6:
Your |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The shared-memory chapter states the hardware rule for
sync_threads()and says nothing about what the compiler may move across it. Users cannot tell whether raw-pointer orptx_asm!shared accesses stay on their side of the barrier, so speakrs wraps every shared access in a side-effectingptx_asm!.SharedArrayindexing,as_raw_mut_ptr,DynamicSharedArray,ptx_asm!with no options, withclobber("memory")and withoptions(register_only),cp_async_*, and a reference that outlives the barrier.llvm.nvvm.barrier.cta.sync.aligned.allon the LLVM NVPTX route, andasm sideeffect "bar.sync 0;"with~{memory}on the libNVVM route.cp_async_commit_groupandcp_async_wait_grouprequirement before the barrier.ptx_asm!row of the feature list.Closes #1463
Test: a throwaway probe example (not in this diff) with 25 kernels ran 21 of them on an RTX 5060 Laptop (sm_120) through both backends, and 20 passed on each route. The failure is the
cp.asynckernel with nocp_async_wait_group(0), which read the stale value in 128 of 128 threads. The same kernel with the wait read 0 stale values. PTX from llc and from libNVVM showsst.shared, bar.sync, ld.shared, bar.sync, st.shared, bar.sync, ld.sharedfor every access form, in straight-line code and in loops with a runtime trip count. The four compile-only kernels show that an unusedregister_onlyld.sharedleaves no PTX instruction and that a default one stays.sphinx-build -Won the book,check-book-api-names.sh,check-book-import-order.shandcheck-source-references.shpass.