Repository navigation
borealis: enable ordered tile reduction pass on AGX3B - #1573
DjDeveloperr merged 1 commit into
Conversation
All native AGX3B chips (M3 G15G/S/C, M4 G16G/S/C, M4 Max G17P) expose 32-wide subgroups and encode immediate-lane simdbfly shuffle_xor natively in compute shaders, just like AGX3C. Extend the hk_nir_opt_ordered_tile_reduction() gate in hk_preprocess_nir_internal() from AGX3C-only to both AGX3B and AGX3C, allowing 16x16 shared-memory tile reductions (texelFetch -> 8-stage ordered min/max/sum -> imageStore) to lower into 32x8 subgroup shuffles with 1 barrier instead of 8 and 384 B of shared memory instead of 3072 B. Measured on Apple M4 Max (G17P) with a 2048x2048 R32_UINT -> 128x128 RGBA32F 16x16 ordered tile reduction (40 batched dispatches, 7 runs): - Shader: 142 -> 87 instrs, 166 -> 97 native, 1764 -> 850 code bytes, 1024 threads preserved, 0 spills. - GPU time: 103.35 us -> 40.67 us median (2.54x faster, bit-exact hash ecf8005493440c25). - Compile smoke-checked via drm-shim on g15g, g16g, g17p, and g17s (88-89 instrs, ~854 B, 1024 threads). Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
RyanTheTide
left a comment
There was a problem hiding this comment.
The change enables the existing ordered reduction only for AGX3B chips that still pass all three 32-wide subgroup checks. The constant XOR shuffle form is available on these targets. The M4 Max row reports a bit-exact result and lower dispatch time, with M3 and M4 additionally covered by compile checks.
|
We run the pass at |
|
J516s (Apple MacBook Pro 16-inch M3 Pro, Results
|
|
Hardware verification on J773g (Apple Mac mini M4, Environment & Arms
Key Results
Full
|
J700 (MacBook Neo, A18 Pro, G17P B1) at PR head
|
| Check | Result |
|---|---|
| The program, base, head, head, base: 180 combinations each (5 sizes, 4 inputs, 3 shaders, 3 dispatch kinds), 3 times each, every texel against a CPU reference with a guard row and column | PASS in all 4 runs, 3,003,372 texels checked per run, 0 bad |
| Pass active on G17P | yes. The matching shader drops from 148 to 101 instructions (173 to 112 native), code size 1,798 to 1,072 bytes, threads and spills unchanged |
The two near misses (near_xor, near_rev) |
unchanged between base and head |
| Time of the matching dispatch at 3024×1964, median | 1,018.7 µs to 428.8 µs (0.421×, 2.4× faster), both head runs agree to 0.1 µs and both base runs to 0.1 µs |
| CTS, 16,875 cases (subgroups and compute), base and head | 16,875 of 16,875 recorded on both, 11,054 Pass, 5,821 NotSupported on both, 0 differences |
| GPU lines in the kernel log during the run | 0 |
Not covered: one J700, one boot, the CTS list is the kit's. The near misses differ between repeats by up to 0.8 % (near_rev 1,010.5 µs on the two base runs, 1,018.7 µs on the head runs), which is a timing spread, not a shader change.
Summary
Extends the
hk_nir_opt_ordered_tile_reduction()gate inhk_preprocess_nir_internal()fromAGX_ISA_ENCODING_AGX3Cto bothAGX_ISA_ENCODING_AGX3B(M3 G15G/S/C, M4 G16G/S/C, M4 Max G17P) andAGX_ISA_ENCODING_AGX3C.Every native AGX3B chip exposes 32-wide subgroups and encodes immediate-lane
simdbflyshuffle_xornatively in compute shaders (agx_nir_lower_subgroups.c/agx_compile.c), and the pass only emits constant shuffle distances (16/8/4/2/1) with an explicit 16x16 → 32x8 workgroup remap.Verification
hk_ordered_tile_reduction,hk_compute_pair,hk_pack, andagx_testsall PASS.drm-shim,MESA_SHADER_CACHE_DISABLE=true):g15g,g16g,g17p,g17sall lower the 16×16 ordered min/max/sum tile reduction cleanly (87–89instrs,~854 B,1024threads,0spills).2048×2048R32_UINT→128×128RGBA32F16×16 ordered min/max/sum tile reduction, 40 batched dispatches × 7 runs):142 → 87instrs (-38.7%),166 → 97native (-41.6%),1764 → 850code bytes (-51.8%),1024threads preserved,0spills103.35 µs → 40.67 µs(2.54× faster, bit-exact readback hashecf8005493440c25)g15g) and M4 (g16g) compile-verified viadrm-shim.