Skip to content

Dedupe the prefetch hint, drop the streaming one, add the missing benches - #26

Closed
enthropy7 wants to merge 1 commit into
mainfrom
kernel-opt
Closed

Dedupe the prefetch hint, drop the streaming one, add the missing benches#26
enthropy7 wants to merge 1 commit into
mainfrom
kernel-opt

Conversation

@enthropy7

Copy link
Copy Markdown
Owner

Fallout from reviewing #22.

prfm pldl1keep had drifted into three identical copies. They fold into
ops::prefetch::prefetch_l1_keep, which documents the two rules the measured
results depend on: hoist the gate out of the K-loop, and only hint operands
whose stride actually defeats the hardware prefetcher.

By that second rule the AVX binary_same_shape prefetch does not belong — the
access is unit-stride over three streams. On Zen 4 it measures inside
run-to-run drift (the A/B flips sign with run order).

The transposed-A and matmul_row_set hints from #22 are deliberately not here.
Run in both directions the trans_a kernel at the tracker's real shape is
18.97 vs 19.05 us, p = 0.31 — no effect. And FusedTransposeMatMul, their only
caller, is 1.1% of node time on Zen 4 and 1.3% on the A53. Both kernels were
unbenchmarked, which is why that was invisible; they have benchmarks now.

Plus two review follow-ups: use_avx512_mr12 claimed "DEFAULT ON" where the
gate below it is opt-in on the exact value 1, and rebuild_runtime_index now
debug-asserts one plan action per node, since #24 removed the only fallback for
a short plan.

Validation: cargo test --workspace (all green, incl. doctests), fmt, clippy
--all-targets -D warnings, doc-count gate. A53 (Orange Pi, 1T, 60 iters x 3
alternating): 337.6/337.8/337.8 ms vs 338.7/338.9/339.8 on main. Zen 4 tracker
unchanged at 8.8 ms.

…ssing benches

Reviewing PR #22 turned up that `prfm pldl1keep` had drifted into three
identical copies. Fold them into `ops::prefetch::prefetch_l1_keep`, which
also documents the two rules the measured results depend on: hoist the
gate out of the K-loop (the per-iteration branch alone costs the A53 more
than the hint saves), and only hint operands whose stride actually beats
the hardware prefetcher.

By that second rule the AVX `binary_same_shape` prefetch does not belong:
the access is unit-stride over three streams. Measured on Zen 4 it sits
inside run-to-run drift — the A/B flips sign depending on which arm runs
first — so it was only adding uops to a bandwidth-bound loop.

The transposed-A and `matmul_row_set` prefetch hints from that PR are not
here: they measured neutral. On Zen 4 the trans_a kernel at the tracker's
real shape is 18.97 vs 19.05 us (p = 0.31) once the A/B is run in both
directions, and `FusedTransposeMatMul` — their only caller — is 1.1% of
node time on Zen 4 and 1.3% on the A53, so there is nothing there to win.
Both kernels were unbenchmarked, which is why that was not visible; they
have benchmarks now.

Also assert the execution plan carries one action per node. With the
sequential fallback gone the runner walks the plan and nothing else, so a
short plan would silently skip trailing nodes rather than fail.

A53 (Orange Pi, 1T, 60 iters x 3 alternating): 337.6/337.8/337.8 ms vs
338.7/338.9/339.8 on main. Zen 4 tracker unchanged at 8.8 ms.
@enthropy7

Copy link
Copy Markdown
Owner Author

Closing — landing directly on main instead.

@enthropy7 enthropy7 closed this Aug 7, 2026
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.

1 participant