Repository navigation
agx: classify helper/stack ops as barriers and serialize stack_adjust - #951
Conversation
In agx_opcodes.py, doorbell, stack_map, and stack_unmap carried can_reorder = False but left schedule_class at its default (none), and agx_ilp_schedule() only checked schedule_class for ordered memory and barriers on AGX3C. After AGX2 enabled agx_ilp_schedule(), the pure-ALU loop scheduler hoisted get_sr_barrier (helper_op_id) above doorbell(DB_NEXT) in libagx_helper, deadlocking stack/threadgroup allocation requests with continuous GPU timeouts on M1/M2 (reproduced deterministically on Godot 4.7.2 Forward+ and Proton D3D12/Vulkan on J316s G13S). In addition, agx_pressure_schedule.c's instr_mem_space() omitted AGX_OPCODE_STACK_ADJUST from SCHED_MEM_STACK, leaving stack_load and stack_store unordered relative to stack frame adjustment. - Give doorbell, stack_map, and stack_unmap schedule_class = barrier. - Map AGX_OPCODE_STACK_ADJUST to SCHED_MEM_STACK in instr_mem_space(). - Apply the ordered_memory/barrier guard in agx_ilp_schedule()'s pure-ALU loop path uniformly across all Apple GPU generations instead of gating it on AGX3C. - Add unit tests in test-m5-copy-schedule.cpp covering helper doorbell ordering in AGX2 loops and stack_adjust serialization. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 96b3a744cf9f
Blockers: none
Checked: the root cause holds and the fix covers it. create_dag() builds ordering edges from schedule_class alone and ignores can_reorder. So the old doorbell / stack_map / stack_unmap (class none) had no ordering edge against the get_sr_barrier helper-op/arg reads, and any scheduler could move them past those reads. As barrier they now join the full chain. doorbell is only emitted by libagx/helper.cl, so the new class costs nothing in other shaders. Every other pass that reads schedule_class (register cache, M5 word-load window, publication/texture passes, RA) already excluded these ops through can_reorder = False / can_eliminate = False, so nothing else changes. stack_adjust is class store. Before this change it was ordered only against DEVICE-space ops, so stack_load / stack_store could cross it. In SCHED_MEM_STACK it sits in the stack load/store chain. Dropping the AGX3C encoding gate removes a chip gate. The PR merges cleanly into the current aurora-wip (f9b9a5435cf). No PR CI is reported on this branch, so I built and ran the tests myself (results below).
Non-blocking, fine as follow-ups:
test-m5-copy-schedule.cppStackAdjustSerializesStackAccessesstill passes when theAGX_OPCODE_STACK_ADJUSTcase is removed frominstr_mem_space(), so it does not guard that hunk. The block is not a loop and the pressure scheduler keeps the source order here. A test that checks the DAG edge directly, or that gives the scheduler a reason to hoist the store, would catch it.- Removing the gate is not needed for this bug: the barrier class alone keeps the doorbell order, and so does the gate removal alone (mutations below). It is safe, but on AGX2/AGX3B loop ILP is now skipped for any loop block that has a barrier,
get_sr_barrier,stack_adjust, a uniform/state store or a pixel wait/signal, and #927 did not measure that. A before/after on one #927 compute workload (Geekbench compute or the xorshift microbench) on J316s or J413, plus a Neo base fps next to the 39.55 / 55.69 numbers, would show the #927 gain survives.
Evidence
Host build: agx_tests at 96b3a744cf9, built in the aurora/mesa-xbuild-x86 image (release, b_ndebug=false, asahi gallium+vulkan, mesa-clc + precomp).
- Full
agx_testsat head: 1375 passed, 1 skipped (NativeFMA.ExactDyadicOracle), 0 failed.
Mutation runs. Each one rebuilds agx_tests and runs the 2 new tests:
| Mutation | AGX2HelperDoorbellOrderPreserved (order assertion only) |
StackAdjustSerializesStackAccesses |
|---|---|---|
| head | PASS | PASS |
| opcodes.py reverted, scheduler at head | PASS (gate removal alone also skips loop ILP here) | PASS |
opcodes.py + agx_pressure_schedule.c at base 38833c9317b |
FAIL first_sr_pos > doorbell_pos, actual 0 vs 1 |
PASS |
barrier class kept, AGX3C gate restored |
PASS (barrier class alone keeps the order) | PASS |
only case AGX_OPCODE_STACK_ADJUST: removed |
PASS | PASS (mutation not killed) |
The class EXPECT_EQs at the top of the doorbell test catch the opcodes.py revert on their own, so the doorbell test as written does guard the class change.
Ops that now skip AGX2/AGX3B loop ILP (class load/store/atomic/barrier, not in ilp_block_has_memory()) include threadgroup_barrier, memory_barrier*, device_barrier_*, image_barrier_*, get_sr_barrier, stack_adjust, stack_map/unmap, doorbell, wait_pix/signal_pix, tex_state_store, sampler_state_store. The rest are AGX3/M5-only.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 96b3a744cf9f
Blockers: none
Checked:
src/asahi/compiler/agx_opcodes.py:624-631:doorbell,stack_unmap, andstack_mapnow carryschedule_class = "barrier", socreate_dag()serializes them against all memory spaces (SCHED_MEM_DEVICE,SCHED_MEM_LOCAL,SCHED_MEM_STACK),coverage, and other barriers (get_sr_barrier,memory_barrier, etc.) across bothagx_pressure_schedule()andagx_ilp_schedule()(including non-loop compute-load hoisting inlibagx_helper'sOP_STACK_ALLOC/OP_STACK_FREEblocks). Audited all otherschedule_classconsumers (agx_compile.c,agx_opt_licm.c,agx_opt_cse.c,agx_dce.c,agx_optimizer.c,agx_opt_register_cache.c,agx_register_allocate.c,agx_insert_waits.c) with no regressions.src/asahi/compiler/agx_pressure_schedule.c:161-164,1888-1898:AGX_OPCODE_STACK_ADJUST(schedule_class = "store") now maps toSCHED_MEM_STACKininstr_mem_space(), serializing stack frame adjustments withstack_load/stack_storeviamemory_store[SCHED_MEM_STACK]. Removing theAGX_ISA_ENCODING_AGX3Cgate onordered_memoryapplies the pure-ALU loop guard uniformly across all Apple GPU generations (G13–G18) while keeping!ilp_block_has_memory(block)forNONE/COVERAGEtexture and tile ops.agx_chip.his untouched.src/asahi/compiler/test/test-m5-copy-schedule.cpp:782-818:AGX2HelperDoorbellOrderPreserveddirectly reproduces the pre-fixagx_ilp_schedule()inversion (hoistingget_sr_barrierabovedoorbellby critical-path height in an AGX2 loop block) and guards all threeschedule_classassignments.- Policy §1–§6: removes a chip gate (§1), clean production fix (§2–§3), human author/committer + DCO
Signed-off-bywith zero AI attribution across commit/title/body/diff (§4), exact-head96b3a744cf9hardware A/B on J316s (G13S), J413 (G14G), and Neo (G17P) plus hostmeson test --suite asahi258/258 pass andTested:/Risk:lines (§5), clean naming (§6). Mergeable againstaurora-wip(cf5ce9d902c, zero overlapping files with the 80 intervening commits).
Non-blocking notes:
src/asahi/compiler/test/test-m5-copy-schedule.cpp:824-862(StackAdjustSerializesStackAccesses): currently passes even without theAGX_OPCODE_STACK_ADJUSTfix becauseorig_max_pressure == 2causespressure_schedule_block()to bail out (max_pressure >= orig_max_pressure), andagx_ilp_schedule()skips non-loop compute blocks with 0 device/local loads and 0 samples. Adding a second overlappingmov_imm+stack_storebeforestack_adjust(16)(raisingorig_max_pressureto 4 sopressure_schedule_block()actively reschedules down to 2) would make it fail without the fix.src/asahi/compiler/agx_pressure_schedule.c:1474: comment onilp_single_tile_blend()still mentionsDOORBELLas an example ofschedule_class = NONE.
Evidence
- PR head verified live before posting:
96b3a744cf9fd1ebb8b1ba01779cb45af6e35f7f(OPEN, non-draft,MERGEABLEintoaurora-wip@cf5ce9d902c). - CI status: no check runs reported on branch (same across recent
aurora-silicon/mesaPRs); merge gate is review approval. - Hardware A/B at
96b3a744cf9(per PR evidence): J316s G13S and J413 G14G Godot 4.7.2 Forward+ deterministic GPU hangs (41 and 38 timeouts in 15s) resolved to steady passes with 0 new faults andAVC=0; Neo G17P regression pass; hostmeson test --suite asahi258/258 pass.
|
Merged into Verification summary:
|
joshuaswarren
left a comment
There was a problem hiding this comment.
Verdict at 96b3a74: APPROVED.
Blockers
None.
Checked
doorbell,stack_map,stack_unmapnow carryschedule_class = "barrier"inagx_opcodes.py;stack_adjustjoinsSCHED_MEM_STACKininstr_mem_space, so the pressure scheduler creates ordering dependencies between frame alloc/free and the stack accesses between them.- The
m5_ordered_memoryAGX3C-only gate is widened toordered_memoryacross all encodings: any loop block containing a load/store/atomic/barrier-class op now takes the ordered-memory path instead of the pure-ALU ILP scheduling policy. On AGX2 this is what keeps doorbell/get_sr_barrier protocol sequences from being reordered inside loop bodies — the reported deadlock. can_reorder = Falsewas already set on these opcodes but only constrained the earlier scheduling pass, not the ILP loop scheduler — consistent with the hang appearing only under specific loop workloads.- Both regression tests run at
AGX_ISA_ENCODING_AGX2/AGX_CHIP_G13G: one asserts doorbell stays ordered beforeget_sr_barrier, the other asserts strict stack_adjust → stack_store → stack_load → stack_adjust ordering. Both pass on the built tree. - Trade-off: AGX2 loop blocks with any ordered-memory op now skip the aggressive ALU-only ILP policy. Correctness over scheduling freedom; the alternative is a deadlocked queue.
Evidence
- Exact head:
96b3a744cf9fd1ebb8b1ba01779cb45af6e35f7f. - aarch64 cross build with asserts on (
-Db_ndebug=false), clean:libvulkan_asahi.soproduced. - asahi+poly suite on Apple MacBook Pro (14-inch, M2 Max, 2023) / AGX2 G14: 183/183 (178 asahi + 5 poly), includes agx_tests with both new ordering tests.
- GPU stress under the built ICD (
VK_ICD_FILENAMES→ build artifact): Qwen3.8-9B-Distill-mlx-4Bit decode, 256 tokens — completed cleanly, 43.8 tok/s, rc=0. dmesgsweep after the run: no agx faults, GPU timeouts, or resets.
Problem
On
aurora-wip(38833c9317b), native Godot 4.7.2 Forward+ and Proton D3D12/Vulkan apps deadlock the GPU with continuous timeouts on M1 Pro (G13S) and M2 Air (G14G). Bisection pinned this to #927 (ec4746c2006), which enabledagx_ilp_schedule()on AGX2:src/asahi/compiler/agx_opcodes.py,doorbell,stack_map, andstack_unmapsetcan_reorder = Falsebut leftschedule_classat its default (none).src/asahi/compiler/agx_pressure_schedule.c,agx_ilp_schedule()only checkedschedule_classfor ordered memory and barriers onAGX_ISA_ENCODING_AGX3C. On AGX2, the pure-ALU loop scheduler reorderedlibagx_helper's main loop block, hoistingget_sr_barrier(helper_op_id) abovedoorbell(DB_NEXT)and deadlocking hardware stack/threadgroup allocation requests.instr_mem_space()inagx_pressure_schedule.comittedAGX_OPCODE_STACK_ADJUSTfromSCHED_MEM_STACK, leavingstack_loadandstack_storeunordered relative to stack frame adjustment.Change
schedule_class = "barrier"ondoorbell,stack_map, andstack_unmapinsrc/asahi/compiler/agx_opcodes.py.AGX_OPCODE_STACK_ADJUSTtoSCHED_MEM_STACKininstr_mem_space()(src/asahi/compiler/agx_pressure_schedule.c).AGX_ISA_ENCODING_AGX3Cchip gate onordered_memoryinagx_ilp_schedule()so the pure-ALU loop scheduler skips blocks containing any orderedLOAD/STORE/ATOMIC/BARRIERuniformly across all Apple GPU generations.src/asahi/compiler/test/test-m5-copy-schedule.cpp(AGX2HelperDoorbellOrderPreserved,StackAdjustSerializesStackAccesses).Tested: J316s (M1 Pro G13S, fleet87), J413 (M2 Air G14G, fleet87), Neo (J700 A18 Pro G17P, fleet87) at 96b3a74; host
meson test --suite asahi258/258 passRisk: two-way · J316s, J413, Neo, and all Apple GPU generations (restores barrier/stack scheduling order in shared compiler)
Still to run
ordered_memorywas already active onAGX3C, so behavior there is preserved).Exact-head hardware A/B proof (base 38833c9 vs head 96b3a74)
38833c9317bGodot 4.7.2 Forward+96b3a744cf9Godot 4.7.2 Forward+96b3a744cf9Godot 4.7.2 Mobilem1pro)7.3.0-aurora-fleet8759.99 / 60.30 / 59.84 fps, 64/64 px112.32 fps, 64/64 pxworkgroup_memory10/11 (0 fail),arrays.unnamed_parameter30/30 (0 fail); 0 new faults,AVC=0m2)7.3.0-aurora-fleet8735.50 fps, 64/64 px68.68 fps, 64/64 pxj700)7.3.0-aurora-fleet8739.55 fps, 64/64 px55.69 fps, 64/64 pxworkgroup_memory10/11 (0 fail); 0 faultsExact-head binaries tested (rebuilt with matching
asahi_clc/libagx_shaders.h):38833c9317b:sha256:727780af66574b85c84f9040f3b5214a873852e0bfa0315a522f179970b3fcc196b3a744cf9:sha256:d62e9538695194d9578da3f37ab7ad1c0bacab2c12cb7ab344fb0193306323bbHost unit tests:
meson test -C build --suite asahi: 258/258 PASS, 0 Fail (agx_testsincludesM5CopySchedule.AGX2HelperDoorbellOrderPreservedandM5CopySchedule.StackAdjustSerializesStackAccesses).