Repository navigation
agx: enable load flattening on AGX3B, fold post-DMA selects (AGX3B/M5), and flatten tile-load bursts - #761
agx: enable load flattening on AGX3B, fold post-DMA selects (AGX3B/M5), and flatten tile-load bursts#761DjDeveloperr wants to merge 2 commits into
Conversation
|
Review at cf49487. Read at cf49487 (not built here). I could not construct a miscompile in the store sink or the burst flatten, and "AGX2 and G18G unchanged" holds by reading. What blocks it:
|
0dee159 to
73cad5b
Compare
|
Review at 73cad5b. Re-read after the force-push (now ecfce54 + 73cad5b; not built here). Status of our points from cf49487:
Commits have only the human Signed-off-by. Verdict: NITS on code (the shared late-tail helper in 3, plus the test control in 2). Merge waits on the rows in 1 and the shader-db numbers in 5. Both are owed by the author. |
Enable agx_nir_opt_flatten_loads on AGX3B alongside AGX3C (sharing the (AGX3B || AGX3C) && !emit_agx3d gate, leaving AGX2 and G18G untouched), using a single encoding-uniform peephole_select expensive_limit = 0 inside the load-flattening loop so G15G/G16G/G17P/G17S flatten identically without chip-name divergence. Detect uniform 4/2/1 IV-stepped binary-tail cascades locally inside agx_nir_opt_flatten_loads rather than marking nir_selection_control_dont_flatten in agx_nir_unroll_runtime_loops, keeping nir_opt_peephole_select free to fold pure-ALU / speculatable tail chunks while still preventing dummy-page load speculation across tail cascades. When !form_preamble runs agx3_nir_lower_uniform_dma (including AGX3B compute and M5 no-preamble fragment programs), promoting UBO loads inside short-circuit branches to load_preamble makes those branches trivial. Run nir_opt_peephole_select (expensive_limit = 0) and, when it makes progress, re-run the full late-lowering tail (int64 scalarize/lower, agx_nir_lower_algebraic_late, agx_nir_fuse_selects, agx_nir_fold_const_select_alu, constant folding, CSE, scalarization, sink/move with derivative guard, phi scalarization, copy prop, DCE, and divergence). Reaches all shader stages on AGX3B (G15/G16/G17P/G17A) and AGX3C without emit_agx3d (G17G/G17S / M5), including M5 no-preamble fragment shaders. Signed-off-by: DjDeveloperr <hey@djdev.me>
73cad5b to
f9f69ac
Compare
|
Review at f9f69ac. range-diff against 73cad5b: commit 1 changed, commit 2 is identical. Status of our points:
Commits have only the human Signed-off-by. Nothing new found in the helper extraction. Verdict: APPROVE on code (the duplicate gate is a nit). Merge waits on rows owed by the author at f9f69ac: dEQP-VK compute + SSBO/UBO + robustness and a GL row on M3 (G15G), M4 (G16G), A18 Pro and M4 Pro (G17P), and one M5, plus an ABBA perf row per encoding and the shader-db numbers for point 5. #762 is stacked on this PR. |
Bare-Metal M5 Pro (
|
| API / Driver | CTS Group | Passed | Failed | Not Supported |
|---|---|---|---|---|
Vulkan (Borealis) |
dEQP-VK.compute.pipeline.basic.* (full) |
80/81 | 0 | 1 |
Vulkan (Borealis) |
dEQP-VK.ssbo.* (489 evenly-sampled of 12,225) |
487/489 | 0 | 2 |
Vulkan (Borealis) |
dEQP-VK.ubo.* (491 evenly-sampled of 13,240) |
491/491 | 0 | 0 |
Vulkan (Borealis) |
dEQP-VK.robustness.buffer_access.* (303 evenly-sampled of 1,212) |
255/303 | 0 | 48 |
Vulkan (Borealis) |
dEQP-VK.glsl.loops.* (312 evenly-sampled of 624) |
312/312 | 0 | 0 |
| Native Asahi GLES3 | dEQP-GLES3.functional.ubo.single_basic_type.* (full) |
968/968 | 0 | 0 |
| Native Asahi GLES3 | dEQP-GLES3.functional.shaders.loops.for_constant_iterations.* (full) |
64/64 | 0 | 0 |
| Native Asahi GLES3 | dEQP-GLES3.functional.color_clear.* (full) |
19/19 | 0 | 0 |
- GPU faults (
dmesg):0(delta = 0). - Note: Because
agx_testsfailed to compile under GCC 16.1.1,meson test --suite asahiis blocked until the designated-initializer order intest-flatten-loads.cpp:783,789is fixed.
|
Addressed all remaining review items from
Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
Bare-Metal M5 Pro (
|
| CTS Group | Passed | Failed | Not Supported |
|---|---|---|---|
dEQP-VK.compute.pipeline.basic.* (full) |
80/81 | 0 | 1 |
dEQP-VK.ssbo.* (489 evenly-sampled of 12,225) |
487/489 | 0 | 2 |
dEQP-VK.ubo.* (491 evenly-sampled of 13,240) |
491/491 | 0 | 0 |
dEQP-VK.robustness.buffer_access.* (303 evenly-sampled of 1,212) |
255/303 | 0 | 48 |
dEQP-VK.glsl.loops.* (312 evenly-sampled of 624) |
312/312 | 0 | 0 |
- GPU faults (
dmesg):0(delta = 0).
|
Pushed
Earlier R3 row on J773g, kept for reference: Exact-head verification on Apple M4 (
Single-Threaded CTS (
|
| Suite / Group | Passed | NS | Failed |
|---|---|---|---|
dEQP-VK.compute.pipeline.basic.* |
79/81 |
2 |
0 |
dEQP-VK.glsl.loops.* |
624/624 |
0 |
0 |
dEQP-VK.ssbo.layout.single_basic_type.std430.* |
303/303 |
0 |
0 |
dEQP-VK.ubo.{random,2_level_struct,single_basic} |
118/160 |
42 |
0 |
dEQP-VK.robustness.*robustness2.* (1d comp/v/f) |
36/36 |
0 |
0 |
dEQP-VK.robustness.index_access.* |
31/40 |
9 |
0 |
dEQP-VK.robustness.buffer_access.{v,f,c} + rob2 |
120/156 |
36 |
0 |
| VK unique total (deduplicated) | 1,275/1,364 |
89 |
0 |
dEQP-GLES31.functional.compute.basic.* |
41/41 |
0 |
0 |
dEQP-GLES31.functional.ssbo.layout...std430.* |
121/121 |
0 |
0 |
| GLES31 total | 162/162 |
0 |
0 |
gpubench-vk ABCCBA: #761 R3 (f9f69ac793) vs #758 R2 (01a39fa4f9)
72/72 pairwise (108/108 unique 6-leg stack) CRCs bit-identical PASS, 0 non-cooling dmesg lines. Highlights -1.74% (d=1) / -1.42% (d=4) GPU win on compute.edge kind=harris.
| Workload | d |
Wall (us_per_submit) #758 R2 -> #761 R3 |
Wall delta / speedup | GPU (gpu_us) #758 R2 -> #761 R3 |
GPU delta / speedup | CRC |
|---|---|---|---|---|---|---|
compute.conv2d kind=gaussian,res=1080p |
1 |
1506.07 -> 1242.24 |
-17.52% (1.212×) |
939.55 -> 909.38 |
-3.21% (1.033×) |
2d55a14d PASS |
compute.conv2d kind=gaussian,res=1080p |
4 |
913.24 -> 913.24 |
+0.00% (1.000×) |
910.10 -> 910.08 |
-0.00% (1.000×) |
2d55a14d PASS |
compute.conv2d kind=bilateral,res=1080p |
1 |
1754.39 -> 1746.76 |
-0.43% (1.004×) |
1469.71 -> 1469.73 |
+0.00% (1.000×) |
6cdc0716 PASS |
compute.conv2d kind=bilateral,res=1080p |
4 |
1481.48 -> 1481.48 |
+0.00% (1.000×) |
1472.54 -> 1472.60 |
+0.00% (1.000×) |
6cdc0716 PASS |
compute.stereo disp=64 |
1 |
20000.00 -> 19090.91 |
-4.55% (1.048×) |
18726.90 -> 18727.35 |
+0.00% (1.000×) |
c62aadf9 PASS |
compute.stereo disp=64 |
2 |
18181.82 -> 18181.82 |
+0.00% (1.000×) |
18723.64 -> 18721.82 |
-0.01% (1.000×) |
c62aadf9 PASS |
compute.edge kind=sobel,res=1080p |
1 |
798.41 -> 793.65 |
-0.60% (1.006×) |
510.42 -> 513.50 |
+0.60% (0.994×) |
27c79e6d PASS |
compute.edge kind=sobel,res=1080p |
4 |
518.13 -> 522.20 |
+0.78% (0.992×) |
515.09 -> 518.67 |
+0.69% (0.993×) |
27c79e6d PASS |
compute.edge kind=harris,res=1080p |
1 |
961.74 -> 954.70 |
-0.73% (1.007×) |
674.83 -> 663.06 |
-1.74% (1.018×) |
4cebadfc PASS |
compute.edge kind=harris,res=1080p |
4 |
701.75 -> 690.85 |
-1.55% (1.016×) |
698.46 -> 688.53 |
-1.42% (1.014×) |
4cebadfc PASS |
compute.uber kind=divergent |
1 |
727.27 -> 722.02 |
-0.72% (1.007×) |
499.98 -> 500.02 |
+0.01% (1.000×) |
9963f56c PASS |
compute.uber kind=divergent |
4 |
504.41 -> 504.41 |
+0.00% (1.000×) |
502.21 -> 502.20 |
-0.00% (1.000×) |
9963f56c PASS |
compute.uber kind=uniform |
1 |
411.10 -> 411.52 |
+0.10% (0.999×) |
185.77 -> 185.77 |
+0.00% (1.000×) |
b022fbaf PASS |
compute.uber kind=uniform |
4 |
190.39 -> 190.57 |
+0.10% (0.999×) |
187.88 -> 187.85 |
-0.01% (1.000×) |
b022fbaf PASS |
compute.uber kind=ilp |
1 |
611.64 -> 610.70 |
-0.15% (1.002×) |
383.46 -> 383.47 |
+0.00% (1.000×) |
19f35e30 PASS |
compute.uber kind=ilp |
4 |
389.48 -> 389.86 |
+0.10% (0.999×) |
386.88 -> 387.06 |
+0.05% (1.000×) |
19f35e30 PASS |
compute.light |
1 |
139.84 -> 138.81 |
-0.74% (1.007×) |
1.58 -> 1.58 |
-0.03% (1.000×) |
n/a |
compute.light |
4 |
55.69 -> 56.00 |
+0.56% (0.994×) |
1.58 -> 1.58 |
+0.00% (1.000×) |
n/a |
compute.heavy |
1 |
790.53 -> 787.40 |
-0.40% (1.004×) |
544.33 -> 544.31 |
-0.00% (1.000×) |
n/a |
compute.heavy |
4 |
547.95 -> 547.95 |
+0.00% (1.000×) |
544.33 -> 544.33 |
+0.00% (1.000×) |
n/a |
compute.cull_mdi |
1 |
2439.39 -> 2469.14 |
+1.22% (0.988×) |
1268.09 -> 1273.13 |
+0.40% (0.996×) |
57276de2 PASS |
compute.cull_mdi |
4 |
1793.75 -> 1753.65 |
-2.24% (1.023×) |
1339.14 -> 1338.41 |
-0.05% (1.001×) |
57276de2 PASS |
gpubench-gl ABCCBA: #761 R3 vs #758 R2
16/16 pairwise (24/24 unique 6-leg stack) CRCs PASS, DMESG_DELTA=0, 0 regressions.
| Workload | d |
Wall (us_per_submit) #758 R2 -> #761 R3 |
Wall delta / speedup | GPU (gpu_us) #758 R2 -> #761 R3 |
GPU delta / speedup | CRC |
|---|---|---|---|---|---|---|
compute.uber kind=divergent |
1 |
738.92 -> 735.29 |
-0.49% (1.005×) |
n/a |
n/a |
9963f56c PASS |
compute.uber kind=divergent |
4 |
506.76 -> 506.76 |
+0.00% (1.000×) |
n/a |
n/a |
9963f56c PASS |
compute.uber kind=uniform |
1 |
421.40 -> 427.96 |
+1.56% (0.985×) |
n/a |
n/a |
b022fbaf PASS |
compute.uber kind=uniform |
4 |
192.31 -> 192.93 |
+0.32% (0.997×) |
n/a |
n/a |
b022fbaf PASS |
compute.image |
1 |
456.63 -> 453.86 |
-0.61% (1.006×) |
n/a |
n/a |
n/a |
compute.image |
4 |
191.94 -> 192.80 |
+0.45% (0.996×) |
n/a |
n/a |
n/a |
compute.heavy |
1 |
795.76 -> 800.01 |
+0.53% (0.995×) |
5.06 -> 5.10 |
+0.83% (0.992×) |
n/a |
compute.heavy |
2 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.15 -> 5.25 |
+2.02% (0.980×) |
n/a |
compute.heavy |
4 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.06 -> 5.35 |
+5.77% (0.945×) |
n/a |
compute.heavy |
8 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.21 -> 5.29 |
+1.60% (0.984×) |
n/a |
compute.heavy |
16 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.13 -> 5.38 |
+4.86% (0.954×) |
n/a |
compute.heavy |
32 |
559.70 -> 559.70 |
+0.00% (1.000×) |
5.15 -> 5.42 |
+5.08% (0.952×) |
n/a |
compute.heavy |
64 |
559.70 -> 559.70 |
+0.00% (1.000×) |
5.25 -> 5.40 |
+2.94% (0.971×) |
n/a |
- Post-flight health:
DMESG_CLEAN_DELTA=0,NON_COOLING_CLEAN_DELTA=0,0GPU faults / kernel bugs (REAL_FULL_BOOT_KERNEL_BUGS=0,SCHED_WHILE_ATOMIC=0,INTERRUPT_RC_WARN=0),IDLE_CLEAN.
satchlj
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge
Checked: Full diff across src/asahi/compiler/agx_compile.c, src/asahi/compiler/agx_nir_opt_flatten_loads.c, src/asahi/compiler/test/test-agx3-vision-opts.cpp, and src/asahi/compiler/test/test-flatten-loads.cpp, plus native assert-enabled -Dbuild-tests=true compilation under g++ (GCC) 16.1.1 on Mac Studio M5 Max (J775c, T6050).
Blockers:
src/asahi/compiler/test/test-flatten-loads.cpp:783-785and:789-791(FlattenLoadsKeeps::StoreSharedMismatchedOrVolatileNotSunk): bothnir_store_shared(...)calls pass.accessafter.write_maskand.align_mul, violating C++20 designated-initializer declaration order forstruct _nir_store_shared_indices(base,access,write_mask,align_mul,align_offset). This breaks-Dbuild-tests=truecompilation ofagx_testsunder GCC 16.1.1 (also noted on R2 and still present at R3f9f69ac793a9). Move.accessimmediately after.base = 0in both calls soagx_testsbuilds cleanly under strict C++20 compilers as well as Clang.
Notes:
- Compiler logic in
agx_optimize_nir_late_tail(),agx_compile_shader_nir_once(),sink_common_store_shared(),collect_burst_ifs(), andcollect_binary_tail_ifs()is clean and addresses prior review points.
Evidence
- Head audited:
f9f69ac793a97c9089af1708fca6543af166a778(aurora-silicon/mesa#761) - Native build check (
g++ (GCC) 16.1.1 20260430,-Dbuild-tests=true -Db_ndebug=false,ninja src/asahi/compiler/agx_tests): fails compilation with out-of-order designated initializers;src/asahi/compiler/test/test-flatten-loads.cpp:783-785and:789-791still place.accessafter.write_maskand.align_mul.
In agx_nir_opt_flatten_loads, sink matching terminal store_shared instructions out of single-block if/else diamonds into one store_shared(phi(v_then, v_else), saddr) after the if when both arms compute structurally equivalent pure-ALU shared offsets (intersecting access flags, refusing volatile/atomic stores, and capping same_pure_expr work to a 64-node budget to prevent exponential recursion). Also flatten contiguous runs of >= 4 small single-load divergent ifs in the same CF list (separated only by pure ALU or non-volatile store_shared, reset on barriers or other CF nodes, and excluding load_global_constant so UBO reads stay intact for uniform DMA): - Burst threshold (>= 4): isolated 1-3 divergent loads rarely amortize speculative zero-page redirection when an arm is cold, whereas >= 4 consecutive guarded tile loads remove >= 4 serial load-wait CF barriers so global loads issue back-to-back with overlapped latency and let LICM hoist shared tile-address math. - Per-arm cap (MIN2(limit, 24)): admits a 2D/3D index + byte offset + descriptor setup (~8-16 NIR ops) while keeping speculative untaken ALU bounded across a multi-if burst. Reaches all shader stages under (AGX3B || AGX3C) && !emit_agx3d (AGX3B: G15/G16/G17P/G17A; AGX3C: G17G/G17S / M5). AGX2 and G18G are unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
f9f69ac to
8e2d121
Compare
|
@DjDeveloperr Status of the AGX3 vision stack above #680 as of today, with what each PR still needs. This is one list so you don't get a separate ping on every PR. Stack base. #657 is merged. #680 is retargeted to #761 (this PR). satchlj's CHANGES_REQUESTED at #762. It now conflicts with #761's new head in #801, open items, no reply or push since
#804, open items, no reply or push since
#805 and #920 are approved at head and wait on the stack below them. |
There was a problem hiding this comment.
Verdict: MERGE at 8e2d121 after #758 and its bases land and the integrated check passes.
Checked: The direct delta is confined to the two test call sites. Both designators follow the generated C++ declaration order and share the original volatility value. The author reports GCC 16.1.1 now compiles the affected file and the driver source is byte-identical to the hardware-tested revision.
The initializer order in the two shared-store fixtures is corrected at 8e2d121. Stack order and integrated validation remain. 8e2d12181e18
|
I started carrying the remaining changes onto current The preview also passed 393 Asahi and Poly host tests with one skip and an AArch64 build. This covers the store-sinking part. I’m carrying the sibling tile-load bursts and post-DMA select folding forward separately so their interactions with #681 and #757 can be checked. |
|
The post-DMA select slice now folds the guarded preamble read on J615. With the same saved Edge boot and isolated ICDs, parent preview The broad sibling-burst admission hit an existing occupancy check on the guarded G17P im2col dual-copy shader at 136 GPRs and 768 resident threads. The narrower admission passes that check and the J615 exclusion controls. A hardware workload that exercises the narrowed burst is still due. |
|
Thanks, Dj. I opened #1537 with your terminal shared-store change on current I filed #1535 for sibling burst qualification and #1536 for the post-DMA timing regression. If you want to take either follow-up, feel free to open a PR against current trunk. I’ll keep the stack moving after #1537 lands. |
|
The shared-store continuation is now #1538. It preserves Dj's original sign-off and declines to merge stores whose access qualifiers differ, including the coherent mismatch Satya flagged. The refreshed J615 row and host results are in the replacement. #762's rotated-stencil integration passed its current-trunk comparison and is staged locally on the revised parent. |
|
Thanks, Dj. The terminal shared-store sinking landed via #1538 in |
What
This PR is stacked on #758, which is stacked on #743 and #735. It has two commits:
agx: enable load flattening on AGX3B and fold post-DMA selects. This runsagx_nir_opt_flatten_loadson AGX3B and AGX3C (not AGX3D or AGX2). It marks the binary-tail chunk ifs fromagx_nir_unroll_runtime_loopsas don't-flatten, so the uniform 4/2/1 tail cascades are not flattened into dummy-page loads. When there is no preamble, it runs the standardnir_opt_peephole_selectand cleanup afteragx3_nir_lower_uniform_dma.agx: sink common store_shared and flatten tile-load bursts. If both arms of a single-block if/else end in a matchingstore_sharedwith an equivalent pure-ALU offset, the two stores become one store of a phi after the if. Volatile and atomic stores are refused. Bursts of four or more sibling small single-load divergent ifs are flattened, with a per-arm cap of 24. UBO loads stay out so uniform DMA keeps them.Rebase note for #757: it also edits the
agx3_nir_lower_uniform_dmablock inagx_compile.c. Whichever PR merges second should feed thepeephole_selectprogress intopost_opt_progressand keep thenir->options = original_optionsrestore.Tested
Head
8e2d12181e181ef9b001adab30581eaa4b33d35a. The only change from R3f9f69ac793a9is the designator order in the twonir_store_sharedcalls inFlattenLoadsKeeps.StoreSharedMismatchedOrVolatileNotSunk, from the review. The driver sources are identical to R3, so the R3 hardware rows still apply:With GCC 16.1.1,
test-flatten-loads.cppnow compiles. At R3 it failed with the reported designator-order error. Clang 23-Werrorno longer reports the two-Wreorder-init-listdiagnostics, and only the 41 existing-Wc99-designatordiagnostics remain, the same count as R3.Risk
Two-way on AGX3B (M3, M4, A18 Pro) and AGX3C (M5). Flattening turns divergent single-load ifs into unconditional loads, so a wrong guard would read memory the original branch skipped.
Not yet
aurora-wipat 902bafb on 11-21. At that fork point,test-agx3-vision-opts.cpp:387/389also fails under GCC.aurora-wipreplaced that test in c05f1c4, so a rebased stack drops the error.