Skip to content

fetch: a per-slice L0 instruction cache (VX_CFG_ICACHE_L0_ENABLE, default off) - #581

Open
jel221 wants to merge 2 commits into
masterfrom
perf/fetch-l0-cache
Open

jel221 wants to merge 2 commits into
masterfrom
perf/fetch-l0-cache

Conversation

@jel221

@jel221 jel221 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Human comment: Adds the L0 instruction cache. This is the first of the series of frontend changes to support 256 registers per thread. The problem with the current Vortex frontend is that the latency of instruction fetch is extremely high, and you can't really hide it because you have lower occupancy with more registers.

This adds the L0, which caches responses from the Icache so that it avoids the full icache trip. More details in the AI-generated summary below.


Summary

A per-fetch-slice L0 instruction cache in front of the shared icache, behind a new knob VX_CFG_ICACHE_L0_ENABLE (default off).

A warp fetches its next instruction only after the previous one is decoded, so every instruction pays the whole icache round trip: request buffer, icache, response. With few warps per slice nothing hides that latency, and it, not the operands, bounds issue. Kernels that use many registers per thread leave few warps resident, so this is the first step toward 256 registers per thread.

With the knob on:

  • Line store. Each fetch slice keeps VX_CFG_ICACHE_L0_LINES (default 4) whole icache lines, fully associative and replaced round-robin. A hit reaches decode the next cycle. A miss asks the icache for the whole line and keeps it.
  • Output buffer. Decode reads only a two-entry registered output buffer, so every handshake into decode is registered.
  • Runs. Once an instruction is delivered, the L0 delivers the same warp's next instruction behind it, up to 16, crossing into the next line when the L0 holds it. The warp stays locked until the run's last instruction is decoded.
    • If decode sees a stalling instruction inside a run, it drops the instruction behind it, and that instruction's ibuffer slot is refunded.
    • A run takes its ibuffer slot as it is made (run_take), and only from a slot that was free the cycle before.
  • Next-line prefetch. One prefetch per slice is in flight at a time, sent in a cycle no fetch misses.
  • Shared port. The slices share one icache port, round-robin, and the icache has one bank, which now returns whole lines.
  • Flush. The icache flush also invalidates the L0, and a prefetch in flight across the flush is not installed.
  • SimX. fetch_l0() in core.cpp models the same structure: line store, output buffer, runs and their drop, prefetch, and the shared port with its per-slice two-entry request buffers.

The L0 serves the fixed-length fetch path only. It is static-asserted against the C extension in both models.

Gain (rtlsim cycles, 1 core, 4 threads; instruction counts equal off and on):

app 4 warps, off → on 2 warps, off → on
sgemm -n64 787,625 → 540,413 (−31.4%) 1,569,734 → 923,326 (−41.2%)
sgemv -m512 -n512 746,326 → 642,652 (−13.9%) 1,480,487 → 1,127,469 (−23.8%)
softmax -n64 4,850,762 → 3,640,724 (−24.9%) 9,621,362 → 5,706,496 (−40.7%)
vecadd -n16384 348,467 → 267,246 (−23.3%) 663,834 → 486,621 (−26.7%)
geomean −23.6% −33.6%

Impact and evidence

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

Contracts touched:

  • VX_decode_sched_if: gains cont (under VX_CFG_ICACHE_L0_ENABLE). Decode sets it for a run's instruction, and the scheduler advances that warp's PC by 4.
  • VX_gpu_pkg::fetch_t: gains run_more / run_cont (under the same ifdef).
    • The icache word becomes a whole line with the L0 on.
    • The icache fetch tag gains a prefetch bit and a slice select.
    • Every field and width reduces to master's with the knob off.
  • VX_config.toml: adds VX_CFG_ICACHE_L0_ENABLE and VX_CFG_ICACHE_L0_LINES. VX_CFG_ICACHE_NUM_BANKS becomes 1 when the L0 is on (unchanged otherwise).
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: all pass. Knob on, also passed on both models: vecadd at issue width 2 / fetch width 1 (frontend xbar), with VX_CFG_VM_ENABLE, with ICACHE_DISABLE, and sgemm at 4 fetch slices. Knob off: the 51 perf_gate cases pass. xrt not run: no FPGA flow for this preliminary change.
model_parity run parity-l0-sgemm 0.02%, parity-l0-sgemm-2w 0.02%, parity-l0-vecadd-fw2 0.00%, parity-l0-sgemm-fw4 1.18%, parity-l0-vecadd-vm 1.43%; instruction counts equal in all five.
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 (the new knobs change the resolved config); cycles and instruction counts are identical in all 51.
Beacon logic_gate run Knob off against the merge base with master: core and top_vortex PASS, identical depth (15 → 15) and LUTs (127,132 → 127,132; 126,581 → 126,581). Knob on, top_vortex: see V-ISO-6 item 4 below. The STALE verdict a local run prints is the Beacon version (local 134d03b9e, baselines 4060e3af4), not this change: the config hash does not include VX_config.toml.
synthesis (fpga_gate / asic_gate) not run Knob off is the same netlist by Beacon; knob-on synthesis is left for when the register-file work turns the knob on.
XLEN 64 build not run Author policy: XLEN 32 only.

Self-check: precheck: 7 pass, 0 with findings, 0 fail, 0 not run

Departures from SHOULD rules: none

Design note: docs/proposals/fetch_l0_design_note.md; the user-facing description is the new "Fetch L0" section of docs/designs/mlp_optimizations.md.

V-ISO-6 justification

  1. Goal. Remove the icache round trip from each warp's fetch-to-fetch loop, so a warp issues back to back when few warps share a slice. Every extension point sits behind decode, and the latency to remove sits between the warp scheduler and decode, in fetch itself, so no extension point can reach it.
  2. The isolated alternative. A line buffer at the icache output. It saves the tag lookup and the data read, but not the request and response registers, which make most of the round trip. Not built or measured. This change is preliminary work for 256 registers per thread, and the maintainer is asked to waive this item for it.
  3. The gain. Against the base (knob off): −23.6% geomean rtlsim cycles at 4 warps and −33.6% at 2 warps (table above). No numbers for the isolated alternative (item 2): the waiver is requested here too.
  4. The cost to every configuration. Knob off: none (item 5). Knob on, top_vortex (two cores, Beacon against 923d4e2, the parent before the rebase onto current master):
    • Deepest path 15 → 15 levels. LUTs +6.7%, FFs +7.8%, LUTRAM +19.7%.
    • Per core, the L0 itself (fetch) is +1,268 LUTs, +376 FFs and +410 LUTRAM. Most of the rest carries whole lines on the icache response path: the icache response queue and crossbar, the flush arbiter's buffer, and the iMMU's output pipes and skid buffers.
    • Deeper paths: each warp's ibuffer counter (warp_ctx/ibuf_size_r, ibuf_full_r), 5 → 9 levels, from the L0 output buffer through run_take. The L0's own deepest path is 10 levels; its two next-line tag compares take precomputed tag−1 and tag−2 copies instead of an adder.
  5. Knob-off identity.
    • Beacon on core and top_vortex: identical depth and area (evidence table).
    • perf_gate: all 51 cases re-recorded with the knob off, cycles and instructions identical to master; only the config hash moves.
  6. Approval. Pending the maintainer.

Review notes

An independent review found no correctness bug. Its smaller findings are in this PR:

  • a prefetch in flight across an icache flush is not installed;
  • static asserts that the L0 has at least one line;
  • runtime asserts on the ibuffer counter;
  • the SimX ifetches / fetch_stalls counters count what the RTL's count.

Not done:

  • Moving the L0 into its own VX_fetch_l0 module (and a SimX class). Worth doing once the register-file work settles its interface. Today the L0 shares the scheduler and decode handshakes with the rest of VX_fetch.
  • UUIDs. A run's instructions take the next UUID without advancing the warp's UUID counter, so the warp's next scheduled fetch reuses those UUIDs. The counter RAM has a single write port; trace diffs between SimX and the RTL still line up, because both models do the same.

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.

…ault off)

A warp fetches again only after its instruction is decoded, so with few
warps per fetch slice each instruction pays the whole icache round trip.
The L0 keeps VX_CFG_ICACHE_L0_LINES (default 4) whole icache lines per
fetch slice, fully associative, round-robin:

- a hit reaches decode the next cycle through a two-entry registered
  output buffer; a miss asks the icache for the whole line and keeps it;
- runs: the L0 delivers the warp's next instructions behind a delivered
  one (up to 16, across into the next line when held), the warp locked
  until the run's last is decoded; decode drops the instruction behind a
  stalling one and its ibuffer slot is refunded (run_take/run_refund);
- one next-line prefetch per slice in flight; slices share one icache
  port (round-robin) and the icache has one bank returning whole lines;
- the icache flush invalidates the L0; a prefetch in flight across it is
  not installed.

SimX models the same structure in Core::fetch_l0(). With the knob off
every package width, tag and scheduler path reduces to master's (Beacon:
identical depth and LUTs on core and top_vortex).

rtlsim, 1 core, 4 threads: -23.6% cycles geomean at 4 warps and -33.6%
at 2 warps over sgemm, sgemv, softmax and vecadd. model_parity cases
parity-l0-{sgemm,sgemm-2w,vecadd-fw2,sgemm-fw4,vecadd-vm}.
The new knobs change 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

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