'Fix DPP row shift direction logic' #3154
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!3154
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3152"
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?
@KelboLive on GitHub · 2026-11-27 18:37 UTC · original
KelboLive:dpp-row→main· +7 −3 · 1 files · 1 commits · closed without merging'Correct peer calculation for row_shl and row_shr.'
@thepatrickworld on GitHub · 2026-11-27 19:28 UTC · original
Measured regression at
b68cb540:native_dpp_row_hardwarepasses on the merge base and fails on this headNot a code change; measurements only.
Environment
devnative_store_replaycreates its device from the default adapter (tests/native_store_replay.cpp:45). The machine's video controllers areAMD Radeon RX 9070 XTandMeta Virtual Monitorb68cb5406f19747abb3c9def350ff5367772c790, then the same tree with only this PR's file taken from429f11d5(its merge base).src/gfx1013_direct_compute.inlsha256 on the Windows checkout:51656573d637…at the head,1b731ee1fe67…at the base (LF blobs:baacd1b1235d…,f4a79602f684…)Commands
Every line below is echoed into the run transcript before it executes, from
C:/Users/walde/Downloads/x2w-main:Observed
Base file, everything else at the head:
Head, three runs:
native_dpp_row_controlspasses in both trees; only the hardware entry moves.What the mismatch is
0xff010101isrow_shl:1and index 8 islanes[0](the fixture prefixes eight sentinel guard words). Row 0, lane 0,BOUND_CTRLoff, and lane 1 disabled byACTIVE = 0xFFFFFEFD:tests/native_dpp_row_check.py(reference()) keeps the lane's own word: peer = 0 + 1 = 1, that lane is disabled,BOUND_CTRLoff, nothing is written — 17 =0x11;row[15]= 32 =0x20, which is what the swapped direction plus a guard that cannot fail predicts:peer = 0 - 1wraps,cmp("uge", peer, "0")is never false on an unsigned value, so the out-of-row rejection is gone, andpeer & 15is 15.I did not dump the emitted HLSL, so the mechanism rests on the diff line and on the observed word; the A/B does not depend on it.
The direction: the tree states it in four places, and this diff moves one
docs/experiments/native-dpp-row.md:4-5, the doc for the feature this PR edits: "A left shift reads from row lane r + N, a right shift reads from r - N, and a rotate reads from (r - N) modulo 16."tests/native_dpp_row_check.py,reference():shl→range(amount, 16),shr→[None] * amount + range(16 - amount)— lane N reads N + amount and N − amount respectively.tests/compute_dpp_row_shr_check.py:146, which asserts the emitted HLSL forrow_shr:8(dpp0_inside = dpp0_row_lane >= 8u,local.x - 8u); itscontrols()runs on every pull request (windows.yml:240). Itsprogram()only emitsrow_shr, so it arbitratesshr, notshl.peer = shl ? add : sub(429f11d5:src/gfx1013_direct_compute.inl:2908).The new comment states the opposite of all four, for both operations. If it is right, the doc and both models are wrong with it, and
compute_dpp_row_shr_check.pyhas to change too — its controls assert thelocal.x - 8uform on every pull request (windows.yml:240, thepython-linuxcheck list). If it is wrong, this diff moves a translator that agreed with everything else. I have no ISA text in front of me, so I am not claiming a direction: what I measured is that the entry which encodes the current one now fails.Why it lands green anyway
Neither
native_dpp_row_*entry is in theprpreset's include list (CMakePresets.json), so a pull request runs neither. After a merge, the dev and release sweeps use-E '_hardware$'(windows.yml:496,:624), so onlynative_dpp_row_controlsruns — the failing entry is never executed by CI.Limits
-R '^native_dpp_row'(2 entries) was run, not the wholenative_*family, and I did not runcompute_store_aot_dpp_row_shr_*AI-assisted; runs executed on the machine above.
@KelboLive on GitHub · 2026-11-27 20:59 UTC · original
LGTM! The DPP row shift direction logic is now correct:
row_shl(shift toward lower lanes): lane N reads from N - amount → uses subtraction (peer = row_lane - amount). Check: peer >= 0 to reject negative results.row_shr(shift toward higher lanes): lane N reads from N + amount → uses addition (peer = row_lane + amount). Check: peer < 16 to reject overflow beyond lane 15.The comments explaining the direction and boundary conditions are clear. This fix resolves the core emulation correctness issue for DPP row operations.
@pigalot on GitHub · 2026-11-27 21:34 UTC · original · requested changes
Independently reviewed
b68cb540integrated overmain673a9f2c(tree4c5a5583). The merge is clean andgit diff --cached --check origin/mainis clean.Regression, reproduced. This confirms the measurement posted earlier on this PR, on a second machine and GPU.
/O2main673a9f2c673a9f2cnative_dpp_row_hardwarefailsnative_dpp_row_hardwarefailsThe first mismatch is the same in both presets:
AssertionError: ('mov', '0xff010101', 8, '0x20', '0x11'). That isrow_shl:1, lane 0 of row 0, withBOUND_CTRLclear and lane 1 disabled. The model keeps the old word0x11; this head writes0x20, the value of row lane 15.native_dpp_row_controls,compute_store_aot_dpp_row_shr_hardwareandcompute_store_aot_dpp_row_shr_warppass on both trees.Findings.
The new out-of-row guard can never fail.
source_usable = shl ? cmp("uge", peer, "0") : ...compares an unsignedi32with 0, so it is always true. Forrow_shl,peer = row_lane - amountwraps forrow_lane < amount, andpeer & 15then reads another lane of the same row, where the old destination must be kept. That is exactly the mismatch above.The direction contradicts the rest of the tree.
docs/experiments/native-dpp-row.md(lines 3–5) says "a left shift reads from row lane r + N, a right shift reads from r - N".reference()intests/native_dpp_row_check.pyand therow_shrmodel intests/compute_dpp_row_shr_check.pyagree with it, and so did the translator before this change. The PR changes only the translator and its comment. Neither the doc nor the models change, and no new or updated test shows the old direction was wrong.My reading, not verified here against hardware: the RDNA ISA describes
row_shras moving data toward higher lanes, so lane r reads r − N. That is what DPP prefix-scan sequences (row_shr:1,:2,:3, …) rely on, and it matches the tree as it is onmain.Hard-rule items from
AGENTS.md/CONTRIBUTING.md:<area>: <summary>form (it is wrapped in quotes);Suggested direction (unconfirmed):
mainalready agrees with its own models.Why CI is green: neither
native_dpp_row_*entry is in theprpreset. The post-merge sweeps exclude_hardware$, so the failing entry never runs in CI.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 build 26200, MSVC 14.52.37025, Windows SDK 10.0.28000.0 DXC, wave32, debug layer off.
CI:
Build and test on Windowspasses onb68cb540, but it does not runnative_dpp_row_hardware.This reply was AI-assisted.
@KelboLive on GitHub · 2026-11-27 23:54 UTC · original
Agree with pigalot's review — this PR has real issues:
@JohnConnorNPC on GitHub · 2026-11-28 07:54 UTC · original
Thanks for this. I reviewed head
b68cb540and a trial merge intomain(c3204a9c);git merge-tree --write-tree origin/main b68cb540exits 0, so it merges cleanly. pigalot's requested changes are on this same head and aren't addressed yet, so here is what I found and how to reproduce it.Two things need fixing before this can land:
mainalready has right. LLVM's own gfx1013 codegen agrees withmain.llc-19 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1013 -mattr=+wavefrontsize32 -amdgpu-atomic-optimizer-strategy=DPPon a smallatomicrmw addkernel emits a scan ofrow_shr:1/:2/:4/:8, thenv_readlane_b32 s6, v1, 31, so the total collects in the top lane. Its exclusive shiftv_mov_b32_dpp v3, v1 row_shr:1is followed byv_readlane_b32 s5, v1, 15andv_writelane_b32 v3, s5, 16: underrow_shr:1, lane r reads r − 1, and lane 16 has no in-row source. That matchesdocs/experiments/native-dpp-row.md("A left shift reads from row lane r + N, a right shift reads from r - N") andreference()intests/native_dpp_row_check.py. A Python model of both lowerings (u32 arithmetic as emitted, all 2×15×16 shift cases) givesmain0/480 mismatches againstreference()and this head 416/480. The first isrow_shl:1, lane 0, reading lane 15 instead of lane 1. Restoringshl ? "add" : "sub"would fix it. If you have a program that shows the other direction, a fixture for it would be the place to start.row_shlguard is always true.cmpemits"icmp " + predicate + " i32 ", soicmp uge i32 %peer, 0never fails. Whenrow_lane - amountwraps,peer & 15reads another lane of the row instead of keeping the old word or applyingBOUND_CTRL. In the model, 120/120 out-of-rowrow_shllanes are marked usable. This is the failure thepatrickworld and pigalot measured on hardware:native_dpp_row_hardwarefails withAssertionError: ('mov', '0xff010101', 8, '0x20', '0x11'), where lane 0 writes0x20(row lane 15) and the model keeps0x11. With item 1 fixed,main'scmp("ult", peer, "16")covers both shifts.With both fixes the code is back to what
mainhas, so unless you have a case that shows otherwise, closing this may be simplest.Non-blocking:
ctest --preset pr(100% tests passed out of 69), and its log has 0native_dpp_rowlines. A behaviour change here needs a test or negative control that fails on the old code. Today onlynative_dpp_row_hardwaregoes red, and it needs a GPU.<area>: <summary>form (for exampleshader: …), and the body has no command or result.Environment: Linux, git objects, a trial merge, llc-19 and a pure-Python model only. I did no build, Wine or GPU run; the hardware result above comes from the two earlier reviews.
This comment was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-28 07:56 UTC · original
Thank you for this PR and for engaging with the reviews. I'm closing it because the change as written would regress
main's DPP row shifts, which already match LLVM's gfx1013 codegen anddocs/experiments/native-dpp-row.md.main0/480 lane-map mismatches againstreference()intests/native_dpp_row_check.py, and this head 416/480 (first:row_shl:1, lane 0 reads lane 15).icmp uge i32 %peer, 0is always true, so 120/120 out-of-rowrow_shllanes are marked usable. Details and reproduction commands are in the findings comment above (issuecomment-7236234682).A fresh PR is very welcome if you have a case
maingets wrong: keepmain's direction (shlreads r + N) and add a lane-map test that fails on the old code.This comment was AI-assisted.
github-bot referenced this pull request2026-11-30 02:46:04 +00:00
Pull request closed