Skip to content

agx: keep the constant data of an AGX3 shuffle in a register - #1569

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
fix/agx3-shuffle-constant-data
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
fix/agx3-shuffle-constant-data

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown

What: llama.cpp's conv2d_f32 and conv2d_f16_f32 do not compile on any AGX3 Mac for a kernel two wide and one high: AGX3 binary packer refused shuffle [d32:reg80 s0=16:imm#0 s1=32:reg2]. The optimizer folded a constant into the data operand of a shuffle. AGX3 shuffles read their data from a register; only the lane or delta has an immediate form. agx_optimizer_inline_imm() now leaves that operand alone, as it already does for the reductions and scans. llama.cpp aborts on the failed pipeline, so one such convolution ends the process.

Tested: Local only at 6667929e0f24 (base 76714ec00800), no Mac yet. Assert-enabled x86-64: asahi, poly and vulkan suites 465 ok, 0 failed, 1 skipped, before and after; agx_tests 1973 passed before, 1975 after (the two new tests), 1 skipped. Both new tests fail on the base. The convolution cases of test-backend-ops compile on M3, M4, A18 Pro and M5 profiles.

Risk: two-way door · M3, M4, A18 Pro, M5, M6. Every emitter path already required a register here, so only shaders that were refused can change. AGX2 (M1, M2) is untouched.

Not yet: hardware rows on M4 (J773g) and A18 Pro (J700), and on M5 Pro (J714s): test-backend-ops -o CONV_2D,CONV_2D_DW,CONV_TRANSPOSE_2D against the CPU, plus the compute shuffle, quad and broadcast groups of dEQP-VK.subgroups.

Details
  • Since when: hk,agx: prove uniform compute loop bounds and fold AGX3 bitfield slices #1495 (408af606be8), merged 2026-12-02 13:29 UTC. With the driver built at its first parent 9ad573a9bfdf, all CONV_2D cases of llama.cpp f0c9c91f compile on G16G and G17P; at its merge 9b20f932127 they are refused. The missing guard is older.
  • How it gets there: the shader shuffles KH_idx = (crs % KW) / KW, with KW = 2 that is (x & 1) >> 1. nir_opt_uniform_subgroup() removes a shuffle of a constant, but runs earlier. agx_nir_opt_bitfield_slices() then replaces the value with zero, and the optimizer inlines the zero. Other late passes can do the same, so the guard belongs in the optimizer.
  • Cost: a constant shuffle now costs one immediate move and the shuffle. Removing it would need another nir_opt_uniform_subgroup() after the late passes; not done here.
  • is_shuffle() of agx_lower_divergent_shuffle.c moves to agx_compiler.h as agx_is_shuffle().
  • The new tests: all eight shuffle opcodes at 16 and 32 bits for AGX2, AGX3B, AGX3C and the M6 layer (the data stays in a register on AGX3 and still folds on AGX2, the lane folds everywhere); and the (x & 1) >> 1 shuffle compiled whole for G15S, G16G, G17P, G17S and G18G.
Evidence

Each driver runs on its noop shim. A probe build hashes every compiled binary; base 80a0ac5d0cdd with and without this change (the change is the same commit content; #1567 and #1181 landed since).

llama.cpp f0c9c91f, every pipeline the device creates plus the CONV_2D, CONV_2D_DW, CONV_TRANSPOSE_2D and CONV_3D cases:

chip pipelines refused, base refused, head binaries unchanged changed new
G16G 3,796 16 0 5,289 0 16
G17P 3,818 16 0 5,310 0 16
G17S 2,892 12 0 3,615 0 12

The failing cases all have a 2x1 kernel, and the new binaries are the refused conv2d_f32 and conv2d_f16_f32 pipelines.

Convolution cases (CONV_2D, CONV_2D_DW, CONV_TRANSPOSE_2D) on every profile the shim can submit on:

chip refused, base refused, head binaries unchanged changed
G15S 12 0 222 0
G15C 8 0 166 0
G16G 16 0 262 0
G16S 12 0 223 0
G17P 16 0 281 0
G17S 12 0 220 0
G17D 8 0 162 0
G13X 0 0 228 0
G14G 0 0 272 0

The same cases with the unmodified drivers at 76714ec00800 and 6667929e0f24 on G15S, G16G, G17P and G17S: 12 / 16 / 16 / 12 refused before, 0 after. The M6 profile of the shim rejects submissions, so M6 is covered by the compile test only.

GTA V pipelines:

chip compiled binaries changed
G16G 77,706 0
G17P 77,755 0
G17S 32,686 0
G13S 57,920 0
G18G 11,891 0

Failing on the base, passing with the change:

  • Optimizer.AGX3ShuffleKeepsConstantDataInARegister: shuffle #7, #2 instead of mov_imm and shuffle r, #2, for every opcode and width on AGX3B, AGX3C and the M6 layer.
  • AGX3SubgroupShuffle.LateConstantDataCompiles: refused on all five targets.

The shuffle instructions read their data from a register on AGX3. Only
the lane, or the delta of the relative forms, has an immediate encoding.
agx_optimizer_inline_imm() folded a constant into either source, and the
packer then refused the whole shader:

  AGX3 binary packer refused shuffle [d32:reg80 s0=16:imm#0 s1=32:reg2]

Skip source 0, as the reductions and scans above already do. Every
emitter path required a register there, so no program that compiled
before changes.

nir_opt_uniform_subgroup() removes shuffles of a constant, so it takes
data that becomes constant after its last run. llama.cpp's conv2d_f32
with a 2x1 kernel shuffles (x & 1) >> 1, which
agx_nir_opt_bitfield_slices() replaces with zero, and has not compiled
since that pass was added.

Fixes: 408af60 ("hk,agx: prove uniform compute loop bounds and fold AGX3 bitfield slices")
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 03:50

@RyanTheTide RyanTheTide 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.

The AGX3 guard keeps shuffle data in a register while preserving immediate folding for the lane or delta and preserving AGX2 behavior. The base-failing optimizer cases cover the eight opcodes and both widths, and the full compiler case exercises the late NIR constant. The reported pipeline comparison shows the refused convolutions compiling with unchanged binaries for previously successful cases. Hardware execution remains pending.

@DjDeveloperr

Copy link
Copy Markdown
Author

J714s (M5 Pro, T6050, G17S B1, AGX3C, stock 7.3.0-m5-pr67, boot eca1eecc, SLC ON 16 planes, headless) #1569 6667929e0f24baae4c47f7b53f3b242791236e15 vs base 76714ec008000f6859e87ef8410dcfc59de803e0: PASS (test-backend-ops 3ecc5c6da875 CONV_2D,CONV_2D_DW,CONV_TRANSPOSE_2D: base rc=134 ok=16 refused=1 AGX3 binary packer refused shuffle [d32:reg90 s0=16:imm#0 s1=32:reg2], head twice rc=0 ok=2020/2020 fail=0 refused=0; dEQP-VK 3,900-case caselist.txt 6859d5e1d53a: 1936 Pass / 1964 NS / 0 Fail on both arms, 0 diffs; 0 new GPU/kernel faults; DSOs base e43a8e106e90, head 424d1bc47e3f).

@DjDeveloperr

Copy link
Copy Markdown
Author

J700 (MacBook Neo, A18 Pro, G17P B1) at 6667929e0f24: PASS, with one step the kit couldn't name by itself

Stock Fedora 44 kernel 7.3.0-41 (feature word 0x0000007a2001fc06, soft faults off), zero reboot, userspace only. Base is the merge base 76714ec00800. Both arms are cross-builds with one build configuration, loaded per process; nothing was installed.

Check Result
llama.cpp conv2d on the head, twice rc 0 both times, 2,020 of 2,020 tests pass, 0 failing, 0 pipelines refused
The same on the base, twice aborts both times (rc 134) after 16 cases pass, with 1 pipeline refused: AGX3 binary packer refused shuffle … compute pipeline creation failed for conv2d_f32
Where the base stops the kit's own verdict was INCOMPLETE, because its log ends before it could name the case (buffered output at the abort). The head ran the cases in the same order, and the 16 passing lines are identical in both. The case after them is CONV_2D(… ne_kernel=[2,1,1,1] … f32 …), the 2x1 kernel the PR is about
CTS, the recipe's 3,900 shuffle, quad and broadcast cases 3,900 on both arms: 1,936 Pass, 1,964 NotSupported, 0 differences
Kernel log 0 GPU-side lines in every step, including the base's abort

So the row reaches the bug on the base and the head fixes it.

Not covered: the run-time internal shaders; a conv2d case that fails for another reason (none did); other generations (J714s and J773g are their own rows).

@DjDeveloperr
DjDeveloperr merged commit b94524a into aurora-wip Dec 3, 2026
@DjDeveloperr
DjDeveloperr deleted the fix/agx3-shuffle-constant-data branch December 3, 2026 06:07
@DjDeveloperr

Copy link
Copy Markdown
Author

Merged at 6667929e0f24 onto aurora-wip b8a216b8c877 (landed tree d170ff4677b5, the tree that was tested): x86-64 asserts-on asahi + poly + vulkan suites 465 ok, 0 failed, 1 skipped; agx_tests 1981 passed, 1 skipped, including both new tests; GTA V pipelines base vs head, G17S 32,689 and G17P 77,755 compiled binaries, 0 changed, 0 refused. Rows: J714s and J700 PASS at this head. On the J700 the kit's own verdict was INCOMPLETE because the base's log ends before it names the case; the raw logs show the base stopping after the same 16 cases as the head, with conv2d_f32 refused, and the head's 17th case is the 2x1 f32 kernel. J773g is now a post-merge row.

@DjDeveloperr

Copy link
Copy Markdown
Author

J773g (Mac16,10, T8132, Apple M4 G16G B0, os-fw 27.2 / 26B123) post-merge verification of mesa#1569 at head 6667929e0f24 vs base 76714ec00800: PASS.

Provenance

  • Host / kernel: J773g stock 7.3.0-ARCH-m4main-6c83a2a6, boot_id=72d2ce11-d81c-4956-803d-95328f7a4f7d (zero-reboot, no driver install, MESA_SHADER_CACHE_DISABLE=true).
  • Matched AArch64 cross-builds:
    • base (76714ec00800): libvulkan_asahi.so SHA-256 7a85cedea3c1f20c1e81725dd4eb84c4d22acad1c328ee9787454224a70eb9d8
    • head (6667929e0f24): libvulkan_asahi.so SHA-256 3c6ad6eeae52f54377b072740c5448380320af6ac8916fc080e7f2c60ebcf003
  • CTS: /root/m4cts/cts-vk/deqp-vk SHA-256 d3ef839af652df22ee79e3c9746ff43175feb4776ceb40cce94bbbe339ec3c7f.

1. llama.cpp test-backend-ops (-b Vulkan0 -o CONV_2D,CONV_2D_DW,CONV_TRANSPOSE_2D)

  • conv 1 base: reproduced (rc=134, ok=16 fail=0 refused=1 — hk: CreateComputePipelines refused pipeline 0 of 1: VK_ERROR_UNKNOWN, ggml_vulkan: compute pipeline creation failed for conv2d_f32)
  • conv 2 head: PASS (rc=0, ok=2020 fail=0 refused=0, 2020/2020 tests passed, 2/2 backends passed)
  • conv 3 head: PASS (rc=0, ok=2020 fail=0 refused=0, 2020/2020 tests passed, 2/2 backends passed)

2. CTS (3,900 cases)

  • base: 1,936 Pass, 1,964 NotSupported, 0 Fail
  • head: 1,936 Pass, 1,964 NotSupported, 0 Fail
  • Status differences: 0

GPU health

  • 0 new kernel/GPU fault lines.

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