Skip to content

fetch: icache stream prefetch from the L0 (VX_CFG_ICACHE_STREAM_ENABLE, default off) - #583

Open
jel221 wants to merge 2 commits into
perf/fetch-l0-cachefrom
perf/icache-stream-prefetch
Open

jel221 wants to merge 2 commits into
perf/fetch-l0-cachefrom
perf/icache-stream-prefetch

Conversation

@jel221

@jel221 jel221 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Human comment: The L0 prefetches into the icache. So this isn't an icache prefetch at the icache controller, but more like the L0 requesting an icache line early and ignoring it. This closes the most of the last bit of the fetch bottleneck.


Stacked on #581. The base is perf/fetch-l0-cache, so the diff shows only this change: the stream prefetch and its baseline re-record.

Summary

An icache-only stream prefetch driven by the fetch L0, behind VX_CFG_ICACHE_STREAM_ENABLE (default off; it needs VX_CFG_ICACHE_L0_ENABLE).

The L0 prefetches the next line into itself. When that line misses the icache, the prefetch returns too late and the warp waits on memory. That is the common case for long, unrolled code larger than the icache, which is what kernels with many registers per thread look like.

With the knob on, a slice also asks the icache for the line 4 past the one a fetch or a run enters, and drops the response; the icache keeps the line.

  • Priority. The request ranks lowest on the slice's request buffer, behind demand misses and the L0's own prefetch.
  • Gate. It is sent only while recent prefetch responses came back late (two or more 16-cycle ticks, the send tick carried in the request tag), so code that fits in the icache sends none.
  • Filter. A line already wanted, or one of the last two sent, is not asked again.
  • SimX. It models the same in fetch_l0(). A stream request in flight counts in pending_ifetches_, so the core does not go quiescent before its response returns. Without that, SimX dogfood hung at test 20 with a 4 KB icache.

Gain on master is about neutral. SimX, which tracks rtlsim within 0.1–2% on these cases, over 9 kernels larger than a shrunken icache (dogfood, flash_attn, jacobi, lazy_fetch, ldst_matrix, printf, raycast, sgemm_v1, softmax). Stream on vs the L0 alone:

icache 2 warps (geomean, range) 4 warps (geomean, range)
2 KB −0.31% (−1.78% … +0.57%) −0.03% (−1.30% … +0.73%)
4 KB +0.23% (−0.13% … +0.86%) −0.04% (−0.46% … +0.40%)

Master has no kernels of the kind this is for. On the 256-register branch (feature/256-registers, unrolled kernels at 2 warps × 256 registers), the stream moved the frontend's gain from −4.0% to −10.9% cycles geomean, and a 64-key sort by −26%. Those kernels come with the register-window PRs.

Impact and evidence

Impact class: R3 (pipeline-stage, gpu-pkg-types, config-knobs).

Contracts touched:

  • Icache fetch tag. ICACHE_FETCH_PF_BITS is 6 with the stream on (prefetch bit, stream bit, 4-bit tick), 1 with the L0 alone, and 0 without the L0; the width flows through ICACHE_TAG_WIDTH.
  • VX_config.toml. Adds VX_CFG_ICACHE_STREAM_ENABLE. Both models assert that the L0 is on when the stream is enabled.
evidence status detail
functional tests (simx / rtlsim / xrt) simx, rtlsim run; xrt not run make -C tests/regression run-simx and run-rtlsim with -DVX_CFG_ICACHE_L0_ENABLE -DVX_CFG_ICACHE_STREAM_ENABLE: all pass. The 40-run SimX screen above (2 and 4 warps, 2 and 4 KB icache) also passes, dogfood 25/25 in each. xrt not run: no FPGA flow for this preliminary change.
model_parity run parity-l0-stream-jacobi 2.05%, parity-l0-stream-dogfood 0.89%, parity-l0-stream-fw2 0.10%, all at a 4 KB icache; instruction counts equal in all three. The L0's five cases (stream off) pass with cycles identical to #581 on both SimX and rtlsim.
perf_gate run All 51 cases pass (XLEN 32, toolchain v3.0.4). The second commit re-records the baselines with pytest ../ci -m perf_gate --update-baselines: only config_hash changes; cycles and instruction counts are identical in all 51.
Beacon logic_gate run Against perf/fetch-l0-cache: knob off, core and top_vortex PASS with identical depth and LUTs; L0 on and stream off, top_vortex identical (15 → 15 levels, 135,041 → 135,041 LUTs). Knob on: item 4 below.
synthesis (fpga_gate / asic_gate) not run Knob off is the same netlist by Beacon.
XLEN 64 build not run Author policy: XLEN 32 only.

Self-check: precheck: 7 pass, 0 with findings, 0 fail, 0 not run (against perf/fetch-l0-cache)

Departures from SHOULD rules: none

Design note: docs/proposals/icache_stream_prefetch_design_note.md

V-ISO-6 justification

  1. Goal. Hide the icache miss of the line a warp enters next, for code larger than the icache. Only the L0, inside VX_fetch, knows which lines its warps are about to enter. No extension point sees it.
  2. The isolated alternative. A next-N-line prefetcher inside the icache. It knows hit or miss exactly, so it would need no tick heuristic, no tag bits and no fetch-port slots. Not built or measured. The maintainer is asked to waive this item for this preliminary step.
  3. The gain. Against the L0 alone, about neutral on master (table above). The motivating gain is on the 256-register branch (−4.0% → −10.9%). No numbers for the isolated alternative: the waiver is requested here too.
  4. The cost to every configuration. Knob off: none (item 5). Knob on, top_vortex (two cores) against the L0 alone: deepest path 15 → 15 levels; LUTs +574 (+0.4%), FFs +312 (+0.2%), LUTRAM +11. Registers at 8 or more levels 434 → 438. The fetch stage's own deepest path moves 10 → 11 levels (the sched_line + 4 adder ahead of the filter compares).
  5. Knob-off identity. Beacon: identical depth and LUTs with the stream off, both with the L0 off and with it on (evidence table). perf_gate: all 51 cases identical in cycles and instructions.
  6. Approval. Pending the maintainer.

Review notes

An independent review found two must-fix issues. Both are fixed here:

  • With the L0 on and the stream off, the request-address mux was a different function (it took the stream line as its default). It now takes the stream line only when the stream request is selected, which restores the L0's netlist.
  • Missing braces in SimX.

Also from that review:

  • a static assert that the stream needs the L0;
  • the pending stream line is filtered, so it is never sent twice;
  • SimX's fetch-stall counter counts a waiting stream request, as the RTL does;
  • SimX's tick counts from reset, as the RTL's does;
  • a two-slice parity case.

Not done:

  • The schedule-PC adder (sched_line + 4) in front of the filter compares. The fetch stage's deepest path moves 10 → 11 levels, under the threshold. A shadow register would remove it, but the depth does not justify one yet.
  • Page crossing under VM. A prefetch may cross a page boundary. The L0's next-line prefetch already can; the kernel image sits in an identity-mapped executable range.

Checklist

  • No test silenced (known_issue:, wider tolerance, smaller args, removed case) without a root-cause plan.
  • Golden data changed only through its update command; the commit names the command and who ran it (X-EV-1).
  • Cycle-moving RTL changes carry the matching SimX change, or the parity case that shows none moved.
  • A toolchain pin moves only after the prebuilt tag exists.

…E, default off)

The L0's next-line prefetch comes back too late when its line misses the
icache, so straight-line code larger than the icache waits on memory.
With the knob on (it needs VX_CFG_ICACHE_L0_ENABLE), a slice also asks
the icache for the line 4 past the one a fetch or a run enters, at the
lowest priority on its request buffer, and drops the response. It runs
only while recent prefetch responses came back late (two or more 16-cycle
ticks, carried in the request tag); a line already wanted or one of the
last two sent is not asked again.

SimX models the same in fetch_l0(); a stream request in flight is counted
in pending_ifetches_, so the core does not go quiescent before its
response returns (dogfood had hung at test 20 without it). With the knob
off the RTL is the L0's (Beacon: identical depth and LUTs, L0 on and off).

model_parity: parity-l0-stream-{jacobi,dogfood,fw2}.
… hash

The new knob changes the resolved config, so every perf_gate case's
config_hash moves. Cycles and instruction counts are unchanged in all 51
cases (the knob is off by default).

Command: pytest ../ci -m perf_gate --update-baselines (from a configured
XLEN 32 build tree).
Re-recorded by: agent, authorized by jel221 2026-12-03
@jel221
jel221 marked this pull request as ready for review December 3, 2026 21:58
@jel221
jel221 added this pull request to stack #590 December 4, 2026 08:28

This branch has not been deployed

No deployments
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