Repository navigation
feat(shader): implement ds_wrxchg2_rtn_b32 and ds_wrxchg2st64_rtn_b32 - #385
Conversation
|
@boykopovar this one needs your call: is it OK to implement My read: acceptable, as long as the gap goes into TechnicalDebt (CONTRIBUTING asks for known gaps there, and right now it's only in the PR body). |
|
@oneandonlydean measured on RDNA2 hardware (gfx1035), for the open question here:
|
Both swap data0 with the dword at addr + offset0 and data1 with the dword at addr + offset1, and return the two previous values in vdst and vdst + 1. The offsets are scaled by 4 bytes, or by 256 bytes for the st64 form. Each location goes through the existing SharedAtomicSwap32. An encoding whose two offsets are equal is rejected at decode time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The masked case loaded EXEC from a scalar literal. A scalar mask is read by subgroup lane, so on a host whose subgroups are narrower than the wave (llvmpipe: 8 lanes) lane 16 took bit 0 and stayed active. v_cmpx_gt_u32 on the thread id gives the same low 16 lanes on any subgroup size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f97ea10 to
12008dc
Compare
|
Rebased on main and added the TechnicalDebt line @oneandonlydean asked for (12008dc), with what we measured on gfx1035: hardware does every lane's first exchange before any lane's second one, so two atomics per invocation can differ when lanes overlap addresses. Build and full ctest green on RADV; |
What
ds_wrxchg2_rtn_b32(DS 0x2e) andds_wrxchg2st64_rtn_b32(DS 0x2f) threwDS opcode is not supported.Both swap
data0with the dword ataddr + offset0 * Sanddata1with the dword ataddr + offset1 * S, and return the two previous values invdstandvdst + 1.Sis 4 bytes, or 256 bytes for the st64 form, as fords_read2_b32/ds_read2st64_b32.Sources: AMD's machine-readable RDNA2 ISA specification (description, operand shape: 64-bit
VDST,ADDR,DATA0,DATA1) and LLVM'sDSInstructions.td(encodings,v[n:n+1], addr, data0, data1 offset0 offset1).Implementation: no new IR. The translation emits one
SharedAtomicSwap32per location, the opds_wrxchg_rtn_b32already uses, so EXEC masking, bounds and the LDS barrier are the existing ones. All three sources are read before the destination is written.Rejected at decode time instead of guessed:
offset0 == offset1: the specification does not say what the two results and the final memory value are when both offsets name the same location.vdst == 255: the second result has no register.The 64-bit forms (
ds_wrxchg_rtn_b64,ds_wrxchg2_rtn_b64,ds_wrxchg2st64_rtn_b64) are not in this PR: LDS is an array of dwords here, and two 32-bit swaps are not a 64-bit atomic exchange.Not measured on hardware. The swaps of the two locations are two separate atomics, not one atomic pair.
Test
agc_driver_ds_wrxchg2: one wave32 compute shader, every lane on its own LDS dwords. It checks both returned values and both memory locations for:ds_wrxchg2_rtn_b32withoffset0 < offset1ds_wrxchg2st64_rtn_b32withoffset0 > offset1v_cmpx_gt_u32on the thread id so that it does not depend on the host subgroup size: inactive lanes keep their registers and their memoryIt also checks the two rejections by their message.
Tested
Windows 11, MinGW-w64 GCC 15.2.0, full
ctest: 109/109 pass.agc_driver_ds_wrxchg2fails withDS opcode is not supported.data0anddata1swapped in the translation it fails withlane 0 ds_wrxchg2_rtn_b32 offset0 memory is 0x40000003, expected 0x30000002.No title was run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code