Repository navigation
agx: put the inclusive ballot count's +1 at the count - #1549
Conversation
When ballot_bit_count_inclusive reuses the rank already in front of its ballot, active_rank_at_ballot() leaves the builder cursor where the previous rewrite put it, and the +1 is emitted there. If that rewrite was a count of another ballot(true) inside an if, the iadd lands inside the if while its use comes after it. Such shaders fail NIR validation in builds with asserts, and release builds compile the invalid SSA. Put the +1 in front of the count it replaces, and add a test of this shape for the default, G17P and M5 subgroup lowering. Fixes: e20bc72 ("agx: reuse adjacent rank reads for the same ballot") Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed at c365c46d7d9f (non-author, 12-01 bar).
active_rank_at_ballot() only moves b->cursor when inserting a new rank, so reusing a rank after an inner-branch rewrite left the inclusive-count +1 inside the preceding if block where it does not dominate the use. Setting b->cursor = nir_before_instr(&intr->instr) before nir_iadd_imm(b, active_id, 1) guarantees dominance on both reuse and insert paths. The new Wave8InclusiveCountReusedRankAfterIf test covers default, G17P, and M5 lowering with explicit dominance checks and nir_validate_shader().
Not merging from B2-MERGE while your hardware rows at c365c46d7d9f are pending.
J773g (M4 mini, T8132, G16G B0, OS FW 27.2 / 26B123) — PASS (exact-head A/B vs base
|
| Suite | Base c94b25ce4e2f (Pass / Fail / NotSup) |
Head c365c46d7d9f (Pass / Fail / NotSup) |
New Fails |
|---|---|---|---|
dEQP-VK.subgroups.ballot_other.compute.* |
14 / 0 / 0 | 14 / 0 / 0 | 0 |
dEQP-VK.subgroups.ballot_broadcast.compute.* |
264 / 0 / 1356 | 264 / 0 / 1356 | 0 |
dEQP-VK.subgroups.arithmetic.compute.* |
1608 / 0 / 522 | 1608 / 0 / 522 | 0 |
dEQP-VK.subgroups.basic.compute.* |
12 / 0 / 0 | 12 / 0 / 0 | 0 |
| Total (3776 cases) | 1898 / 0 / 1878 | 1898 / 0 / 1878 | 0 |
- GPU & kernel health:
0GPU recoveries,0new GPU kernel errors (dmesgclean),WARN_BUG_OOPS_SERROR=0.
J700 (MacBook Neo, A18 Pro, G17P B1): PASS. Exact-head A/B against base
|
| Group | Cases | Base: Pass / Not supported / Fail | Head: Pass / Not supported / Fail | New fails on head | Fail on base, pass on head |
|---|---|---|---|---|---|
subgroups.ballot_other.compute.* |
14 | 14 / 0 / 0 | 14 / 0 / 0 | 0 | 0 |
subgroups.basic.compute.* |
12 | 12 / 0 / 0 | 12 / 0 / 0 | 0 | 0 |
subgroups.ballot_broadcast.compute.* |
1,620 | 264 / 1,356 / 0 | 264 / 1,356 / 0 | 0 | 0 |
subgroups.arithmetic.compute.* |
2,130 | 1,608 / 522 / 0 | 1,608 / 522 / 0 | 0 | 0 |
| Total | 3,776 | 1,898 / 1,878 / 0 | 1,898 / 1,878 / 0 | 0 | 0 |
Every case had the same status on both arms. There were no crashes, timeouts or InternalErrors, and all 8 deqp-vk runs exited 0.
What this shows: the base passed every case too, including subgroupballotinclusivebitcount and its _requiredsubgroupsize variant. So on G17P these groups don't reach the shape asahi: optimize integer and subgroup operations #1540 miscompiled (a reused rank whose +1 lands at a stale cursor). That shape is covered by the PR's new unit test. This row shows the fix is safe on AGX3B for these groups. It is not a CTS reproduction of the bug.
Faults and kernel log: a scan after each step and a final scan found 0 GPU-side lines: no faults, timeouts, recoveries or lost devices. The kernel log over the run window had no new lines at all, so there were 0 WARN/BUG/Oops lines.
Stock handback: the boot ID, kernel, Mesa packages and library hashes, GRUB default entry and failed units (0) all matched before and after. One GRUB env flag changed, boot_success=0 to 1. Fedora's own grub-boot-success.timer set it at 12:53:49, two minutes after this boot started, while the row was running. I re-checked the board under the lease afterwards and it is in its stock state.
What: Fixes a bug that #1540 added to the AGX compute ballot-count lowering. When
ballot_bit_count_inclusivereuses the rank in front of its ballot, its+1is emitted wherever the previous rewrite left the builder cursor. After a rewrittenballot(true)count inside anif, the+1lands inside thatifbut is used after it, so the shader fails NIR validation when asserts are on and release builds compile the invalid SSA. This puts the+1in front of the count it replaces and adds a regression test. Reported in #1540 (comment).Tested: at
c365c46d7d9f: J773g (M4 mini, G16G) and J700 (G17P) subgroup compute CTS A/B against basec94b25ce4e2fare both PASS with 0 new fails (3,776 cases each: 1,898 Pass and 1,878 NotSupported on both arms), 0 GPU faults or recoveries, receipts 7353790211 and 7353816751. Local CI: Meson asahi/poly/vulkan suites 454 OK, 0 fail, 1 skip;agx_tests1,960 passed, 1 skipped; the repro shader now compiles on G14G, G16G and G17P; the GTA V shader-db is unchanged on G17P and G16G. Without the fix, the new test fails and the repro shader fails NIR validation on all three GPUs.Risk: two-way · all Macs: compute shaders on every AGX generation that use subgroup ballot bit counts. The change only moves where one
iaddis placed.Not yet: rows on J414s (G14) and J714s (G17S). They don't gate the merge: two generations pass at this head, and the host test covers all three lowerings.
Details
active_rank_at_ballot()reuses theu2u32(load_active_subgroup_invocation_agx)that sits right before a ballot, and it only setsb->cursorwhen it has to insert a new rank.nir_shader_intrinsics_pass()does not reset the cursor between instructions. So on the reuse path the inclusive count'siaddwent wherever the previous rewrite had left the cursor, in front of another ballot that can be inside anif. The+1is now placed withb->cursor = nir_before_instr(&intr->instr). On the insert path it used to sit in front of the ballot and now sits in front of the count. Both positions dominate the use.The exclusive count and the
bit_count(ballot & lt_mask)form emit no instruction on the reuse path, so they were not affected.New test
AGX3VisionOpts.Wave8InclusiveCountReusedRankAfterIf, next to #1540's tests: an exclusive count of ballot A, then an exclusive count of ballot B inside anif, then an inclusive count of ballot A after theif. It runs the default, G17P and M5 subgroup lowering, checks that the stored value dominates its store (nir_validate_shader()is a no-op without asserts), validates the shader, and checks that there are two ranks, which shows the inclusive count took the reuse path.The signed power-of-two idiv fold from #1540 is not touched here.
Evidence
Head
c365c46d7d9fb2f336090e4c70b866440527fbb4, baseaurora-wipatc94b25ce4e2fb5586e947554a694c48b2fc166d3(the #1540 merge).Local CI: x86-64 Fedora 44 container,
debugoptimizedwith asserts, warm build directory and ccache.c94b25ce4e2fc365c46d7d9fagx_testsWithout the fix, the new test fails on each target (0 = default, 1 = G17P, 2 = M5 lowering):
Repro shader through Borealis and the noop drm-shim (
ASAHI_SHIM_CHIP=<chip> fossilize-replay --enable-pipeline-stats):nir_block_dominates, nir_validate.c:1879)GTA V shader-db, base to head (Steam Fossilize DB,
fossilize-replay --master-process --num-threads 10 --enable-pipeline-stats, no crashed or hung pipelines in any run):