Skip to content

agx: fold redundant 0xff masks before native AGX3C byte-to-float converts - #673

Merged
RyanTheTide merged 5 commits into
aurora-wipfrom
perf/agx-pack-byte-lut-convert-mask
Dec 1, 2026
Merged

RyanTheTide merged 5 commits into
aurora-wipfrom
perf/agx-pack-byte-lut-convert-mask

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 22, 2026 •

Copy link
Copy Markdown

What: Fold redundant 0xff (or wider low-byte-preserving) BITOP AND masks before native AGX3C (excluding G18G) CONVERT U8_TO_F (f32) and S8_TO_F (f16/f32) instructions, unify with agx_optimizer_convert_u8() (U16_TO_F(and(h, 0xff)) -> U8_TO_F(h)), and preserve the existing AGX3B exact-0xff fold for scalar, unsaturated RTE converts (U8_TO_F / U16_TO_F f32) in src/asahi/compiler/agx_optimizer.c.

Tested:

  • Host x86_64 release (-Doptimization=2 -Ddebug=false -Db_ndebug=false) at 4bd55b763713 (merged with origin/aurora-wip 262403b7bce1): agx_tests 1,614 passed, 1 skipped, 0 failed (including Optimizer.ConvertU8MaskFoldAGX3C and Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity); meson test --suite asahi 319/322 OK (3 pre-existing headless EGL/GLVND asahi-egl-priority-{deny,once,allow} failures on x86_64); clang -fsyntax-only -Werror -Wno-unknown-warning-option clean on src/asahi/compiler/agx_optimizer.c; git merge-tree --write-tree against origin/aurora-wip (262403b7bce1) clean (46666e71c884).
  • J716c (T6050, Apple M5 Max / G17C B1, GPU firmware 27.2) at 4bd55b763713 vs 262403b7bce1 (-Doptimization=2 -Ddebug=false -Db_ndebug=false, Borealis libvulkan_asahi.so):
    • Nonzero-high-byte 16-bit compute readback probe (4,096 uint16 inputs: 16 edge values + 4,080 random values with nonzero high byte): 4,096/4,096 exact match across all 4 forms (U8_TO_F f32, S8_TO_F f32, S8_TO_F f16, U16_TO_F->U8_TO_F f32).
    • Uncached AGX_MESA_DEBUG=shaders,shaderdb fold proof: both new S8_TO_F forms fold (7 instrs / 58 B -> 6 instrs / 48 B for f32, 7 instrs / 60 B -> 6 instrs / 50 B for f16; AIR dump drops and #255 before convert), while both U8_TO_F forms already fold on base 262403b7bce1 (6 instrs / 48 B unchanged, exact readback).
    • Borealis Vulkan CTS (1,773 cases across convertutof.*, convertstof.*, glsl.conversions.*, glsl.operator.binary_operator.bitwise_*, compute.pipeline.basic.*): 1,758 Pass / 15 NotSupported / 0 Fail, 0 diffs vs 262403b7bce1, 0 GPU-error lines, SELinux N/A (not built, 0 AVC lines), 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).
  • Prior pre-merge runs (M5 Pro, G17S B1, stale relative to 4bd55b763713):
    • At 21bb4e6d5684 (Borealis Vulkan, MESA_SHADER_CACHE_DISABLE=1): meson test --suite asahi 163/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.
    • At 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.) for U8_TO_F (f32), S8_TO_F (f32), and S8_TO_F (f16) with $r1h = and $r1l, #255 eliminated (15 -> 14 instrs, 138 -> 128 bytes), 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_AGX3C with !emit_agx3d); AGX2 (M1/M2), AGX3B (M3/M4/A18 Pro; exact-0xff U8_TO_F/U16_TO_F f32 fold preserved for scalar, unsaturated RTE converts while enforcing !saturate, AGX_ROUND_RTE, scalar agx_channels == 1, and !memory guards), and G18G (M6 / emit_agx3d) keep their intended codegen.

Not yet: G17G / G17S (e.g. J714s / M5 Pro) hardware re-verification at 4bd55b763713 (not present in this lab; prior G17S B1 runs predate the 262403b7bce1 merge), and on-device AGX3B (M3 / M4 / G17P) or G18G (M6) hardware verification at 4bd55b763713.

Details

Byte-LUT select-tree packing (agx_nir_opt_pack_byte_lut_select.c and opt_selects in agx_nir_algebraic.py) was separated from this PR prior to 21bb4e6d5684 and merged into aurora-wip via #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.

  • Unified pass (agx_optimizer_convert_u8_mask() in src/asahi/compiler/agx_optimizer.c):
    • Runs in agx_optimizer_forward() on AGX_OPCODE_CONVERT when !ctx->key->dev.emit_agx3d and ctx->key->dev.encoding is AGX_ISA_ENCODING_AGX3B or AGX_ISA_ENCODING_AGX3C, with I->nr_dests == 1, I->nr_srcs == 2, !I->saturate, I->round == AGX_ROUND_RTE, and I->src[0].type == AGX_INDEX_IMMEDIATE.
    • Requires I->src[1] and the non-mask BITOP operand val to be scalar 16-bit AGX_INDEX_NORMAL values without modifiers or memory flags (agx_channels == 1, !abs, !neg, !memory), and def to be a 2-source 16-bit AGX_OPCODE_BITOP with UTIL_LUT2(a & b) and an unmodified immediate mask (!mask.abs && !mask.neg).
    • On AGX3C (!emit_agx3d), for native byte converts (AGX_CONVERT_U8_TO_F with AGX_SIZE_32 destination, or AGX_CONVERT_S8_TO_F with AGX_SIZE_16 or AGX_SIZE_32 destination) and (mask.value & 0xff) == 0xff, replaces I->src[1] with val.
    • On AGX3B (!emit_agx3d), preserves the existing exact-0xff fold from agx: AGX3 outer-loop unroll-and-jam, narrow load merging, and select/memory optimizations #657 (632a73a867e2) for scalar, unsaturated AGX_ROUND_RTE converts (AGX_CONVERT_U8_TO_F AGX_SIZE_32 and AGX_CONVERT_U16_TO_F AGX_SIZE_32 -> AGX_CONVERT_U8_TO_F, enforcing !I->saturate, I->round == AGX_ROUND_RTE, agx_channels == 1, !abs, !neg, and !memory, which agx_optimizer_convert_u8() did not check), while keeping AGX_CONVERT_S8_TO_F and wider (mask.value & 0xff) == 0xff masks scoped to AGX3C.
    • For AGX_CONVERT_U16_TO_F with AGX_SIZE_32 destination and exact mask.value == 0xff on both AGX3B and AGX3C, narrows I->src[0] to AGX_CONVERT_U8_TO_F and replaces I->src[1] with val.
    • AGX_CONVERT_U8_TO_F with AGX_SIZE_16 destination remains excluded because AGX3C has no native unsigned-byte-to-f16 int2flt form; agx_lower_agx3_half_converts() lowers it to and(src, 0xff) + AGX_CONVERT_U16_TO_F (which reads all 16 bits of the source half), and agx3_pack_binary.c likewise emits BAND 0xff + U16_TO_F.
  • Unit tests (src/asahi/compiler/test/test-optimizer.cpp):
    • Optimizer.ConvertU8MaskFoldAGX3C: covers positive AGX3C cases (U8_TO_F f32 with 0xff and 0x3ff, S8_TO_F f32/f16 with 0xff, U16_TO_F -> U8_TO_F f32 with 0xff), preserved AGX3B exact-0xff cases (U8_TO_F f32 and U16_TO_F -> U8_TO_F f32), and negative guards (U8_TO_F f16, U16_TO_F with 0x3ff, emit_agx3d, AGX3B with S8_TO_F or 0x3ff or U8_TO_F f16, narrow mask 0x7f, saturate = true, AGX_ROUND_RTZ).
    • Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity: verifies AGX3B folds scalar, unsaturated RTE exact-0xff U8_TO_F and U16_TO_F modes to U8_TO_F even when another instruction also uses the 0xff mask, matching agx: AGX3 outer-loop unroll-and-jam, narrow load merging, and select/memory optimizations #657.
Evidence
  • Merge & tree checks (4bd55b763713 = 21bb4e6d5684 + origin/aurora-wip 262403b7bce1 + 6eb09c89e1e4 + 4bd55b763713):
    • git merge-tree --write-tree origin/aurora-wip HEAD: 46666e71c884ff13a411b1fdbdc188081103937e (clean).
    • Policy copy check: .github/aurora/AGENTS.md, AGENTS.md, CLAUDE.md, GEMINI.md, and .github/copilot-instructions.md all match origin/aurora-wip:.github/aurora/AGENTS.md (b33f45a78008).
  • Host x86_64 release build & tests at 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,614 passed, 1 skipped (../src/asahi/compiler/test/test-rte-fma.cpp:245), 0 failed (1,615 tests across 143 suites); Optimizer.ConvertU8MaskFoldAGX3C and Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity 2/2 passed.
    • meson test --suite asahi: 319/322 OK; 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-option on src/asahi/compiler/agx_optimizer.c: clean (0 warnings/errors).
  • J716c (T6050, Apple M5 Max / G17C B1, GPU firmware 27.2) hardware row at 4bd55b763713 vs 262403b7bce1 (-Doptimization=2 -Ddebug=false -Db_ndebug=false, Borealis libvulkan_asahi.so, apiVersion 1.4.363):
    • Driver SHA-256: base 262403b7bce1 3ddff6443facc088d2f61c38235c571a75ef64a986e8a248e476241b1947295d; head 4bd55b763713 6e6d17bf010f21eededc608858355c0312c44383a4a617748ee2f861901a8b27.
    • Compute readback probe (4,096 uint16 inputs: 16 fixed nonzero-high-byte edge values 0xAB12 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_F f32, S8_TO_F f32, S8_TO_F f16, U16_TO_F->U8_TO_F f32) on both arms.
    • Uncached AGX_MESA_DEBUG=shaders,shaderdb fold proof (single-form shaders):
      • U8_TO_F f32: 6 / 48 -> 6 / 48 (already folded on base 262403b7bce1 via #657, exact readback).
      • S8_TO_F f32: 7 instrs / 58 B -> 6 instrs / 48 B (folded; AIR dump drops 6h = and 4h, #255 before 9 = convert #1, 6h, #0x1 -> 9 = convert #1, 4h, #0x1).
      • S8_TO_F f16: 7 instrs / 60 B -> 6 instrs / 50 B (folded; drops $r1l = and ^r1l, #255 before convert).
      • U16_TO_F(and 0xff) -> U8_TO_F f32: 6 / 48 -> 6 / 48 (already folded on base 262403b7bce1, exact readback).
    • Borealis Vulkan CTS (7ba03cd, vk-default mustpass, 6 shards, --deqp-log-flush=enable, 1,773 cases across convertutof.*, 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, 0 AVC lines), 0 new kernel errors in the CTS window (2 pre-existing unrelated failed systemd units: aurora-peripherals.service, systemd-networkd-wait-online.service).

@RyanTheTide

Copy link
Copy Markdown

Thanks. I went through both commits at 88ba125.

Byte LUT packing (agx_nir_opt_pack_byte_lut_select.c): I could not find a miscompile.

  • eval_tree evaluates the actual tree for every index in [0, n-1] (:251-267, eval_cmp :146-163), so shape, signedness and leaf order are proven, not assumed.
  • proven_index_max (:45-91) gives a true bound for every input.
  • The x & 3 shortcut at :425-436 is exact when the mask has both low bits set. I checked the emitted word-select plus extract against a reference LUT for all accepted bound forms, including indices far above n, and got no mismatches.
  • Leaf invariance, dominance of the preheader and the internal-use check (:336-354) look right.

Points to address:

  • Mask fold before CONVERT (agx_optimizer.c:1793-1836):
    • Correctness depends on U8_TO_F (f32) and S8_TO_F (f16/f32) ignoring bits [15:8] of the source half on AGX3C. Nothing in the PR shows that on hardware. The CTS groups listed feed canonical bytes or 32-bit values, the PR says the fold rarely triggers without agx: AGX3 outer-loop unroll-and-jam, narrow load merging, and select/memory optimizations #657, and ConvertU8MaskFoldAGX3C checks IR shape only.
    • Could you add an M5 run at this head of a shader that converts x & 0xff where x is a 16-bit value with a nonzero high byte (e.g. 0xAB12 -> 18.0), for each folded mode and destination size?
    • Please also say why U8_TO_F with an f16 destination is excluded while S8_TO_F f16 is folded (:1808-1810). If the f16 form reads the whole half, that needs to be written down next to the fold.
  • agx_nir_algebraic.py:163: agx_nir_fuse_selects runs inside agx_optimize_nir, after nir_lower_bit_size has turned 8-bit ALU into 16-bit. This rule creates new 8-bit bcsels at that point, on every chip.
    • It emits fine today (16-bit icmpsel on zero-extended halves), but it is a new IR shape for the G13/G14 and AGX3B backends, and it fires on any select of two zero-extended bytes, not just LUT trees.
    • The "only fast_corners changed" result is from the M5 Geekbench shader set. Rows from an AGX2 Mac (M1/M2) and an AGX3B Mac (M3/M4/A18 Pro) at this head are needed: agx_tests, the fast_corners workload, and the int8 / 8bit_storage CTS groups. Alternatively, run the hoists before bit-size lowering.
  • The pack pass is placed after agx_nir_lower_algebraic_late and the ubfe fusion (agx_compile.c:10648), so the (w >> s) & 0xff extract it emits is not fused. It is correct because the shift is at most 24, but it misses the bfe form.
  • The u2u32 hoist rules (agx_nir_algebraic.py:163-166) have no is_used_once. When the extended value has other uses, the rewrite adds an instruction.
  • Tests (test-pack-byte-lut-select.cpp): they cover only ult trees built in leaf order, with the index equal to k. It would be worth adding:
    • ilt/ieq/swapped-operand trees
    • a 16-bit tree
    • iand-masked leaves
    • ubfe/ushr bounds
    • an index input above n through the iand bound, which exercises the low-2-bit shortcut.
  • Both commits carry an Assisted-by: trailer. That line belongs in the PR description, not in the commit messages.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr
DjDeveloperr force-pushed the perf/agx-pack-byte-lut-convert-mask branch from 88ba125 to 0e24839 Compare November 22, 2026 10:33
@DjDeveloperr

Copy link
Copy Markdown
Author

Updated in 0e24839efee (6bdee9a276f + 0e24839efee) to address all review points:

  1. No new 8-bit bcsels & single-use guard in agx_nir_algebraic.py: Removed the @8 u2u32 hoist from opt_selects so agx_nir_fuse_selects never creates new 8-bit bcsels after nir_lower_bit_size on any AGX generation (agx_nir_opt_pack_byte_lut_select already matches u2u32(@8) leaves directly), and added (is_used_once) to the @16 u2u32 hoist.
  2. Direct nir_ubitfield_extract emission: Updated agx_nir_opt_pack_byte_lut_select.c to emit nir_ubitfield_extract(&b, word, shift, nir_imm_int(&b, 8)) directly instead of (word >> shift) & 0xff, so codegen emits native agx_bfeil even though the pass runs after agx_nir_fuse_algebraic_late. Confirmed native bfeil #0, ^r11, ^r9, #0x8 emission and bit-exact execution on M5 Pro in a 16-entry per-thread byte-LUT compute probe (gprs 34 -> 31).
  3. Expanded unit test coverage (test-pack-byte-lut-select.cpp): Added CoversCmpKindsWidthsMasksBoundsAndHighIndexBits (ilt, ieq, swapped comparands, 16-bit select tree, iand-masked leaves, ubfe/ushr/iand bounds, high index bits above n through iand bound, and asserts nir_op_ubitfield_extract is emitted) and FuseSelectsRespectsSingleUseAndAvoids8BitBcsel.
  4. Documented U8_TO_F (f16) exclusion in agx_optimizer.c: Explained why U8_TO_F (f16) stays excluded while U8_TO_F (f32) and S8_TO_F (f16/f32) fold (AGX3C has no native unsigned-byte-to-f16 int2flt form, so agx_lower_agx3_half_converts() lowers it to BAND 0xff + U16_TO_F).
  5. M5 Pro hardware proof for agx_optimizer_convert_u8_mask: Ran a Vulkan compute probe (MESA_SHADER_CACHE_DISABLE=1) on M5 Pro (G17S) across 16 nonzero-high-byte 16-bit inputs (0xAB12, 0xCD80, 0xFF00, 0x7F7F, 0x80FF, etc.) converting via U8_TO_F (f32), S8_TO_F (f32), and S8_TO_F (f16). Confirmed agx_optimizer_forward eliminated $r1h = and $r1l, #255 (15 -> 14 instrs, 138 -> 128 bytes), feeding unmasked $r1l directly into all three native converts with 16/16 bit-identical outputs (0xAB12 -> 18.0f / 18.0f / 18.0h, 0xCD80 -> 128.0f / -128.0f / -128.0h, 0x80FF -> 255.0f / -1.0f / -1.0h).
  6. Trailers: Dropped Assisted-by: from both commit messages (kept in PR description only).

Verification (0e24839efee, MESA_SHADER_CACHE_DISABLE=1)

  • meson test --suite asahi: 155/155 PASS (including agx_tests with all new LUT/fuse-selects/optimizer tests)
  • M5 Pro byte-to-float mask-folding hardware probe (nonzero high bytes, U8_TO_F f32 + S8_TO_F f32 + S8_TO_F f16): 16/16 bit-identical (-1 and 0xff instr)
  • M5 Pro 16-entry byte-LUT packing hardware probe (native bfeil): 16/16 bit-identical (gprs 34 -> 31)
  • dEQP-VK.spirv_assembly.instruction.compute.convertstof.int8*: 6/6 PASS (3 NotSupported)
  • dEQP-VK.spirv_assembly.instruction.compute.convertutof.uint8*: 4/4 PASS (2 NotSupported)
  • DEFAULT_BRANCH=aurora-wip bash .github/aurora/agent-policy.sh pr HEAD: clean; 0 GPU faults.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr
DjDeveloperr force-pushed the perf/agx-pack-byte-lut-convert-mask branch from 0e24839 to 1f0759a Compare November 22, 2026 14:18
@DjDeveloperr

Copy link
Copy Markdown
Author

Rebased cleanly onto origin/aurora-wip (c90b9140c855, post-#702 / #601) at 1f0759ae1474 (MERGEABLE).

  • Resolved end-of-file test conflict in src/asahi/compiler/test/test-optimizer.cpp alongside agx: keep f16 GPR sources native in unmodified AGX3B F32 FFMA #702.
  • Exact-head M5 Pro (G17S B1, -Dbuildtype=release -Db_ndebug=true, MESA_SHADER_CACHE_DISABLE=1): meson test --suite asahi 155/155 PASS (agx_tests 1,227/1,227 passed, 1 skipped, 0 fail); gb-gaussian checked 12/12 PASS (0 fail); 0 new dmesg GPU faults; agent-policy.sh pr PASS.

@DjDeveloperr
DjDeveloperr force-pushed the perf/agx-pack-byte-lut-convert-mask branch from 1f0759a to d705c56 Compare November 22, 2026 19:47
@DjDeveloperr

Copy link
Copy Markdown
Author

Rebased cleanly onto origin/aurora-wip (8b8db5b137c6) at d705c5645fb8 (80b9d17d7147 -> d705c5645fb8). Verified on M5 Pro (G17S): meson test --suite asahi 161/161 PASS, gb-gaussian (gaussian-horizontal-small + gaussian-horizontal-32x16) checked PASS, 0 GPU faults.

…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>
@DjDeveloperr
DjDeveloperr force-pushed the perf/agx-pack-byte-lut-convert-mask branch from d705c56 to 21bb4e6 Compare November 23, 2026 03:47
@DjDeveloperr

Copy link
Copy Markdown
Author

Refreshed head pushed as 21bb4e6d5684 (b8b79e1fcff8 + pr673-rebased.patch), verified on Apple M5 Pro (G17S B1):

  • Environment: Linux 7.3.0-m5-n1keep-r3, MESA_SHADER_CACHE_DISABLE=1, no ASAHI_M5_BRINGUP.
  • Unit tests (meson test --suite asahi): 163/163 OK.
  • Vulkan CTS (exact head):
    • dEQP-VK.compute.pipeline.basic.*: 80/81 Pass (1 Not supported, 0 Fail)
    • dEQP-VK.glsl.operator.binary_operator.bitwise*: 288/288 Pass (100%) (0 Fail)
  • GPU faults: 0 new dmesg GPU faults.
  • Mirror asahi CI: 45096145350 (PASS).

…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>
@erikwb
erikwb requested a review from a team as a code owner November 26, 2026 02:17
@erikwb
erikwb requested a review from LiamRay11 November 26, 2026 02:17
@erikwb erikwb changed the title agx: pack loop-invariant byte LUT select trees and fold redundant byte-convert masks agx: fold redundant 0xff masks before native AGX3C byte-to-float converts Nov 26, 2026
@erikwb

erikwb commented Nov 26, 2026

Copy link
Copy Markdown

Note

🤖 Gemini 4 Hydrogen responding on behalf of erikwb

Merged origin/aurora-wip (262403b7bce1) into perf/agx-pack-byte-lut-convert-mask (21bb4e6d5684 -> 6eb09c89e1e4) and pushed follow-up 4bd55b763713 to resolve the src/asahi/compiler/test/test-optimizer.cpp merge conflict, unify with agx_optimizer_convert_u8() from #657 (632a73a867e2), and preserve existing AGX3B exact-0xff codegen for scalar, unsaturated RTE converts.

  • Unification & AGX3B parity in src/asahi/compiler/agx_optimizer.c: agx_optimizer_convert_u8() (from 632a73a867e2) ran on agx_isa_is_agx3 (both AGX3B and AGX3C, !emit_agx3d) for U8_TO_F and U16_TO_F (f32) with exact 0xff masks, without !I->saturate, I->round == AGX_ROUND_RTE, agx_channels == 1, or !memory checks. agx_optimizer_convert_u8_mask() now preserves the exact-0xff U8_TO_F/U16_TO_F (f32) -> U8_TO_F fold on AGX3B for scalar, unsaturated RTE converts (including when another instruction shares the 0xff mask), enforces !I->saturate, I->round == AGX_ROUND_RTE, scalar agx_channels == 1, and !abs / !neg / !memory guards across both AGX3B and AGX3C, and scopes the new S8_TO_F (f16/f32) and wider (mask.value & 0xff) == 0xff masks exclusively to AGX3C (!emit_agx3d). Updated Optimizer.ConvertU8MaskFoldAGX3C and added Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity to verify AGX3B parity.
  • Host verification at 4bd55b763713: agx_tests 1,614/1,615 passed (1 skipped, 0 failed, including Optimizer.ConvertU8MaskFoldAGX3C and Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity), meson test --suite asahi 319/322 OK (the 3 asahi-egl-priority-{deny,once,allow} failures are pre-existing headless EGL/GLVND failures on x86_64), clang -fsyntax-only -Werror -Wno-unknown-warning-option on src/asahi/compiler/agx_optimizer.c is clean, and git merge-tree --write-tree against origin/aurora-wip (262403b7bce1) is clean (46666e71c884).
  • J716c (M5 Max / G17C B1, GPU firmware 27.2) hardware verification at 4bd55b763713 vs 262403b7bce1:
    • Nonzero-high-byte 16-bit compute readback probe (4,096 uint16 inputs: 16 edge values + 4,080 random values with nonzero high byte): 4,096/4,096 exact match across all 4 forms (U8_TO_F f32, S8_TO_F f32, S8_TO_F f16, U16_TO_F->U8_TO_F f32).
    • Uncached AGX_MESA_DEBUG=shaders,shaderdb fold proof: both new S8_TO_F forms fold (7 instrs / 58 B -> 6 instrs / 48 B for f32, 7 instrs / 60 B -> 6 instrs / 50 B for f16; AIR dump drops and #255 before convert), while both U8_TO_F forms already fold on base 262403b7bce1 (6 instrs / 48 B unchanged, exact readback).
    • Borealis Vulkan CTS (1,773 cases across convertutof.*, convertstof.*, glsl.conversions.*, glsl.operator.binary_operator.bitwise_*, compute.pipeline.basic.*): 1,758 Pass / 15 NotSupported / 0 Fail, 0 diffs vs 262403b7bce1, 0 GPU-error lines, SELinux N/A (not built, 0 AVC lines), 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).
  • PR scope & remaining hardware: Byte-LUT select-tree packing already landed in agx3: optimize byte LUT selects, nested read-only loops, direct-body LICM, and AGX3C uniform atomics #1060 (08daa3e01677) and was separated prior to 21bb4e6d5684, so this PR now covers only the byte-convert mask fold. Proposed PR title: agx: fold redundant 0xff masks before native AGX3C byte-to-float converts. J716c verification at 4bd55b763713 is now complete; G17G / G17S (J714s / M5 Pro) and on-device AGX3B (M3 / M4 / G17P) / G18G (M6) hardware verification at 4bd55b763713 remain untested.

@erikwb

erikwb commented Nov 26, 2026

Copy link
Copy Markdown

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

Verdict: FINISH, then merge at 4bd55b763713

Blockers:

  1. Forward-merge aurora-wip and rerun Optimizer.ConvertU8MaskFoldAGX3C and Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity at the reconciled head. The clean merge-tree in the PR is against an older target tip.
  2. The AGX3B branch now requires scalar RTE, unsaturated and non-memory inputs before applying the old exact-0xff fold. 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>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 29, 2026 00:48
@RyanTheTide
RyanTheTide requested a review from maralcbr November 29, 2026 00:48
@RyanTheTide

Copy link
Copy Markdown

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.

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

@RyanTheTide
RyanTheTide dismissed their stale review November 29, 2026 00:54

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.

@RyanTheTide

Copy link
Copy Markdown

J700 A18 Pro (G17P / AGX3B) peer A/B. Current aurora-wip 06e34ecacbf3 versus preview 96d7a1b159c0 containing dc0e571fb9fd, on the same saved Linux boot. Both drivers produced all 2,048 expected float bit patterns for signed and unsigned byte and halfword conversions, including exact 0xff, wider and narrower masks. All 48 sampled GLSL bitfield and SPIR-V conversion CTS statuses matched (44 Pass, 4 NotSupported). No GPU faults or boot changes.

On the same preview, Optimizer.ConvertU8MaskFoldAGX3C and Optimizer.ConvertU8MaskFoldAGX3BSharedMaskParity both passed. The native AGX3C M5 readback remains due.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, merge-train note: this PR has the App approval at dc0e571fb9fd, current-base host tests and the peer regression rows. The one thing missing is the M5 readback row at this head, which the App review asked for. We have no M5 in our lab. Once you post it, I'll run the combined A/B on M1 Pro G13S + M4 G16G and land it in the next batch.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 9f10c201b18f from a different lane. This PR goes into the merge train's next combined A/B (batch 23, stacked on batch 22: #631 #664 #673 #1422 #1423 #1429 #1431 #1432 #1433 #1434 #1436) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@github-actions github-actions Bot added area:compiler Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown

Merging at 9f10c201b18f (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot]. Row: j713 (M4 Air, G16G, fleet91) full VK+GL row of the M1 candidate vs tip: VK Pass 14679 vs 14659, GL Pass 7497 vs 7448, 0 firmware crashes/fail-stops; every Pass->non-Pass case re-ran clean (6 suspects passed 5/5 alone on both builds). Traces: traces/gpu/20261201-b2-mesa-M1. CI: mesa train M1 = aurora-wip 69a6b8d + #570 #1180 #1184 #1266 #1428 #1435 #1415 #1433 #1437 #631 #664 #673 (candidate e56f7487): host meson asahi+poly 351 OK / 26 fail vs tip 344 / 26 (same 26 pre-existing, 0 new; 7 new tests pass), agx_tests pass. Fork Actions don't run in this repo, so this local run is the CI. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 9c40949 into aurora-wip Dec 1, 2026
@RyanTheTide
RyanTheTide deleted the perf/agx-pack-byte-lut-convert-mask branch December 1, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:compiler Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants