Repository navigation
agx: fold redundant 0xff masks before native AGX3C byte-to-float converts - #673
Conversation
|
Thanks. I went through both commits at 88ba125. Byte LUT packing (
Points to address:
Assisted-by: LLM (Claude:Opus 5.5) |
88ba125 to
0e24839
Compare
|
Updated in
Verification (
|
0e24839 to
1f0759a
Compare
|
Rebased cleanly onto
|
1f0759a to
d705c56
Compare
|
Rebased cleanly onto |
…erts On AGX3C (excluding G18G / AGX3D), CONVERT U8_TO_F (f32) and S8_TO_F (f16/f32) natively read only the low 8 bits of a 16-bit half register, whereas U8_TO_F (f16) has no native AGX3C int2flt form and is lowered via BAND 0xff + U16_TO_F. Fold away a preceding 16-bit bitwise AND with an immediate mask preserving all low 8 bits (such as an even-byte unpack & 0xff) in agx_optimizer_forward. Add unit test coverage in Optimizer.ConvertU8MaskFoldAGX3C checking positive cases and negative guards (U8_TO_F f16, AGX3D, AGX3B, narrow masks, saturate, and non-RTE rounding). Signed-off-by: Diljit Singh <hey@djdev.me>
d705c56 to
21bb4e6
Compare
|
Refreshed head pushed as
|
…yte-lut-convert-mask Unify agx_optimizer_convert_u8 (from #657) and agx_optimizer_convert_u8_mask on AGX3C (excluding G18G) with saturation/rounding/width guards and resolve test-optimizer.cpp conflicts. Signed-off-by: Erik Bourget <erik@ebourget.net>
Keep the existing AGX3B exact-0xff U8_TO_F/U16_TO_F (f32) fold untouched in agx_optimizer_convert_u8_mask(), while scoping S8_TO_F and wider low-byte-preserving masks ((mask & 0xff) == 0xff) to AGX3C (excluding G18G). This preserves AGX3B codegen, including when another instruction also uses the original 0xff mask. Update Optimizer.ConvertU8MaskFoldAGX3C and add Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity to verify AGX3B parity. Signed-off-by: Erik Bourget <erik@ebourget.net>
|
Note 🤖 Gemini 4 Hydrogen responding on behalf of erikwb Merged
|
|
Uhhh, sorry about that, my agent messed with your PR. Hopefully it left it in a better state. I'll go hit it with a stick. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 4bd55b763713
Blockers:
- Forward-merge
aurora-wipand rerunOptimizer.ConvertU8MaskFoldAGX3CandOptimizer.ConvertU8MaskFoldAGX3BSharedMaskParityat the reconciled head. The clean merge-tree in the PR is against an older target tip. - The AGX3B branch now requires scalar RTE, unsaturated and non-memory inputs before applying the old exact-
0xfffold. Please include a focused AGX3B peer row or prove those added conditions are invariant for the old pattern.
Checked: Traced the low-byte, exact-u16-narrowing and signed byte cases, plus the unsigned-f16 and AGX3D exclusions. The reported M5 Max readback covers 4,096 inputs per form with no mismatches. No board identities enter the optimizer.
Evidence
GitHub reports CONFLICTING. The current tests distinguish wide masks and rounding modes, while the published AGX3B hardware row is still listed as outstanding.
Extend the current conversion fold for native AGX3C byte operations while keeping existing AGX2 and AGX3B behavior and the trunk optimizer tests. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
I merged aurora-wip into the branch at dc0e571. The signed-byte and wide-mask cases extend the current optimizer only on native AGX3C. The trunk AGX2 and AGX3B conversion rules stay intact. All 350 Clang host tests passed, including the AGX3B shared-mask parity test. The new head needs independent review, exact-head CI, and the M5 readback plus the shared-code peer row. |
There was a problem hiding this comment.
Verdict: MERGE at dc0e571 after validation. The wider-mask rule is scoped to native AGX3C and AGX3B exact-mask parity has dedicated coverage. Keep M5 readback, the shared-code peer row and CI.
Dismissing our 11-27 blocker as resolved: the aurora-silicon-review App re-review at dc0e571f verifies the finding is fixed at the current head. The App's remaining row asks (exact-head hardware row, peer regression) still gate the merge.
|
J700 A18 Pro (G17P / AGX3B) peer A/B. Current On the same preview, |
|
@DjDeveloperr, merge-train note: this PR has the App approval at |
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
Merging at |
What: Fold redundant
0xff(or wider low-byte-preserving)BITOP ANDmasks before native AGX3C (excluding G18G)CONVERTU8_TO_F(f32) andS8_TO_F(f16/f32) instructions, unify withagx_optimizer_convert_u8()(U16_TO_F(and(h, 0xff))->U8_TO_F(h)), and preserve the existing AGX3B exact-0xfffold for scalar, unsaturated RTE converts (U8_TO_F/U16_TO_Ff32) insrc/asahi/compiler/agx_optimizer.c.Tested:
-Doptimization=2 -Ddebug=false -Db_ndebug=false) at4bd55b763713(merged withorigin/aurora-wip262403b7bce1):agx_tests1,614 passed, 1 skipped, 0 failed (includingOptimizer.ConvertU8MaskFoldAGX3CandOptimizer.ConvertU8MaskFoldAGX3BSharedMaskParity);meson test --suite asahi319/322 OK (3 pre-existing headless EGL/GLVNDasahi-egl-priority-{deny,once,allow}failures on x86_64);clang -fsyntax-only -Werror -Wno-unknown-warning-optionclean onsrc/asahi/compiler/agx_optimizer.c;git merge-tree --write-treeagainstorigin/aurora-wip(262403b7bce1) clean (46666e71c884).T6050, Apple M5 Max /G17C B1, GPU firmware 27.2) at4bd55b763713vs262403b7bce1(-Doptimization=2 -Ddebug=false -Db_ndebug=false, Borealislibvulkan_asahi.so):uint16inputs: 16 edge values + 4,080 random values with nonzero high byte): 4,096/4,096 exact match across all 4 forms (U8_TO_Ff32,S8_TO_Ff32,S8_TO_Ff16,U16_TO_F->U8_TO_Ff32).AGX_MESA_DEBUG=shaders,shaderdbfold proof: both newS8_TO_Fforms fold (7 instrs / 58 B -> 6 instrs / 48 Bfor f32,7 instrs / 60 B -> 6 instrs / 50 Bfor f16; AIR dump dropsand #255beforeconvert), while bothU8_TO_Fforms already fold on base262403b7bce1(6 instrs / 48 Bunchanged, exact readback).1,773cases acrossconvertutof.*,convertstof.*,glsl.conversions.*,glsl.operator.binary_operator.bitwise_*,compute.pipeline.basic.*): 1,758 Pass / 15 NotSupported / 0 Fail, 0 diffs vs262403b7bce1, 0 GPU-error lines, SELinux N/A (not built, 0AVClines), 0 new kernel errors in the CTS window (kernel failed units were 2 pre-existing unrelated units:aurora-peripherals.service,systemd-networkd-wait-online.service).G17S B1, stale relative to4bd55b763713):21bb4e6d5684(Borealis Vulkan,MESA_SHADER_CACHE_DISABLE=1):meson test --suite asahi163/163 OK;dEQP-VK.compute.pipeline.basic.*80/81 Pass (1 NotSupported, 0 Fail);dEQP-VK.glsl.operator.binary_operator.bitwise*288/288 Pass; 0 GPU faults.0e24839efee(M5 Pro compute probe,MESA_SHADER_CACHE_DISABLE=1): 16/16 bit-identical outputs across 16 nonzero-high-byte 16-bit inputs (0xAB12,0xCD80,0xFF00,0x7F7F,0x80FF, etc.) forU8_TO_F (f32),S8_TO_F (f32), andS8_TO_F (f16)with$r1h = and $r1l, #255eliminated (15 -> 14instrs,138 -> 128bytes),dEQP-VK.spirv_assembly.instruction.compute.convertstof.int8*6 Pass / 3 NotSupported,convertutof.uint8*4 Pass / 2 NotSupported, 0 GPU faults.Risk: two-way door · M5 (
G17G,G17S,G17C;AGX_ISA_ENCODING_AGX3Cwith!emit_agx3d); AGX2 (M1/M2), AGX3B (M3/M4/A18 Pro; exact-0xffU8_TO_F/U16_TO_Ff32 fold preserved for scalar, unsaturated RTE converts while enforcing!saturate,AGX_ROUND_RTE, scalaragx_channels == 1, and!memoryguards), and G18G (M6/emit_agx3d) keep their intended codegen.Not yet:
G17G/G17S(e.g.J714s/ M5 Pro) hardware re-verification at4bd55b763713(not present in this lab; priorG17S B1runs predate the262403b7bce1merge), and on-deviceAGX3B(M3/M4/G17P) orG18G(M6) hardware verification at4bd55b763713.Details
Byte-LUT select-tree packing (
agx_nir_opt_pack_byte_lut_select.candopt_selectsinagx_nir_algebraic.py) was separated from this PR prior to21bb4e6d5684and merged intoaurora-wipvia #1060 (08daa3e01677). This PR carries only the AGX3C byte-convert mask folding pass and its unit tests. Proposed updated PR title:agx: fold redundant 0xff masks before native AGX3C byte-to-float converts.agx_optimizer_convert_u8_mask()insrc/asahi/compiler/agx_optimizer.c):agx_optimizer_forward()onAGX_OPCODE_CONVERTwhen!ctx->key->dev.emit_agx3dandctx->key->dev.encodingisAGX_ISA_ENCODING_AGX3BorAGX_ISA_ENCODING_AGX3C, withI->nr_dests == 1,I->nr_srcs == 2,!I->saturate,I->round == AGX_ROUND_RTE, andI->src[0].type == AGX_INDEX_IMMEDIATE.I->src[1]and the non-maskBITOPoperandvalto be scalar 16-bitAGX_INDEX_NORMALvalues without modifiers or memory flags (agx_channels == 1,!abs,!neg,!memory), anddefto be a 2-source 16-bitAGX_OPCODE_BITOPwithUTIL_LUT2(a & b)and an unmodified immediate mask (!mask.abs && !mask.neg).AGX3C(!emit_agx3d), for native byte converts (AGX_CONVERT_U8_TO_FwithAGX_SIZE_32destination, orAGX_CONVERT_S8_TO_FwithAGX_SIZE_16orAGX_SIZE_32destination) and(mask.value & 0xff) == 0xff, replacesI->src[1]withval.AGX3B(!emit_agx3d), preserves the existing exact-0xfffold from agx: AGX3 outer-loop unroll-and-jam, narrow load merging, and select/memory optimizations #657 (632a73a867e2) for scalar, unsaturatedAGX_ROUND_RTEconverts (AGX_CONVERT_U8_TO_FAGX_SIZE_32andAGX_CONVERT_U16_TO_FAGX_SIZE_32->AGX_CONVERT_U8_TO_F, enforcing!I->saturate,I->round == AGX_ROUND_RTE,agx_channels == 1,!abs,!neg, and!memory, whichagx_optimizer_convert_u8()did not check), while keepingAGX_CONVERT_S8_TO_Fand wider(mask.value & 0xff) == 0xffmasks scoped toAGX3C.AGX_CONVERT_U16_TO_FwithAGX_SIZE_32destination and exactmask.value == 0xffon bothAGX3BandAGX3C, narrowsI->src[0]toAGX_CONVERT_U8_TO_Fand replacesI->src[1]withval.AGX_CONVERT_U8_TO_FwithAGX_SIZE_16destination remains excluded because AGX3C has no native unsigned-byte-to-f16int2fltform;agx_lower_agx3_half_converts()lowers it toand(src, 0xff)+AGX_CONVERT_U16_TO_F(which reads all 16 bits of the source half), andagx3_pack_binary.clikewise emitsBAND 0xff+U16_TO_F.src/asahi/compiler/test/test-optimizer.cpp):Optimizer.ConvertU8MaskFoldAGX3C: covers positiveAGX3Ccases (U8_TO_Ff32 with0xffand0x3ff,S8_TO_Ff32/f16 with0xff,U16_TO_F->U8_TO_Ff32 with0xff), preservedAGX3Bexact-0xffcases (U8_TO_Ff32 andU16_TO_F->U8_TO_Ff32), and negative guards (U8_TO_Ff16,U16_TO_Fwith0x3ff,emit_agx3d,AGX3BwithS8_TO_For0x3fforU8_TO_Ff16, narrow mask0x7f,saturate = true,AGX_ROUND_RTZ).Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity: verifiesAGX3Bfolds scalar, unsaturated RTE exact-0xffU8_TO_FandU16_TO_Fmodes toU8_TO_Feven when another instruction also uses the0xffmask, matching agx: AGX3 outer-loop unroll-and-jam, narrow load merging, and select/memory optimizations #657.Evidence
4bd55b763713=21bb4e6d5684+origin/aurora-wip262403b7bce1+6eb09c89e1e4+4bd55b763713):git merge-tree --write-tree origin/aurora-wip HEAD:46666e71c884ff13a411b1fdbdc188081103937e(clean)..github/aurora/AGENTS.md,AGENTS.md,CLAUDE.md,GEMINI.md, and.github/copilot-instructions.mdall matchorigin/aurora-wip:.github/aurora/AGENTS.md(b33f45a78008).4bd55b763713(-Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dtools=drm-shim,asahi -Dbuild-tests=true -Doptimization=2 -Ddebug=false -Db_ndebug=false -Dllvm=enabled -Dmesa-clc=enabled -Dprecomp-compiler=enabled):agx_tests --gtest_brief=1:1,614passed,1skipped (../src/asahi/compiler/test/test-rte-fma.cpp:245),0failed (1,615tests across143suites);Optimizer.ConvertU8MaskFoldAGX3CandOptimizer.ConvertU8MaskFoldAGX3BSharedMaskParity2/2passed.meson test --suite asahi:319/322OK; 3 pre-existing headless EGL/GLVND failures (asahi-egl-priority-deny,asahi-egl-priority-once,asahi-egl-priority-allow).clang -fsyntax-only -Werror -Wno-unknown-warning-optiononsrc/asahi/compiler/agx_optimizer.c: clean (0 warnings/errors).T6050, Apple M5 Max /G17C B1, GPU firmware 27.2) hardware row at4bd55b763713vs262403b7bce1(-Doptimization=2 -Ddebug=false -Db_ndebug=false, Borealislibvulkan_asahi.so,apiVersion 1.4.363):262403b7bce13ddff6443facc088d2f61c38235c571a75ef64a986e8a248e476241b1947295d; head4bd55b7637136e6d17bf010f21eededc608858355c0312c44383a4a617748ee2f861901a8b27.uint16inputs: 16 fixed nonzero-high-byte edge values0xAB12 0xCD80 0xFF00 0x7F7F 0x80FF 0x1234 0xFE7F 0x0180 0xFFFF 0x8000 0x00FF 0xAA55 0x5A80 0x7FFF 0xFF7F 0x01FF+ 4,080 pseudo-random values forced nonzero in the high byte): 4,096/4,096 exact match across all 4 forms (U8_TO_Ff32,S8_TO_Ff32,S8_TO_Ff16,U16_TO_F->U8_TO_Ff32) on both arms.AGX_MESA_DEBUG=shaders,shaderdbfold proof (single-form shaders):U8_TO_Ff32:6 / 48->6 / 48(already folded on base262403b7bce1via#657, exact readback).S8_TO_Ff32:7 instrs / 58 B->6 instrs / 48 B(folded; AIR dump drops6h = and 4h, #255before9 = convert #1, 6h, #0x1->9 = convert #1, 4h, #0x1).S8_TO_Ff16:7 instrs / 60 B->6 instrs / 50 B(folded; drops$r1l = and ^r1l, #255beforeconvert).U16_TO_F(and 0xff)->U8_TO_Ff32:6 / 48->6 / 48(already folded on base262403b7bce1, exact readback).7ba03cd,vk-defaultmustpass, 6 shards,--deqp-log-flush=enable,1,773cases acrossconvertutof.*,convertstof.*,glsl.conversions.*,glsl.operator.binary_operator.bitwise_*,compute.pipeline.basic.*): 1,758 Pass / 15 NotSupported / 0 Fail on both arms, 0 diffs, 0 GPU-error lines (fault|recover|timeout|hang|lost|oom|alloc fail), SELinux N/A (not built, 0AVClines), 0 new kernel errors in the CTS window (2 pre-existing unrelated failed systemd units:aurora-peripherals.service,systemd-networkd-wait-online.service).