fix(rccl): replace atomicAdd(ptr, 0) reads with scoped atomic loads #13864
<!-- therock-pr-bot-policy-check -->
✅ All Policy Checks Passed
| Check | Status | Details |
|---|:---:|---|
| 📝 PR Description | ✅ Pass | — |
| ⛔ Forbidden Files | ✅ Pass | — |
| 🧪 Unit Test | ⚠️ Warning | Error: Source/code files changed without an accompanying unit test.<br>Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).<br>Current: code file(s) changed: projects/rccl/src/device/prims_ll.h, projects/rccl/src/device/prims_simple.h; no test file found |
| 🚫 Draft PR | 🔜 To Be Enabled | — |
| 🚩 Feature Flag | 🔜 To Be Enabled | — |
| 📊 Code Coverage | 🔜 To Be Enabled | — |
🎉 All policy checks passed!
📖 Need help? See the Policy FAQ for details on every check and how to fix failures.
<!-- therock-pr-bot-fix-policies -->
🚫 Please fix the failed policies before requesting reviews.
The following policy checks failed:
The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.
<!-- ccr-overview-v2 -->
🔵 Needs a closer look
Cross-GPU and host-memory polling changes warrant runtime validation beyond the reported compilation and ISA check.
No open issues 🎉
<details>
<summary><strong>What changed in this PR</strong></summary>
Replaces five RCCL polling reads with system-scoped atomic loads to avoid unnecessary read-modify-write operations.
Changes:
| File | Description |
| ---- | ----------- |
| projects/rccl/src/device/prims_simple.h | Uses scoped loads for four pointer-exchange polls. |
| projects/rccl/src/device/prims_ll.h | Uses a scoped load for the send-head cache reload. |
</details>
<sub>Review effort: Balanced</sub>
Approved these changes.
Approved these changes.
<!-- argus:v1 pr=13864 sha=821e24e243b7 mode=review -->
ARGUS
Findings
<details>
<summary>1 more finding(s), not posted inline</summary>
projects/rccl/src/device/prims_simple.h:936 (Low) Five new inline __scoped_atomic_load_n casts duplicate the existing ld_relaxed_sys_global() helper (op128.h:438)</details>
Bottom line: Looks approval ready.
<sub>Comment <code>@argus review</code> to re-run, or <code>@argus re-review</code> after pushing.</sub>
atomicAdd seems to be device-scope. Why does the load need to be system scope?
Yeah, it should be device scope generally. I had a similar thought given the memory is local to the device. It turns out it doesn't make much of performance difference, so I left it as system scope. It's more idiot-proof if we start polling on CPU memory or remote GPU memory.
Why is there an address space 1 here?
So that the compiler emits a global_load instruction instead of a flat_load instruction. This can have a perf impact. Otherwise, the compiler can lose track of whether this access is to LDS or global memory and have to emit a conservative flat VMEM instruction.
nileshnegi
alex-breslow-amd
Motivation
Several RCCL device primitives read shared values with
atomicAdd(ptr, 0). That makes every poll an atomic read-modify-write, which is more expensive than needed, especially in spin loops polling memory another GPU or the host may be writing.Alex: Previously the compiler optimized this into a relaxed system scope atomic load. However, no longer. Let's just ask for what we want. :-) Credit goes to Larry Meadows for root causing this and Marc Charest for opening the ticket and doing the initial work to determine it was a compiler bump.
Technical Details
Replaces each of these reads with
__scoped_atomic_load_n(..., __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM)on a global (address_space(1)) pointer, following the existing pattern inop128.handprims_ll.h:prims_ll.h: thesendConnHeadCachereload inwaitSend.prims_simple.h: the fourptrExchangeslot reads insetDataPtrs(the recvProvider and sendProvider waits, and the sendAcceptor and recvAcceptor polls).Ordering stays relaxed, as with
atomicAdd. System scope makes sure writes from peer GPUs and the host are observed.Issue Tracking
JIRA ID: ROCM-32706
Test Plan
hipcc --offload-arch=gfx942and checked the generated ISA.Test Result
global_load_dwordx2 ... sc0 sc1(system-scope load) instead of an atomic RMW.Submission Checklist