compute: lower the SMEM atomic families #3622
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3622
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3620"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@lambirou on GitHub · 2026-11-30 15:44 UTC · original
lambirou:compute/smem-atomics→main· +661 −0 · 6 files · 7 commits · merged 2026-12-02 18:07 UTCPart of the SMEM slice (P2). Addresses the blocking review on
381b6a59.This adds the 52 SMEM atomic forms: the
s_atomic_*ands_buffer_atomic_*families for add, and, or, xor, sub, inc, dec, signed/unsigned min and max, swap and cmpswap, each in the 32-bit and_x2forms. They target the bound raw output UAVu0:s_atomic_*uses the 64-bit base pair,s_buffer_atomic_*the full V#. SData carries the data and, withglc, also returns the old value;cmpswaptakes{data, compare}; inc/dec wrap on the limit; smin/smax and umin/umax select the signed or unsigned rule.Refusals: incomplete or misaligned SGPR pairs/quads, unloaded or non-u0 descriptors, non-consecutive result/data SGPRs or registers above s105, negative/misaligned/out-of-field offsets, overlapping atomics and stores, lane guards,
soffset/offset:/dlc/slcspellings, and any thread group other than(1, 1, 1). A scalar SMEM atomic is one wave-uniform guest operation, while the emittedoutputData.Interlocked*call runs per desktop thread.lower()therefore refuses everys_atomic_*ands_buffer_atomic_*spelling outside a one-thread group withSMEM atomics require a group of one thread, before any HLSL is built. The gate covers both families, both widths and unsupported family spellings;s_scratch_atomic_*keeps its separate refusal.Tests
Head
6434b0a6, merged with currentorigin/main(no conflicts).python -B tests/compute_store_check.py smem-atomicspasses at group 1 and with a group-of-2 control in both families and widths, including an unsupporteds_atomic_spelling. The control asserts the exact message, thatsmem_atomic_statementsis not called, and that the refused case writes no coverage record.ctest --test-dir out/build/dev --no-tests=error -j1 -R '^(compute_store_aot_(smem_atomics|smem_stores|smem_wide_loads|gfx1013_buffer_atomics))'passes 9/9 in 72.55 s, no skips. WARP (Microsoft Basic Render Driver, 1414:008c, driver 10.0.26100.10068) and the AMD Radeon RX 9060 XT (1002:7590, driver 32.0.32029.2010) compare 320 words with 0 mismatch; the debug layer is unavailable. Six 32-bit and four_x2mutants mismatch on both adapters.python -B tests/form_coverage_check.pypasses; the control, WARP and hardware records each hold exactly the 52 forms.python -B tests/docs_links_check.pypasses (192 Markdown files, 745 links).tests/checks/python-linux/smem-atomics.txtadds the group-2 control to the platform-independent Linux checks, so it runs in CI instead of only in the author's runs.smem-atomicsfail withAssertionError: Expected rejection: SMEM atomics require a group of one thread.Limits
The one-thread group is measured; larger groups are refused, not modelled. A root UAV carries no length, so the caller must bind a u0 buffer covering every accessed offset. The D3D12 debug layer is unavailable on this host and the internal LLVM 15 round-trip is skipped (no LLVM 15 installed). The scratch atomics, the cache/memtime forms and the MUBUF/DS atomics stay out of scope. No title dispatch was measured.
AI-assisted.
@lukaslw-lab on GitHub · 2026-11-30 18:29 UTC · original · requested changes
Reviewed
381b6a59by reading the diff; not built or run.Verdict: changes requested. The atomics are lowered per thread, but the one-thread-group limit is only documented, not enforced. A larger group gets wrong results with no refusal.
lower()accepts the SMEM atomic branch for anychecked_groupsize (tools/compute_store_aot.py:1219, branch at:1882-1932). On the guest, a scalar atomic runs once per wave. The emittedoutputData.Interlocked*(smem_atomic_statements,:482) runs once per thread. Sos_atomic_add s4, s[0:1], 0 glcwith data 1 in a 64-thread group adds 64 instead of 1 per wave. Each lane also gets a different old value in what the rest of the lowering treats as a uniform SGPR, and theinc/decCAS loop becomes contended. The body anddocs/experiments.mdcall this "unmodelled", but the code still emits HLSL. Refuse whendims != (1, 1, 1), as the LDS path does withShared LDS requires a group of one guest wave(:1408), and add a control with a group of 2.inc/decwrap rules, thecmpswapoperand order (data first, compare second, mapped to HLSL compare-first), the signed and unsigned overloads, and the low-word return withglc. The other paths are refused correctly: no-glcleaves SData unchanged, spans past s105 and misaligned base or data are refused,soffset/offset:fall through toUnsupported SMEM atomic spelling, and both guard orders (atomic inside a guard, and a guard after an atomic,:1542) are refused.Tests:
compute_store_aot_smem_atomicsproves acceptance of the 52 forms, the refusals and the no-glcpath, at group 1 only. The_warp/_hardwaredraws prove the readback and kill the ten mutants, also at group 1. CI ran onlyform_coverage_check.py(the Linux job). Thesmem-atomicscontrol and both draws match neither the Linux check list nor theprpreset filter. The author's runs listed in the body are the only ones so far.@lambirou on GitHub · 2026-11-30 20:26 UTC · original
@lukaslw-lab thanks — fixed in
e6b992b2(after merging currentorigin/main).lower()now rejects any program containings_atomic_*ors_buffer_atomic_*whendims != (1, 1, 1), before HLSL emission, withSMEM atomics require a group of one thread. The pre-scan covers every family spelling, including unsupported ones;s_scratch_atomic_*keeps its own refusal.smem_atomic_controls()now checks a group of 2 for both prefixes and widths, asserts the exact message, assertssmem_atomic_statementsis not reached, and asserts the refused case writes no coverage record. Removing the guard makes the control fail withExpected rejection: SMEM atomics require a group of one thread.docs/experiments.mdand the PR body now state that the limit is enforced. The coverage delta is stated as +52 gfx1013 / +0 gfx1030 for the pinned rows; the stale SMEM group total and open-PR projection were removed.Re-run on Windows 11 build 26300.10075:
compute_store_check.py smem-atomicspassed; the 9-test SMEM/buffer-atomic ctest filter passed 9/9 in 72.55 s with no skips (WARP and AMD Radeon RX 9060 XT, 320 words, 0 mismatch);form_coverage_check.pyanddocs_links_check.pypassed.@lambirou on GitHub · 2026-11-30 20:33 UTC · original
Head is now
6434b0a6:tests/checks/python-linux/smem-atomics.txtadds the group-of-2 control to the Linux job, so it runs in CI. All PR checks pass (Windows, fixture assembly, Linux); the/O2and coverage-chart jobs are skipped by the PR configuration.@lukaslw-lab on GitHub · 2026-12-01 01:32 UTC · original · approved these changes
Reviewed
fcb096b7by reading the diff; not built or run. The delta since our review at381b6a59ise6b992b2and6434b0a6, plus two merges of main.Verdict: approve. The MUST is fixed: a group other than one thread is now refused before any HLSL is built, and the control for it runs on CI. No MUST, no SHOULD.
tools/compute_store_aot.py, start oflower()):dims != (1, 1, 1)together with any line starting withs_atomic_ors_buffer_atomic_raises. The atomic branch matches withre.fullmatchon the same raw line, so every line it lowers starts with one of those prefixes, and the gate cannot miss an accepted form. Unsupported spellings (s_atomic_csub) are refused too.s_scratch_atomic_*keeps its own refusal.smem_atomic_statementsis patched to prove it is never reached, and a refused run writes noFORM_COVERAGE_RECORD. The scratch control at group 2 shows the gate does not swallow that family.tests/checks/python-linux/smem-atomics.txtputs thesmem-atomicscontrol (with the group-2 case) into the Linux job, which passed at this head. The_warp/_hardwaredraws are still outside the Windowsprfilter, so they rest on your WARP + RX 9060 XT runs.@R0Y00 on GitHub · 2026-12-02 12:43 UTC · original · reviewed
I merged current main into the PR branch and kept both the existing SMEM cache coverage and the new atomic coverage.
python -B tests/form_coverage_check.pyandpython -B tests/compute_store_check.py smem-atomicspassed on the integrated source.The required Windows job failed in two existing tests.
native_direct_meshhits the known+0x34: unmapped graphics exportfixture fault covered by #3853. Instartup_indirect_mesh_cache_heap_wide_warp, the probe reachedgraphics/mesh_profile_missing, then the fixture found noreq_*.m86marker to unpack. The latter needs a baseline comparison before we attribute it. The integrated head is awaiting re-review and green Windows CI.@R0Y00 on GitHub · 2026-12-02 13:02 UTC · original
Follow-up on the wide Mesh86 WARP failure. On
main5770f14e,ctest --preset dev --no-tests=error -j 1 -V --repeat until-fail:4 -R '^startup_indirect_mesh_cache_heap_wide_warp$'passed all four runs (Windows 11 26300.9974, Microsoft Basic Render Driver 10.0.26100.9818, D3D12 debug layer enabled). The same test passed in the #3829 and #3831 Windows jobs. The integrated #3622 head and current main have identical stand-in source, indirect-mesh harness and cache check. The missingreq_*.m86remains a single hosted failure so far. The next Windows run after #3853 lands can check whether it recurs.@lambirou on GitHub · 2026-12-02 14:44 UTC · original · reviewed
Re-reviewed the integrated head
fa82cc4fafter R0Y00'smainmerge; read the delta, not built here.Verdict: approve. The earlier MUST remains fixed: every
s_atomic_*/s_buffer_atomic_*program is refused before HLSL unless the group is exactly(1,1,1), and the group-of-two control is in the Linux check list. The merge kept the SMEM cache coverage and the new atomic coverage rather than replacing one with the other.CMakeLists.txt,CMakePresets.json, the existingdocs/experiments.mdcache paragraph and thetests/checks/python-linux/smem-atomics.txtregistration; the lowering and its group gate are unchanged fromfcb096b7.native_direct_meshis the known+0x34: unmapped graphics exportfault tracked by #3853, andstartup_indirect_mesh_cache_heap_wide_warpneeds a baseline comparison before it is attributed to this PR. Neither failure is in the atomic lowering.The PR is
MERGEABLEbut currentlyBLOCKED; it needs the inherited Windows failures resolved on main or a baseline showing they are unrelated.@R0Y00 on GitHub · 2026-12-02 18:04 UTC · original · approved these changes
Re-reviewed
0f0b8d8c. Comparing each of the six files against its own main parent, the edited lines match the revision independently approved atfcb096b7. Independent Windows 11 build 26300/MSVC Debugctest --preset dev --no-tests=error -j 1 -R '^compute_store_aot_smem_atomics'passed 3/3. RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818) both matched the positive readbacks with the debug layer on, and the intended negative controls produced mismatches. The local LLVM 15 round-trip check reported a skip.