Repository navigation
agx: keep the constant data of an AGX3 shuffle in a register - #1569
Conversation
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>
RyanTheTide
left a comment
There was a problem hiding this comment.
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.
|
J714s (M5 Pro, T6050, G17S B1, AGX3C, stock |
J700 (MacBook Neo, A18 Pro, G17P B1) at
|
| 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).
|
Merged at |
|
J773g ( Provenance
1.
|
What: llama.cpp's
conv2d_f32andconv2d_f16_f32do 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(base76714ec00800), no Mac yet. Assert-enabled x86-64: asahi, poly and vulkan suites 465 ok, 0 failed, 1 skipped, before and after;agx_tests1973 passed before, 1975 after (the two new tests), 1 skipped. Both new tests fail on the base. The convolution cases oftest-backend-opscompile 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_2Dagainst the CPU, plus the compute shuffle, quad and broadcast groups ofdEQP-VK.subgroups.Details
408af606be8), merged 2026-12-02 13:29 UTC. With the driver built at its first parent9ad573a9bfdf, allCONV_2Dcases of llama.cppf0c9c91fcompile on G16G and G17P; at its merge9b20f932127they are refused. The missing guard is older.KH_idx = (crs % KW) / KW, withKW = 2that 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.nir_opt_uniform_subgroup()after the late passes; not done here.is_shuffle()ofagx_lower_divergent_shuffle.cmoves toagx_compiler.hasagx_is_shuffle().(x & 1) >> 1shuffle 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
80a0ac5d0cddwith 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 theCONV_2D,CONV_2D_DW,CONV_TRANSPOSE_2DandCONV_3Dcases:The failing cases all have a 2x1 kernel, and the new binaries are the refused
conv2d_f32andconv2d_f16_f32pipelines.Convolution cases (
CONV_2D,CONV_2D_DW,CONV_TRANSPOSE_2D) on every profile the shim can submit on:The same cases with the unmodified drivers at
76714ec00800and6667929e0f24on 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:
Failing on the base, passing with the change:
Optimizer.AGX3ShuffleKeepsConstantDataInARegister:shuffle #7, #2instead ofmov_immandshuffle r, #2, for every opcode and width on AGX3B, AGX3C and the M6 layer.AGX3SubgroupShuffle.LateConstantDataCompiles: refused on all five targets.