Data Races & Flawed Synchronization due to Invalid Atomic Memory Scope in `SystemAtomicF32` and `SystemAtomicF64
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- rust
- Domain
- distributed-systems
Research direction
Start in crates/cuda_std/src/atomic.rs and inspect the macro instantiations for SystemAtomicF32 and SystemAtomicF64. Change their scope argument from device to system, then verify that their atomic operations emit the expected system-scoped PTX operations instead of device-scoped operations.
Written by the indexing model from the issue text.
Description
SystemAtomicF32 and SystemAtomicF64 types are mistakenly configured with device scope instead of system scope in their macro instantiations.
This presents the following issues:
- Flawed Synchronization: Code that uses
SystemAtomicF32orSystemAtomicF64intends to synchronize memory accesses across the entire system (between the GPU and host CPU or across multiple GPUs over PCIe/NVLink). - Data Races: Because the emitted PTX operations use the
.gpuscope (atomic.global.gpu...) rather than the proper.sysscope (atomic.global.sys...), CPU host accesses and multi-GPU accesses to system memory will not observe proper cache coherency. This leads to data races and corrupted shared memory states without emitting any compilation errors.
Reproduction Case
Using SystemAtomicF32 or SystemAtomicF64 and calling atomic operations (like fetch_add, load, or store) will incorrectly generate device-scoped PTX:
use cuda_std::atomic::SystemAtomicF32;
use core::sync::atomic::Ordering;
#[cuda_std::kernel]
pub unsafe fn system_atomic_kernel(val: &SystemAtomicF32) {
// PTX generates: atomic.global.gpu.add.f32 ...
// Expected: atomic.global.sys.add.f32 ...
val.fetch_add(1.0, Ordering::Relaxed);
}
Issue Details
In crates/cuda_std/src/atomic.rs, the type instantiations for system-level float atomics incorrectly pass the $scope argument as device instead of system to the macro:
// Current instantiations in atomic.rs
atomic_float!(f32, AtomicF32, 4, device, 32);
atomic_float!(f64, AtomicF64, 8, device, 64);
atomic_float!(f32, BlockAtomicF32, 4, block, 32, unsafe);
atomic_float!(f64, BlockAtomicF64, 8, block, 64, unsafe);
atomic_float!(f32, SystemAtomicF32, 4, device, 32); // <--- BUG: device instead of system
atomic_float!(f64, SystemAtomicF64, 8, device, 64); // <--- BUG: device instead of system
- Dominant language
- Rust
- Stars
- 5.4k
- Forks
- 249
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 2
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rust-GPU/rust-cuda
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Default NvvmArch::Compute75 silently produces InvalidPtx on pre-Turing GPUs (Pascal/Maxwell/Volta)Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
All issues in Rust-GPU/rust-cuda
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
trailofbits/dylint#2107 ·
Maintainers usually reply within 1 day
-
area:cli bug good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
arrays_zip with two same-named inputs fails with "ArrowArray struct has 2 children (expected 1)"Openbug requires-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/datafusion-comet#6251 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug false-positive harper-core linting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Automattic/harper#4471 ·
Maintainers usually reply within 1 day