Repository navigation
agx: apply the measured compute codegen defaults on G13 (scheduler skip, local-memory immediate fold) - #1133
Conversation
The bottom-up register-pressure scheduler moves each load next to its use, which serializes the memory round trips of small compute kernels. The ILP scheduler still runs, so the kernel keeps its static schedule. Compute shaders therefore skip it unless AGX_MESA_DEBUG=compsched is set; the flag is part of the shared AGX_MESA_DEBUG option so the shader-cache key covers it. Measured on a 13-inch MacBook Pro M1 (G13G): LLM decode +1.4-1.8% tokens/s with bit-identical output; prefill unchanged. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The local load/store index immediate adds 4 elements of the access type per unit. Group the shared accesses of a block that differ only by constants: the member with the lowest real address anchors a shared base, and the other members take their delta in the index immediate with any sub-unit remainder in the address. Deltas are signed 16-bit: shared addressing wraps mod 2^16 but the index-immediate add does not, so folding a raw constant into the immediate can carry a wrapped address out of bounds. The fold applies only while shared_size is at most 32 KiB, where every in-bounds address is below 2^15, the signed 16-bit delta between two real addresses is exact, and base + delta stays under 2^16. AGX_MESA_DEBUG=nolocalfold disables the pass. Measured on a 13-inch MacBook Pro M1 (G13G): +1.8% prefill, bit-exact. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The previous two commits change compute code generation: the shared-memory offset fold and no register-pressure scheduler for compute shaders. Their evidence is from G13 silicon only (13-inch MacBook Pro M1, G13G). Add agx_device_key.g13 and apply both changes only when it is set; other generations keep the existing code paths until they are measured. The gate is a deliberate device gate — a violation of the usual no-gating policy, justified because the codegen trade-offs are measured on exactly one GPU generation and the device key's gpu_generation field is the narrowest available property. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76adbf0fe9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /* Is the target GPU generation 13 (M1 family)? Selects the compute | ||
| * codegen defaults that are measured on G13 only. | ||
| */ | ||
| bool g13; |
There was a problem hiding this comment.
Supply human attribution and sign-off for this commit
The reviewed commit is authored and committed as Codex <codex@openai.com>, has no human Signed-off-by, and includes an Assisted-by: trailer in its commit message. These directly violate the hard attribution rule in AGENTS.md, which requires human-only commit identity and sign-off and places agent disclosure in the PR body rather than commits. Provide a policy-compliant commit before merging.
AGENTS.md reference: AGENTS.md:L50-L50
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Checked the branch commits on GitHub directly (8164551db2a, 65b665c8518, 76adbf0fe9b): all three already have Joshua Warren <816217+joshuaswarren@users.noreply.github.com> as both author and committer, include Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>, and have no Assisted-by: trailer in any commit message (disclosure is in the PR body only). The Codex <codex@openai.com> identity appears to come from the automated review harness synthetic checkout rather than the PR branch commits.
There was a problem hiding this comment.
Re-checked at 51c166b5a452: all three blockers are fixed. No code blockers left.
- Both defaults are now chip-table capabilities (
AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED,AGX_CAP_FOLD_SHARED_OFFSETS) on the G13G and G13X rows throughAGX_CAPS_G13, and thedev.g13key bit is gone. - The
compschedandnolocalfoldswitches are gone. - The
Assisted-by:line is gone. You're right that this repo'sAGENTS.mdasks for that line in the PR body while the policy check refuses it. I've raised the mismatch with the maintainers, so it isn't held against this PR.
Before merge
- Thanks for the exact-head A/B on G13G and G13X and the updated body; both count.
- One thing reaches past G13:
agx_allows_16bit_immediate()now allows a 16-bit immediate index on AGX2 local load/store for every AGX2 chip, not only the two with the new capabilities. So the optimizer can now fold such immediates on G14 as well. The encoding is the same AGX2 form, so I don't see a bug, but G14 behaviour changes. It needs one G14 (M2) row at this head, for exampledEQP-VK.compute.*andssbo/sharedmemory tests, which we'll arrange.
Original review at 76adbf0fe9bc:
Verdict changes needed at 76adbf0fe9bc. Thanks, Joshua. The +1.7% decode result is a good find.
Blockers
- A generation gate in merged code. Both new defaults are keyed on a new
agx_shader_key::dev.g13bit, set fromgpu_generation == 13inagx_device.c. Org code keys behaviour on chip-table capabilities, not chip IDs or generations. Please add two capabilities toagx_chip_caps.h(for the compute-scheduler skip and the shared-offset fold), set them on the G13 rows you measured, and test the cap in the compiler. - New runtime switches.
AGX_MESA_DEBUG=compschedandnolocalfoldexist only to turn the new defaults off. Merged code can't add runtime switches or parameters, so please drop both. The capability is the way to turn one off. - The PR body has an
Assisted-by:line. The PR policy check refuses AI-attribution lines in the title, body and commits, so please remove it.
Checked
agx_ilp_schedulenow runs even when the pressure scheduler is skipped, and onlyNOSCHEDstops both. Other generations are unchanged.- The fold runs before the backend, and DCE follows it.
- Rows: the G13 A/B at the exact head that you list under Not yet is the row needed before merge.
|
Thanks for the review. Removed the One policy question on blocker 3:
Should line 50 be updated to match the PR policy check so the next contributor does not hit the same conflict? Updating the branch now to replace |
Review on the G13 compute codegen series: agx_shader_key::dev.g13 is a generation gate where a capability bit belongs. Replace it with two caps in agx_chip_caps.h, each documented with its evidence: - AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED: compute shaders skip the bottom-up register-pressure scheduler (the ILP scheduler still runs). - AGX_CAP_FOLD_SHARED_OFFSETS: constant deltas between a block's shared-memory accesses fold into the lload/lstore index immediate. Both are set on the measured G13 rows (G13G, G13X); other generations keep the existing paths until they are measured. Also drop the AGX_MESA_DEBUG=compsched and nolocalfold switches: merged code carries no new runtime switches. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
|
Updated head to
Exact-head verification (
|
|
|
…tests Two assert-enabled unit-suite fixes for the G13 compute codegen series: 1. Register AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED and AGX_CAP_FOLD_SHARED_OFFSETS in all_caps in test-chip-caps.c and add a chip-matrix check asserting both bits are set on G13G and G13X only. 2. Check dev.encoding == AGX_ISA_ENCODING_AGX2 alongside AGX_CAP_FOLD_SHARED_OFFSETS and AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED in agx_compile.c. AGX_CHIP_G13G is enum value 0, so synthetic AGX3 unit tests that zero-initialize struct agx_shader_key and set only dev.encoding = AGX_ISA_ENCODING_AGX3B (such as agx3_cmat_mixed_mma8) matched the G13G capability row and ran AGX2 shared-offset folding into AGX3 immediate base operands above 255. Real G13G/G13X hardware always uses AGX_ISA_ENCODING_AGX2, so runtime codegen on all real chips is unchanged. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
|
Thanks for catching both assert-enabled failures on
Because real Re-verified native aarch64 clang release build with
|
|
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 0b10302c9288
Blockers: none
Checked: Read the whole diff. Both behaviours are selected by chip-table capabilities (AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED, AGX_CAP_FOLD_SHARED_OFFSETS) plus the AGX2 encoding, no new switches. Tried to break the shared-offset fold: AGX2 agx_local_immediate_base() still asserts base == 0 on every other path, so the new index-immediate emit only fires for folded accesses; the peel only walks iadd/u2u16/u2u32, all exact mod 2^16; with shared_size <= 32 KiB every in-bounds address is below 2^15, so the int16 deltas are exact, the anchor is the lowest real address and anchor + rest + fold stays below 2^16 (the index immediate does not wrap). Members with different widths get their own unit; the 16-bit immediate limit in agx_pack_local_index() cannot be exceeded. The agx_allows_16bit_immediate() encoding argument keeps the local immediate form off AGX3. Gate below is green for this PR. The G14G J413 row at this head is on the PR (regression only, the caps are off there).
Non-blocking: there is no unit test that pins the fold arithmetic itself (negative deltas, a member with a residual, the 32 KiB cut-off); a small NIR-level test would protect it. The hardware row on G13 at this exact head is still worth having: your M1 Max/M1 rows are at 51c166b5a45 (the follow-up only adds the encoding check, which is always true on G13), and conformance on G13 with the fold active (compute, shared memory) is not shown yet; we will run it on our M1 Pro.
Evidence
Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):
- base
aurora-wip90211df6816: 335/335 OK. - batch build:
90211df6816with 22 open PR heads merged on top (#1133 #1137 #1155 #1136 #1140 #1157 #1158 #1160 #1164 #1165 #1167 #1168 #1170 #1171 #1172 #1175 #1182 #1183 #1185 #1187 #1190 #1191; each also merges cleanly alone, and into currentaurora-wipd2e883ab2e3): 335/336 OK. The one failure,agx3_cmat_mixed_mma8, reproduces with #1187 alone on the base (329/330) and is caused by that PR's new test; nothing else in the batch fails.
|
|
What
Apply the measured M1 compute-codegen defaults via two new chip capabilities in
src/asahi/lib/agx_chip_caps.h, enabled on the measured G13 rows (G13GandG13X), with no generation gate and no new runtime debug switches:AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED: compute shaders skip the bottom-up register-pressure scheduler (which otherwise places each load next to its use and serializes memory round trips in small kernels).agx_ilp_schedulestill runs;AGX_MESA_DEBUG=noschedbehavior is unchanged (still skips every scheduler).AGX_CAP_FOLD_SHARED_OFFSETS: groupslocal_load/local_storein a block that share one constant base, re-anchors the base at the minimum signed 16-bit delta (mod 2^16 arithmetic throughu2u16/u2u32/iadd, so wrapped constants cannot leave the shared window), and puts each member's residual [0, 32767] delta in the hardware index immediate. Skipped whenshared_sizeis 0 or > 32768 (the AGX2 32 KiB local limit), and a group is left alone when no member's residual delta covers a whole index unit. TheLOCAL_LOAD/LOCAL_STOREimmediate form is AGX2-only:agx_allows_16bit_immediatetakes the ISA encoding so the optimizer and validator cannot produce it on AGX3.Both capabilities are set on
G13GandG13XinAGX_CHIP_CAPS; other chips and generations keep their existing paths until measured.Exact-head results (
aurora-wipbabd36d4d47vs51c166b5a45; 5-pair interleaved ABBA, 3 inner trials per leg, isolated per-arm shader cache, identical greedy token IDs per leg, same-machine serialized runs)16-inch MacBook Pro M1 Max (
G13Csilicon,AGX_CHIP_G13X)babd36d4d47)51c166b5a45)f35142981fe6)f35142981fe6)86b9f9ca49f3)86b9f9ca49f3)Environment: 16-inch MacBook Pro M1 Max (
G13Csilicon,AGX_CHIP_G13X), Linux7.1.12, release Vulkan driver builds pinned viaVK_DRIVER_FILES/VK_ICD_FILENAMESand verified in/proc/self/mapson every leg, 0 GPU timeouts, 0 faults.omarchy-mlxC++ GPU suites on51c166b5a45(235/235 passed, 0 GPU timeouts, 0 faults):omarchy_primitive_tests104/104,omarchy_fast_ops_tests45/45,omarchy_runtime_tests50/50,omarchy_reduce_ops_tests36/36.13-inch MacBook Pro M1 (
G13G,AGX_CHIP_G13G)babd36d4d47)51c166b5a45)f35142981fe6)f35142981fe6)Environment: 13-inch MacBook Pro M1 (
G13G), Linux7.3.0, release Vulkan driver builds pinned viaVK_DRIVER_FILES/VK_ICD_FILENAMESand verified in/proc/self/mapson every leg, 0 GPU timeouts, 0 faults.Unit coverage on
51c166b5a45test-chip-capsandagx_tests(with AGX3NativeForms.M5Mesh*local-memory forms pinning the AGX2-only immediate predicate).Risk
Two-way door: gated on two
agx_chip_caps.hcapabilities enabled only on the measuredG13GandG13Xrows for compute shaders. Fragment paths, AGX3, and every other chip keep their existing codegen unchanged. Turning either off for a chip is a one-line row edit inagx_chip_caps.h.Test list
207/207passed, includingtest-chip-caps,agx_tests, andtest-agx3-graphics-compile).omarchy-mlxC++ GPU suites (235/235passed) on 16-inch M1 Max (G13X).G13X) and 13-inch M1 (G13G).Not yet
cdba176bc09(standaloneagx_hoist_loadsdevice-load hoist for compute) is held back deliberately:aurora-wip'sagx_ilp_schedulegrew its own load hoisting (ilp_is_hoisted,hoist_loadsonbb38d56f2c7). Whether a standalone pass still wins on top needs an A/B on this base first, and will be filed separately if it survives.d544e0816e4..ef4219af571) is not in this PR: upstreamed as asahi: dependency-track the per-launch CDM barrier on AGX2 #980, then reverted by Revert "asahi: dependency-track the per-launch CDM barrier on AGX2" #1106 after 6,324 dEQP regressions on M1 Pro. hk: narrow AGX2 CDM barrier word to 0x160 for pure compute SSBO dependencies #1069 reworks the barrier word; this series waits on that redesign.