Repository navigation
agx: Keep reorderable device loads in flight across threadgroup barriers - #1232
Conversation
Read-only non-coherent device loads (memory_can_reorder) write only private registers and cannot race with threadgroup memory. Set memory_can_reorder on AGX2 as well as AGX3 (keeping AGX3 load rematerialization guarded in agx_spill.c) and track per-slot drain_on_tg_barrier in agx_insert_waits() so threadgroup_barrier skips draining slots holding only reorderable device loads until their destination registers are consumed or a memory_barrier/block exit is reached. Add InsertWaits unit tests covering threadgroup_barrier and memory_barrier handling for reorderable and non-reorderable device loads. Signed-off-by: Dante Loi <danteloi1993@gmail.com>
|
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at a4be23e33aed
Blockers: none
Checked:
- Read the whole diff and tried to break the barrier change:
- Only slots that hold nothing but
DEVICE_LOADs withmemory_can_reorderskip the drain atTHREADGROUP_BARRIER. The flag sticks: once any other async op (local load or store, image op, a non-reorderable or coherent device load) lands in the slot, the slot drains. It is cleared only when the slot is waited on.MEMORY_BARRIERstill drains everything. memory_can_reorderrequiresnir_intrinsic_can_reorder(), which rules out volatile loads and needsACCESS_CAN_REORDER(nir_opt_access: nothing in the shader writes that memory), and it also requires!nir_is_coherent(). A load issued before a workgroup barrier that reads memory nobody in the dispatch writes can complete after the barrier without changing the result. Threadgroup memory goes throughLOCAL_LOAD/LOCAL_STORE, which always drain, so shared-memory aliasing cannot reach this path.- Register hazards are unchanged: RAW and WAW on the in-flight destination still wait, and the slot still drains at block end (non-exit blocks and preambles), so nothing stays in flight across a CFG edge.
- The wait pass runs only for
AGX_ISA_ENCODING_AGX2(agx_compile.c:16130), so AGX3 output is unchanged even though AGX3 already set the flag. - The other readers of
memory_can_reorder:agx_pressure_schedule.c:270only acts onIMAGE_LOAD; the load merge at agx_compile.c:13777 ANDs the flag across the merged words; spill remat is now explicitly limited to AGX3 (agx_spill.c:427). So turning the flag on for AGX2 changes nothing else.
- Only slots that hold nothing but
- Head merged into aurora-wip
743fa0d3(clean; none of the touched files changed since your base13400438): local drm-shim gate 338 Ok / 0 Fail. The existing keyless spill/remat tests still pass with the new!ctx->keyguard. - Negative check: with
agx_insert_waits.creverted and the tests kept,InsertWaits.ReorderableDeviceLoadStaysInFlightAcrossThreadgroupBarrierfails (337/1). Non-blocking: the tests setmemory_can_reorderby hand, so nothing covers the agx_compile.c:2456 line that now sets it on AGX2. A NIR-level case (aload_globalwithACCESS_CAN_REORDER, then a barrier, then a use) would pin it, and so would a mixed-slot case (reorderable plus non-reorderable in the same slot). - Rows at this head: present: J316c M1 Max G13X (yours), J316s M1 Pro G13S, J700 G17P and J615 G15G (comment above; the AGX3 rows run unchanged code). Missing: an AGX2 row of another generation (G14G M2 or G13G M1). The change affects every AGX2 chip, and both AGX2 rows so far are G13X. Your own "still to run" double-buffered tiled compute A/B would also show whether this gains anything: the gpubench deltas in the body are all within noise.
To finish: a G14G (or G13G) row at a4be23e33aed with compute.pipeline.*, memory_model.message_passing.*workgroup* and synchronization.basic.*. Then merge.
Evidence
- Gate (head merged into aurora-wip 743fa0d, tree 691e9d2a):
Ok: 338 Fail: 0 - Mutation (agx_insert_waits.c reverted, tests kept):
Ok: 337 Fail: 1,[ FAILED ] InsertWaits.ReorderableDeviceLoadStaysInFlightAcrossThreadgroupBarrier git diff --stat 13400438..743fa0d3 --(the 5 touched files): empty
|
|
…ait slots on G14X Add two AGX2 compute-shader scheduling passes gated via agx_chip_caps on G14X (Apple M2 Pro/Max/Ultra), with no new runtime switches: 1. AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS (1u << 28; agx_hoist_loads in agx_pressure_schedule.c, run after agx_ilp_schedule on AGX2 compute): hoists non-coherent device_loads together with up to 3 pure SSA address-producing predecessors (depth <= 4) up to 64 instructions earlier while maintaining a strictly-earlier SSA dominance invariant. 2. AGX_CAP_COMPUTE_SMART_WAITS (1u << 27; agx_insert_waits_local in agx_insert_waits.c): precomputes per-block first-use positions in a single O(N) backward pass (respecting #1232 reorderable loads across threadgroup barriers) and partitions the two hardware scoreboard slots by first-use distance to eliminate mid-burst AGX_MAX_PENDING=8 slot-0 overflow stalls. Rebased cleanly onto aurora-wip 7617c83 (preserving #1232 drain_on_tg_barrier and #1233 G13X CDM defer flush). Author-Model: google/gemini-4-neon
…ait slots on G14X Add two AGX2 compute-shader scheduling passes gated via agx_chip_caps on G14X (Apple M2 Pro/Max/Ultra), with no new runtime switches: 1. AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS (1u << 28; agx_hoist_loads in agx_pressure_schedule.c, run after agx_ilp_schedule on AGX2 compute): hoists non-coherent device_loads together with up to 3 pure SSA address-producing predecessors (depth <= 4) up to 64 instructions earlier while maintaining a strictly-earlier SSA dominance invariant. 2. AGX_CAP_COMPUTE_SMART_WAITS (1u << 27; agx_insert_waits_local in agx_insert_waits.c): precomputes per-block first-use positions in a single O(N) backward pass (respecting #1232 reorderable loads across threadgroup barriers) and partitions the two hardware scoreboard slots by first-use distance to eliminate mid-burst AGX_MAX_PENDING=8 slot-0 overflow stalls. Rebased cleanly onto aurora-wip 7617c83 (preserving #1232 drain_on_tg_barrier and #1233 G13X CDM defer flush). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Problem
agx_insert_waits_local()unconditionally drains every pending scoreboard slot beforeAGX_OPCODE_THREADGROUP_BARRIER. In tiled compute shaders (GEMM, convolutions, stencils) that prefetch read-only device memory across a workgroup barrier, this forces a full device-load stall before threads even enter the barrier.Change
src/asahi/compiler/agx_compile.c: setload->memory_can_reorderfornir_intrinsic_can_reorder(instr) && !nir_is_coherent(instr)on AGX2 as well as AGX3.src/asahi/compiler/agx_spill.c: guardcan_remat_load()explicitly onagx_isa_is_agx3()so AGX2 spilling behavior is unchanged.src/asahi/compiler/agx_insert_waits.c: trackdrain_on_tg_barrierper scoreboard slot. Slots holding only reorderable read-onlyAGX_OPCODE_DEVICE_LOADs (which write only private registers and cannot race with threadgroup memory) stay in flight acrossAGX_OPCODE_THREADGROUP_BARRIERuntil their destination registers are consumed, aAGX_OPCODE_MEMORY_BARRIERis reached, or the block exits.src/asahi/compiler/test/test-insert-waits.cpp&src/asahi/compiler/meson.build: addInsertWaitsunit tests covering reorderable and non-reorderable device loads acrossTHREADGROUP_BARRIERandMEMORY_BARRIER.Testing
Tested on a 16-inch MacBook Pro M1 Max (J316c, G13X), kernel
7.3.0-ds4-ARCH:origin/aurora-wip13400438325):libvulkan_asahi.sosha256d39ac03363d8a344844f4a0741550018b4b1b94c4f8bb427840a6c75691f15f4agx2-reorderable-loads-across-tg-barriera4be23e33ae):libvulkan_asahi.sosha256b53ceda085bd8b23eee5a124f8e24776386869e0a68c44d41755921de0be3548agx_tests(OK, including all 3 newInsertWaits.*tests).deqp-vk, 0 regressions):dEQP-VK.compute.pipeline.basic.*: 77 Pass, 0 Fail, 3 NotSupporteddEQP-VK.compute.pipeline.workgroup_memory_explicit_layout.*: 2,857 Pass, 0 Fail, 970 NotSupporteddEQP-VK.memory_model.message_passing.core11.u32.coherent.fence_fence.atomicwrite.workgroup.*: 9 Pass, 0 Fail, 16 NotSupportedgpubench-vk alternating A/B (depth 4, 3 pairs x 5 runs, M1 Max J316c)
compute.conv2dcompute.stereocompute.edgecompute.heavycompute.fp16