Repository navigation
asahi/agx3b: allow 16-bit results and immediate selects with uniform isel comparands - #1619
Conversation
…isel comparands AGX3B explicit isel (ep=25/26/27) already encodes one aligned 32-bit uniform comparand (f36/f42=3 or f51/f57=3) beside a 32-bit register with 32-bit register select arms. Silicon verification on Apple M4 Max (G16C B1) confirms the same uniform-comparand encoding also executes bit-accurately with 8-bit immediate select arms and with 16-bit results (both even ep=25 and odd ep=26 destination halves, and even/odd 16-bit register or 8-bit immediate select arms). Admit those shapes in agx3_isel_core.c and keep their uniforms in place in agx_lower_uniform_sources.c for both AGX_OPCODE_ICMP and AGX_OPCODE_ICMPSEL on AGX3B, while skipping agx3_widen_uniform_compare() on AGX3B so 16-bit boolean comparisons do not widen to 32-bit registers and inflate GPR pressure. Uniform select arms remain restricted to 32-bit results, and all other refused combinations (two uniform comparands, uniform beside immediate comparand, uniform comparand with uniform select, 16-bit comparands, misaligned/high uniforms, and cache/discard hints on uniforms) stay rejected. Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Checked at 55d92a6, merged onto aurora-wip 23f7c86 (clean merge, also after mesa#1566's uniform-copy CSE landed).
The code looks right to me:
- The lowering and the encoder agree.
agx3_isel_uniforms_kept()now keeps a uniform comparand only beside a 32-bit register comparand, with select arms that are either registers of the result's width or immediates up to 255. That is exactly whatencode_explicit()now accepts. Uniform select arms stay limited to 32-bit results on both sides. - An ICMP becomes an ICMPSEL with #1/#0 arms in
agx_lower_pseudo(), so keeping its uniform lands on the same encoder form. - Anything outside those forms still copies the uniform: immediates above 255, select registers of the other width, 16-bit comparands, high or odd uniforms, and the preamble. So no immediate that doesn't fit can reach the encoder from this path.
- M5 doesn't change: the M5 path returns before the new code, and only AGX3B skips
agx3_widen_uniform_compare().
What I ran (x86 debugoptimized build, assertions on):
agx_tests2,012 pass, 1 skip.agx3_isel_core_test251 checks, 0 failures.meson test --suite asahi410 OK, 0 fail, 1 skip.- drm-shim compile slice, aurora-wip vs this PR: the 15,641-case wide list (compute, ssbo, robustness, glsl) with each Mac's own feature word, every case covered on each chip. No refused shaders on either side, and no case changed result, on G15S, G16G or G17P.
- Code changes in 2,215 cases on G15S, 1,638 on G16G and 1,893 on G17P, almost all robustness and compute.
- Those shaders get 0.3 to 1.0 % smaller in total. None drops to a lower thread count; 10 on G15S and 10 on G16G go up a step.
- I reran those changed cases A/B on the new tip: same result.
- shader-db under drm-shim (G16G and G17P with the shim's default feature word):
- ggml-vulkan, 1,110 compute shaders: instructions −0.67 % (G15S), −0.53 % (G16G), −0.67 % (G17P) on cea627b, and −0.52 / −0.38 / −0.51 % on the new tip, where #1566 already removes some of the same copies. Uniform copies inside loops drop 57 % on G15S and G17P. Threads, spills and fills are unchanged on every chip.
- GTA V compute, 272 pipelines: −0.28 % (G16G), −0.36 % (G17P), threads unchanged.
- One thing that looks like a regression but isn't: on G16G, two ggml shaders (four pipelines) grow from 3,499 to 4,062 instructions and from 36 to 40 loops. The register savings bring their 8× unrolled version under 96 halves, so
agx_compile_shader_nir_unroll_choice()now keeps it instead of falling back to 4×. They stay at 1,024 threads. That's the unroll rule working as written, so I'm not asking for a change, but it's why G16G's loop-copy count goes up 13 to 14 % while the other chips drop 57 %.
Approving the code. Before it merges it needs CTS rows at this head on our AGX3B Macs. The new forms have only run on G16C (M4 Max), but the encoder change covers the whole AGX3B ISA, so M3 (G15S) and Neo (G17P) code changes too. Kits are sealed for J773g (M4 mini), J700 (Neo) and J516s (M3 Pro). Each runs that chip's changed cases first, then a wide list, and counts refusals and GPU faults.
Small, not blocking: the comment above the admitted shapes in encode_explicit() still says "G17P". The immediate-arm and 16-bit-result forms come from your G16C probes, so it would help to say which chip they were seen on.
|
J516s (MacBook Pro 16-inch M3 Pro,
|
|
Hardware row at head Kit: |
|
J700 (MacBook Neo, A18 Pro, G17P B1) at head Stock Fedora 44 kernel
0 cases with a different result, 0 cases without a result, and 0 GPU fault, reset or timeout lines in the kernel log during the run. |
|
Merged at head |
What:
Allow AGX3B explicit
isel(ep=25/26/27) to read a single aligned 32-bit uniform comparand (cmp0orcmp1) beside a 32-bit register with:imm/imm,reg/imm,imm/reg), andep=25and oddep=26destination halves, with 16-bit register or 8-bit immediate select arms).In
agx_lower_uniform_sources.c, keep those uniform comparands in place for bothAGX_OPCODE_ICMPandAGX_OPCODE_ICMPSELonAGX_ISA_ENCODING_AGX3B, and skipagx3_widen_uniform_compare()on AGX3B so 16-bit boolean comparisons stay 16-bit instead of widening to 32-bit registers and inflating GPR pressure. Uniform select arms remain restricted to 32-bit results, and all other refused combinations (two uniform comparands, uniform + immediate comparand, uniform comparand + uniform select, 16-bit comparands, misaligned/high uniforms, and cache/discard hints on uniforms) stay rejected.Tested:
All tested against base
eede989f441on Apple M4 Max (J616C, G16C B1) and host x86_64 assertions-enabled build (55d92a6631a, compiler binary identical to the silicon-tested build; only test coverage and commit formatting changed after silicon runs):Apple M4 Max (G16C B1), 0 GPU faults / 0dmesgerrors):iselprobe (cmp0_uniform&cmp1_uniform×{imm/imm, reg/imm, imm/reg}+ chained 16-bit boolean compares across signed/unsigned conditions and boundary values0, 1, 0x7fffffff, 0x80000000, 0xffffffff): 1,152 / 1,152 PASS (0 errors).uint16_tiselprobe (AGX_MESA_DEBUG=shadersverified emittedep=25/ep=26even & odd 16-bit dests,cmp0_uniform&cmp1_uniform, even & oddreg16/reg16,reg16/imm,imm/reg16,imm/immwith0/99/177/254/255and cache/discard hints): 256 / 256 PASS (0 errors).isel_loop_bench.spv, mirroringg2p/nets_quads/leaf_step:246 → 196instrs −20.3%,35 → 25GPRs,47 → 0loop uniform copies,1024 → 1024threads, 9 samples × 16 dispatches per run):7.1855, 7.2108, 7.2553, 7.2706, 7.2880, 7.2454, 7.1947, 7.1872 ms, min7.1517 ms)5.6843, 5.6974, 5.7039, 5.7558, 5.6985, 5.7934, 5.7069, 5.6802 ms, min5.6587 ms)15d51c610f5f2237on all 16 runs.mg_restrict.spv(441 → 419instrs −4.99%,1024 → 1024threads, 7 samples × 20 dispatches per run): bit-identical output hashba1f1e8fc15f0f1eon all 16 runs, median2.212 → 2.186 ms(−1.2%, memory-bound).drm-shimshader-db (88 real compute shaders, 0 occupancy regressions):126,881 → 125,240(−1,641 / −1.29 %), code size1,189,834 → 1,183,390 B(−6,444 B), loop uniform copies1,587 → 1,166(−421 / −26.53 %). Top reductions:mg_coarsen−16.93%,nets_quads−12.13% (loop ucpy 38→9),sheet_fill−10.07% (GPRs 35→30),leaf_step−8.23% (loop ucpy 24→5),g2p−189 instrs (loop ucpy 90→9).131,842 → 130,366(−1,476 / −1.12 %), code size −5,940 B, loop uniform copies1,504 → 1,184(−320 / −21.28 %).ggml-vulkanmul_mat_vec(4/4 shaders on G17P): 4/4 changed, Threads up/down: +0 / −0, −55 instrs (−0.81 %), −220 B.-Db_ndebug=false, at exact head55d92a6631a):agx3_isel_core_test: 251 checks, 0 failures.agx_tests: 2,009 passed, 1 skipped, 0 failed (including updated positive/negative AGX3B uniform-comparand pack, decode, and lowering tests, and preserving M5/AGX3Cagx3_widen_uniform_comparecoverage).Risk:
two-way door · scoped strictly to
AGX_ISA_ENCODING_AGX3B(encode_explicit()andagx3_isel_uniforms_kept()/agx3_widen_uniform_compare()); M5 (AGX3C/AGX3D) and AGX2 are untouched, and every newly admitted shape was bit-exact verified on G16C B1 silicon.Not yet: