Repository navigation
Conversation
The atomics example passed shared counters as raw device pointers and rebuilt atomic views inside every kernel with unsafe DeviceAtomic*::from_ptr. The sound form takes the counter as &[DeviceAtomic*] and retypes the host buffer with cast_elem, so the shared updates go through interior mutability and the kernels need no unsafe. This is the pattern legacy_atomic_rmw_cas already uses and the form recommended in Discord #help when this example was flagged as stale. Tests 1-20 convert; the AtomicPtr tests and the compile-only intrinsic probe keep raw pointers because pointer-based core atomics are what they exercise. The atomic_storage helper had no remaining callers. Signed-off-by: Navneet Kumar <4686373+navneet83@users.noreply.github.com>
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.
Summary
This cleans up the atomics example so kernels no longer have to accept counters as raw
*mut Tpointers and immediately rebuildDeviceAtomicU32values withunsafe { DeviceAtomicU32::from_ptr(...) }.Instead, the host retypes the buffers once with
cast_elem::<DeviceAtomicU32>(), and the kernels take&[DeviceAtomicU32]. Shared updates now go through interior mutability, which removes the unsafe blocks from the kernel bodies. The launch-siteunsaferemains, since launching still depends on the usual shape and resource guarantees.Readback casts the buffers back to the plain element type. The old
atomic_storagehelper is gone, since it only existed to turn a buffer into a raw pointer.Behavior
No behavior change intended. The examples still use the same operations, orderings, launch configs, and expected values across all 20 tests.
The scope coverage is unchanged too: the block-scope tests still use
BlockAtomicU32, and test 20 still usescore::sync::atomic::AtomicU32as the slice element for core-intercept coverage.Verification
Ran:
scripts/smoketest.sh --compile-only atomicson current
main.Result: compiled successfully, including
ptxasforsm_80.