Skip to content

agx/optimizer: keep out-of-range ASR shift counts in a register on AGX3 - #1279

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
satchlj/agx3-asr-imm-range
Nov 28, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
satchlj/agx3-asr-imm-range

Conversation

@satchlj

@satchlj satchlj commented Nov 28, 2026

Copy link
Copy Markdown
Member

What

Stops agx_optimizer from folding out-of-range MOV_IMM shift counts (0 or >= width) into src[1] of AGX_OPCODE_ASR on AGX3 (AGX3B / AGX3C).

agx3_pack_program() only has immediate ASR encodings for shift counts in [1, 15] (16-bit value) and [1, 31] (32-bit value). Folding imm#0 (or >= width) into src[1] caused the binary packer to refuse the shader (VK_ERROR_UNKNOWN), failing all runnable VK_NV_cooperative_matrix2 matrixmuladd_dequant.*.decode tests on M5. Keeping out-of-range counts in a register routes them to the register-count ASR encoding cleanly.

Also adds Optimizer.Agx3AsrImmediateRange in src/asahi/compiler/test/test-optimizer.cpp.

Tested

Tested at exact HEAD 5071e934c45 on Apple M5 Max (J775c, 40-core G17C B1, Borealis):

  • Unit tests: meson test -C build --suite asahi — 337/337 OK, 0 FAIL (including new Optimizer.Agx3AsrImmediateRange).
  • Vulkan CTS (dEQP-VK.compute.pipeline.cooperative_matrix.khr_r.subgroupscope.matrixmuladd_dequant.*):

Risk

  • Very low: only prevents immediate-folding into AGX_OPCODE_ASR src[1] on AGX3B/AGX3C when the immediate is 0 or > width - 1 (cases that the AGX3 binary packer unconditionally refuses). Valid shifts 1..15 / 1..31 and AGX2 are unchanged.

Not yet

  • Only tested on Apple M5 Max (G17C B1); G17P (AGX3B) hardware row not yet run (covered by unit test agx3b-32-zero / agx3b-32-one).

AGX3B/AGX3C immediate ASR only encodes shift counts in [1, width - 1]
(1..15 for 16-bit values, 1..31 for 32-bit values). Folding a MOV_IMM
of 0 or >= width into src[1] of AGX_OPCODE_ASR caused agx3_pack_program()
to refuse the shader (hitting VK_ERROR_UNKNOWN on cooperative-matrix
matrixmuladd_dequant.*.decode tests).

Keep out-of-range ASR shift counts in their register so AGX3 uses the
register-count ASR encoding, and add Optimizer.Agx3AsrImmediateRange.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj

satchlj commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Verified combined with #1278 (satchlj/borealis-coopmat2-workgroup) on Apple M5 Max (J775c, G17C B1, Borealis Vulkan, libvulkan_asahi.so SHA-256 a31d5c00e3b85e01e11c4a9b8245289c8c2b72915bf858bd68ea1ff06f67c9d8):

  • *subgroupscope*matrixmuladd_dequant*: 24/24 supported Passed (0 Failed, 36 Not supported).
  • *workgroupscope*matrixmuladd_dequant*: 24/24 supported Passed (0 Failed, 36 Not supported).
  • dmesg: 0 GPU/MMU/asahi faults.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 5071e934

Blockers: none.

Checked: no Apple material, no AI attribution, no board/firmware gates (ISA encoding check AGX_ISA_ENCODING_AGX3B || AGX_ISA_ENCODING_AGX3C matching AGX3 binary packer constraints), human Signed-off-by, 16-bit (max_shift = 15) and 32-bit (max_shift = 31) immediate bounds and 0 exclusion, AGX2 unchanged, Optimizer.Agx3AsrImmediateRange unit tests, 337/337 asahi suite, J775c Vulkan CTS subgroupscope.matrixmuladd_dequant.* 0/6 -> 6/6 PASS.

Evidence
  • Inspected src/asahi/compiler/agx_optimizer.c:676-690 and test-optimizer.cpp: prevents immediate inlining into AGX_OPCODE_ASR src[1] on AGX3B/AGX3C when def->imm == 0 || def->imm > max_shift (15 for AGX_SIZE_16, 31 for AGX_SIZE_32), keeping valid [1, width - 1] immediates and AGX2 unchanged.
  • Verified on J775c M5 Max (G17C B1) at exact head 5071e934: 337/337 asahi unit tests, CTS dEQP-VK.compute.pipeline.cooperative_matrix.khr_r.subgroupscope.matrixmuladd_dequant.* improved from 0/6 to 6/6 PASS, 0 GPU faults.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at 5071e934c45e from a different lane plus the author's exact-head hardware row. I plan to land it no earlier than 06:29Z, after a combined A/B regression row on two lab GPU families (M1 Pro G13S + M4 G16G). The App approval doesn't count toward the ruleset, so that merge uses --admin under the 6-point rule. Please post a review here if you want it held.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 5071e934c45e.

  • Review: aurora-silicon-review App APPROVE at this head by NEON-PR-REVIEW (Gemini lane, different model family from the author), with the author's exact-head J775c (M5 Max, G17C) row (non-author).
  • Feature row: the author's exact-head hardware row on this PR.
  • Regression: combined A/B overlay of aurora-wip plus this PR and the other queued PRs, user space, default kernel command line. M1 Pro (G13S, fleet89): 0 status changes. M4 Pro (G16S, fleet89): 0 regressions. The only flips there are 5 synchronization multi_queue timeouts under 4-job load; all 5 pass 3/3 alone on both arms, and the base arm shows the same flake. Each Mac ran 26,595 dEQP-VK + 8,153 dEQP-GLES cases, with 0 GPU firmware crashes, Enforcing, 0 failed units. Evidence traces/gpu/20261128-mergetrain-mesa.
  • --admin under the 6-point rule: the App approval does not count toward the ruleset. Dj was pinged here more than 1 h ago, and no blocking review is open.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants