Repository navigation
agx: hoist compute device loads over independent ALU and barriers on G13 - #1236
joshuaswarren wants to merge 1 commit into
Conversation
Add agx_hoist_loads, a post-schedule compute pass gated by the new AGX_CAP_COMPUTE_HOIST_LOADS capability on the measured G13 rows (G13G, G13X). For non-preamble compute shaders on chips carrying the capability, the pass moves each non-coherent device_load up to 64 instructions earlier, to just after the last producer of its sources. It crosses pure ALU (schedule class none, reorderable and eliminable), threadgroup barriers, workgroup memory loads and stores, other non-coherent device loads, and immediate uniform_store instructions whose 16-halfword window does not overlap any uniform source of the load. It stops at device stores, atomics, memory barriers, coherent loads, image ops, doorbell and other non-pure ops, phis, preloads, and control flow. Adds 10 HoistLoads unit tests in test-hoist-loads.cpp and capability-table coverage in test-chip-caps.c. No new runtime switches or generation gates. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 53926df751cbf8c191aafcb2796b0b8172dc9c46
Blockers:
- Branch is DIRTY against
aurora-wip(tip7617c835): mergeaurora-wipinto the branch (merge, not rebase). Three conflicts, all mechanical:src/asahi/lib/agx_chip_caps.h:173: bit 23 is nowAGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED, 24/25 areFOLD_SHARED_OFFSETS/CDM_DEFER_FLUSH, andAGX_CAPS_G13already exists. Use1u << 26and add the cap to the existingAGX_CAPS_G13.src/asahi/compiler/agx_compile.c:15409:agx_ilp_schedulemoved out of the pressure-schedule block (it now runs underif (!(agx_compiler_debug & AGX_DBG_NOSCHED))after theskip_schedblock). Put theagx_hoist_loadscall after thatagx_ilp_schedule.src/asahi/lib/tests/test-chip-caps.c: keep bothtest_g13_compute_codegen_caps()/test_cdm_defer_flush()andtest_compute_hoist_loads(), and add the new bit toall_caps.
src/asahi/compiler/agx_pressure_schedule.c:2370:hoist_can_cross()lets any non-coherentdevice_loadcrossthreadgroup_barrier. On AGX2,barrier()with device/global memory semantics is emitted asmemory_barrierfollowed bythreadgroup_barrier(agx_compile.cnir_intrinsic_barrier, AGX2 path:agx_memory_barrier(b)thenagx_threadgroup_barrier(b)). The pass stops atmemory_barrierbut crosses the rendezvous, sostore buf[i]; memory_barrier; threadgroup_barrier; x = buf[j]becomesstore; memory_barrier; x = buf[j]; threadgroup_barrier. The load now runs before the other invocations have reached the barrier, so it can read a value they have not stored yet. Only loads that nir_opt_access proved read-only (I->memory_can_reorder, now set on AGX2 too since #1232) may cross the rendezvous; #1232 uses exactly that rule to keep loads in flight across the barrier. Fix: inhoist_can_cross, returnload->memory_can_reorderforAGX_OPCODE_THREADGROUP_BARRIER(or don't cross it at all), and changeAboveAluAndThreadgroupBarrierto build amemory_can_reorderload. Demonstrated with the unit test below: it fails on the head merged into the tip.
Checked: Read the whole diff. Merged the head into aurora-wip 7617c83 with the conflicts resolved as in item 1, then ran the x86 drm-shim gate (meson test --suite asahi --suite poly): 337/338 with the PR's 10 HoistLoads tests passing. The one failure, hk_sync_stamps, fails identically on the tip without this PR. Added one probe test (below), which fails. Legality review: coherent, volatile and atomic loads are excluded via nir_is_coherent (good); device stores, atomics, memory/image barriers, doorbell, stack and control flow stop the walk (good); crossing local_load/local_store and non-overlapping immediate uniform_store is fine; the only unsafe crossing is the workgroup rendezvous in item 2. The cap is a chip-caps table entry, so no NO-GATES issue.
Non-blocking:
- The A/B base (
822cf58723a) predatesAGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED(G13 compute now skips the pressure scheduler that moved loads next to their uses) and #1232. The posted numbers (decode +0.06%/-0.19%, prefill -0.59%/-1.26%) are already neutral to negative, so please re-measure on the merged tip before landing. If there is still no win, the pass may not be worth carrying. - Rows needed again at the new head after the merge (G13X plus G13G; the cap is G13-only, so no other generation is needed).
Evidence
Gate (head merged into 7617c83, conflicts resolved as in blocker 1, plus one probe test):
Summary of Failures:
131/338 asahi - mesa:hk_sync_stamps FAIL (fails identically on the plain tip)
337/338 asahi - mesa:agx_tests FAIL
[ FAILED ] HoistLoads.ReviewProbeNotAboveDeviceScopedRendezvous
Probe test:
TEST_F(HoistLoads, ReviewProbeNotAboveDeviceScopedRendezvous)
{
NEGCASE({
agx_index off = agx_mov_imm(b, AGX_SIZE_32, 4);
agx_index x = agx_mov_imm(b, AGX_SIZE_32, 0xcafe);
agx_device_store(b, x, agx_uniform(0, AGX_SIZE_64), off, AGX_FORMAT_I32,
1, 0, false);
agx_memory_barrier(b);
agx_threadgroup_barrier(b);
agx_index v = load(b, off, false);
agx_unit_test(b, v);
});
}AGX2 barrier lowering on the tip (agx_compile.c, nir_intrinsic_barrier): modes & (nir_var_mem_global | nir_var_image) -> agx_memory_barrier(b); then for execution_scope >= SCOPE_WORKGROUP -> agx_threadgroup_barrier(b).
|
Merge-train note: #1224 ( The part that's unique here is enabling hoisting on G13G/G13X. Could you re-cut this PR on current |
|
Closing: #1224 already landed agx_hoist_loads and test-hoist-loads.cpp behind AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS, #1297 showed enabling hoisting regresses G13G decode, and the standalone G13X rows above are decode-neutral (+0.06% / -0.19%) with a prefill regression (-0.59% / -1.26%). Will open a clean G13X capability PR for the combined AGX_CAP_COMPUTE_SMART_WAITS + AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS pair once measured and CTS-checked on current aurora-wip. |
What
Adds
agx_hoist_loads, a post-schedule compiler pass that hoistscompute-device loads over independent ALU work and barriers inside a
64-instruction window, behind a new
AGX_CAP_COMPUTE_HOIST_LOADScapability. The cap is set on the G13G and G13X chip rows (the dies that
share this load-latency profile).
Ported from the mesa-1 hoist-loads line, where it shipped as part of a
family with address-drag and smart-waits; this PR is the standalone
piece with its own capability gate.
Why
Separates a single scheduling lever so its effect can be measured and
reverted on its own, instead of living only inside the combined family.
Tests
agx_testson the PR head tree: 1650 passed, 1 skipped(
NativeFMA.ExactDyadicOracle, pre-existing skip), including the 10new
HoistLoadsunit tests and the test-chip-capability coverage.Hardware A/B — jw16 (MacBook Pro 16-inch, G13X / t6001)
Same-machine interleaved ABBA, 5 pairs per cell, 3 inner trials per
leg, isolated
MESA_SHADER_CACHE_DIRper arm,/proc/self/mapsICDverification on every leg (
libvulkan_asahi_hoist_base_822cf58723a.sovs
libvulkan_asahi_hoist_cand_53926df751c.so), deferral pinned off.Workload: greedy decode,
mlx-community/Qwen3-4B-Instruct-2507-4bit,gen 64.
Standalone hoisting is decode-neutral at both context sizes on G13X
(+0.06% / −0.19%, inside run-to-run noise) and slightly slower on
prefill (−0.59% / −1.26%). (In the mesa-1 family measurement the
combined lever line read +3.4% decode on G13C; the standalone lever
is not where that gain lives.) This is the first standalone
measurement of the hoist; posted so the cap and pass can land on
their own with honest numbers. The prefill delta is the honest cost
of the extra hoisted loads in flight; if that is a merge blocker the
cap can be narrowed, but the pass is default-on only where the cap
is set.