Repository navigation
agx/compiler: fix ILP scheduler fwd_cap PHI/net-growth accounting and collect in-flight tracking (+8.6% pp512) - #1287
Conversation
… collect in-flight tracking Fix three scheduling accuracy bugs in ilp_schedule_block() that severely hurt cooperative-matrix compute loops (such as llama.cpp mul_mm Q4_0 and Flash Attention): 1. Exclude loop-carried PHI halves from consuming fwd_cap: Loop-header PHIs (e.g. 64 halves of matmad16 accumulators plus loop IVs) are already live on block entry and cannot be reduced by intra-block scheduling. Charging them against AGX_ILP_FS_SAMPLE_HALVES (88 halves) immediately pushed live > fwd_cap before the first real instruction, forcing the scheduler into smallest-destination-first mode and starving wide vec4 device_loads behind scalar ALU and local_stores. 2. Use net register growth (dest halves minus dying SSA source halves) for the fwd_cap fits check and !fits tie-breaker: Counting only destination size made accumulator-updating instructions like matmad16_agx3 (+16 dest, -16 to -32 dying inputs, net <= 0) look like the worst pressure offenders compared to local_loads (+2/+4), starving all matmad16 ops behind every local_load in the block. 3. Treat AGX_OPCODE_COLLECT like AGX_OPCODE_SPLIT for in-flight load consumption: A collect that regroups split channels from hoisted loads does not consume those loads; advancing consumed_loads on collect caused all 32 local_loads in a cooperative-matrix K-tile loop to hoist ahead of all 8 matmad16 instructions and hold both K-halves live across the end-of-tile barrier. On Apple M5 Max (J775c, G17C B1) with llama.cpp Vulkan (Llama-2-7B Q4_0, fa=1, ngl=99, r=3), interleaved ABBA stacked on #1280+#1283+#1284+#1286: - pp512: 2719.53 -> 2951.92 tok/s (+232.39 tok/s / +8.55%) - pp2048: 2578.13 -> 2787.53 tok/s (+209.40 tok/s / +8.12%) - tg128: 109.20 -> 109.20 tok/s (neutral) - tg128 @ d2048: 76.12 -> 76.25 tok/s (+0.17%) - mul_mm Q4_0 drops from 207 GPRs (512 threads) to 168 GPRs (640 threads), overlapping B-matrix device_loads with A dequant and interleaving all 8 matmad16 ops with local_loads; Flash Attention drops 191 -> 175 GPRs (512 -> 576 threads). Signed-off-by: Satya Benson <satya@benson.earth>
|
Code review notes at
|
…cap to live loop PHIs Address review feedback on ilp_schedule_block(): 1. Propagate load_node and collect_def across COLLECT->SPLIT (per-channel when widths/counts match, whole-collect fallback otherwise) and nested COLLECT->COLLECT chains, and resolve collect_def recursively in ilp_mark_consumed_ssa() so in-flight hoist-window slots cannot leak when scheduling runs before agx_opt_collect_split(). 2. Compute eff_fwd_cap after uses_left[] and dies[] (including trailing control flow) are complete, and only add live loop-header PHIs (block->loop_header && (uses_left[v] > 0 || !dies[v])). Dead PHIs and non-loop if/else merge PHIs keep the original fwd_cap brake intact. 3. Add unit tests in test-m5-copy-schedule.cpp for net-growth priority under fwd_cap, COLLECT->SPLIT / nested COLLECT load consumption, and non-loop merge PHI fwd_cap preservation. Signed-off-by: Satya Benson <satya@benson.earth>
|
@AxxzyWasTaken Thanks for the thorough AGX3B/AGX3C review! All three points are addressed in follow-up commit
Exact-head
|
There was a problem hiding this comment.
Verdict: MERGE at bbfd2814
Blockers: none.
Checked: no Apple material, no AI attribution, no chip/board/firmware gates, human Signed-off-by, full diff of src/asahi/compiler/agx_pressure_schedule.c and test-m5-copy-schedule.cpp, loop-header PHI scoping (block->loop_header), net register growth with repeated-source deduplication vs best_dest_grow live tracking, acyclic COLLECT/SPLIT consumption tracking (ilp_mark_consumed_ssa), 337/337 asahi unit tests, CTS compute.pipeline.basic.* 80/80 PASS, J775c ABBA llama-bench (+8.55% pp512, +8.12% pp2048).
Evidence
- Inspected all changes in
src/asahi/compiler/agx_pressure_schedule.c:eff_fwd_capadds only live loop-header PHIs (block->loop_header && (uses_left[v] > 0 || !dies[v])), keeping non-loop merge PHIs under the originalfwd_capbrake (verified byNonLoopMergePhisKeepOriginalFwdCap).- Net register growth (
grow = dest_grow - dying_unique_srcs) deduplicates repeated SSA sources (seen_before,uses_left[v] == occ) forfitsand tie-breaking whilelivestill advances bybest_dest_growbefore per-source decrement. collect_defandilp_mark_consumed_ssa()walk intra-block SSA DAGCOLLECT/SPLITchains accurately (including exact-channelCOLLECT -> SPLITand nestedCOLLECT -> COLLECT) without prematurely advancingconsumed_loads.
- Verified on J775c M5 Max (
G17C B1): 337/337 asahi tests, CTScompute.pipeline.basic.*80/80 PASS, ABBApp512+8.55% /pp2048+8.12% (standalone +9.8%pp512).
|
@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at |
|
Merge-train landing at
Revert: |
… with occupancy headroom
Extend the wide_flat ({8, 6, 4, 2, 1}) in-flight load window selection
in agx_ilp_schedule() to M5 (AGX3C, non-G18G) compute loop bodies when
device_loads > 4 and the block has register headroom inside its current
occupancy step (device_load_cap > peak).
Because windows > 4 remain strictly capped to device_load_cap - peak
(occ_cap), this never crosses an occupancy boundary and falls back
cleanly to {6, 4, 2, 1} when headroom is tight. Straight-line compute
blocks and G18G are unchanged.
In memory-latency-bound quantized GEMV loops (such as llama.cpp
mul_mat_vec Q4_0 / Q6_K with 10-14 device_loads per loop iteration),
widening the in-flight window from 4 to 6/8 overlaps trailing activation
and weight loads with dequantization ALU instead of stalling shortly
before consumption.
On Apple M5 Max (J775c, G17C B1) with llama.cpp Vulkan (Llama-2-7B Q4_0,
fa=1, ngl=99, r=3), interleaved ABBA stacked on aurora-silicon#1280+aurora-silicon#1283+aurora-silicon#1284+aurora-silicon#1286+aurora-silicon#1287:
- tg128: 109.17 -> 111.34 tok/s (+2.17 tok/s / +1.99%)
- tg128 @ d2048: 76.30 -> 77.13 tok/s (+0.83 tok/s / +1.09%)
- pp512: 2953.41 -> 2953.88 tok/s (neutral)
- pp2048: 2785.65 -> 2787.48 tok/s (+0.07%)
Signed-off-by: Satya Benson <satya@benson.earth>
What
Fix three scheduling accuracy bugs in
ilp_schedule_block()(src/asahi/compiler/agx_pressure_schedule.c) that severely hurt cooperative-matrix compute loops such asllama.cppmul_mmQ4_0 and Flash Attention:PHIhalves from consumingfwd_cap:Loop-header
PHIs (e.g. 64 halves ofmatmad16accumulators plus loop induction variables) are already live on block entry and cannot be reduced by intra-block scheduling. Charging them againstAGX_ILP_FS_SAMPLE_HALVES(88 halves) immediately pushedlive > fwd_capbefore the first real instruction, forcing the scheduler into smallest-destination-first fallback and starving widevec4device_loads behind scalar ALU andlocal_stores.fwd_capfitsand!fitsordering:Counting only destination width made accumulator-updating instructions like
matmad16_agx3(+16 dest halves, -16 to -32 dying input halves, net ≤ 0) look like the worst pressure offenders compared tolocal_load(+2/+4), starving all 8matmad16operations behind everylocal_loadin the block.AGX_OPCODE_COLLECTlikeAGX_OPCODE_SPLITinin_flightload-consumption tracking:A
collectthat regroups split channels from hoisted loads does not consume those loads; advancingconsumed_loadsoncollectcaused all 32local_loads in a cooperative-matrix K-tile loop to hoist ahead of all 8matmad16instructions and hold both K-halves live across the end-of-tile barrier.Tested
meson test -C build --suite asahi: 337/337 PASS, including 2 new unit tests intest-m5-copy-schedule.cpp(LoopPhisDoNotStarveWideDeviceLoadHoisting,CollectDoesNotAdvanceInFlightLoadConsumption) verified to fail without the fix and pass with it.J775c,G17C B1) with Borealis:dEQP-VK.compute.pipeline.basic.*: 80/80 PASS (1 Not supported, 0 Failed).llama-benchon Apple M5 Max (J775c,G17C B1),Llama-2-7B Q4_0,fa=1,ngl=99,r=3, stacked on top of agx/compiler: fold cooperative-matrix shared offsets and hoist invariant bases (+14.4% llama.cpp pp512) #1280 + agx/compiler: fold u2u8/i2i8 of 32-bit words into M5 half-register byte-to-float (+1.5% llama.cpp pp512) #1283 + agx/compiler: narrow masked/shifted u16-to-float and fold aligned shifts (+0.9% llama.cpp tg128) #1284 + agx/compiler: narrow M5 byte-dequant bias and f16 scale chains to FP16 (+0.8% llama.cpp pp512) #1286 (separate shader caches per arm):pp512:2719.53 → 2951.92 tok/s(+232.39 tok/s/+8.55%; A:2720.62, 2718.43, B:2951.26, 2952.57)pp2048:2578.13 → 2787.53 tok/s(+209.40 tok/s/+8.12%; A:2579.67, 2576.58, B:2789.52, 2785.53)tg128:109.20 → 109.20 tok/s(neutral; A:109.31, 109.09, B:109.26, 109.14)tg128 @ d2048:76.12 → 76.25 tok/s(+0.17%; A:76.12, 76.12, B:76.26, 76.24)aurora-wip:pp512~2292 → 2517.16 tok/s(+9.8%),pp20482389.51 tok/s.shaderdb/ IR inspection:mul_mmQ4_0 drops from207 GPRs (512 threads)to168 GPRs (640 threads)while overlapping B-matrixdevice_loads with A dequant and interleaving all 8matmad16ops withlocal_loads; Flash Attention drops191 → 175 GPRs(512 → 576 threads).dmesg.Risk
ilp_schedule_block()while preserving the exact finalilp_max_pressure()budget check and all 29 existingM5CopyScheduletests.Not yet
flat_windows) on M5 compute.