Skip to content

LMEM: separate DXA row-write and TCU row-read DMA ports - #586

Open
jel221 wants to merge 1 commit into
masterfrom
perf/lmem-dma-split
Open

jel221 wants to merge 1 commit into
masterfrom
perf/lmem-dma-split

Conversation

@jel221

@jel221 jel221 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Human comment: There is no reason for the DXA (writes INTO the SMEM) and TCU (reads FROM the SMEM) to arbitrate over a single port. This is one of the bottlenecks identified working on WGMMA.

Summary

Gives VX_lmem_unit separate DMA ports for row writes and row reads, so a DXA write and a TCU read no longer compete for one port.

On master, the DXA's row writes and the TCU tile buffers' row reads share one LMEM DMA port through a round-robin VX_mem_bus_arb in VX_mem_unit, and every DMA access uses bank port A. With two or more LSU blocks the banks are VX_1rw1r_ram, and port B is idle in every DMA cycle: the slot that admits a DMA access holds both LSU passes off. A writer and a reader therefore queue behind each other for one port while a second port sits idle.

  • Ports. VX_lmem_unit has dma_wr_if (row writes, from the DXA) and dma_rd_if (row reads, from the TCU) in place of dma_if. VX_mem_unit connects each agent to its own port, and its DMA arbiter is gone.
  • 2+ LSU blocks. A row read uses bank port B, in the same DMA slot as a row write on port A. The read request is taken into a register as it arrives and fires from it in the slot, so port B's enable and address come from registers only. Port B has no other user in a DMA slot, so this is a mux, not an arbiter. VX_lmem_bank is unchanged.
  • 1 LSU block (VX_sp_ram banks, one port). The two agents alternate round-robin inside the LMEM unit, as on master.
  • Same-row race. A read of the row written in the same cycle returns undefined data. The kernel's barrier keeps a stage from being read while the DXA fills it, as on master, where the two were serialized but not ordered.
  • Single-agent builds. With only the DXA or only WGMMA, the other port is tied off and its logic is not generated.
  • SimX. LocalMem models the same: per DMA slot, one write and one read with two or more LSU blocks, round-robin with one.

Impact and evidence

See docs/review/code-review-policy.md.

Impact class: R3. The classifier gives R3 (golden-values) for the re-recorded baselines. The change also edits a shared unit (the local memory) for the DXA and TCU extensions, so it falls under V-ISO-6 (justification below).

Contracts touched:

  • VX_lmem_unit ports: dma_if is replaced by dma_wr_if and dma_rd_if. Both instantiations changed with it: VX_mem_unit and the lmem unit-test wrapper hw/unittest/lmem_unit/VX_lmem_unit_top.sv.
  • VX_gpu_pkg: LMEM_DMA_DXA_IDX, LMEM_DMA_TCU_IDX, LMEM_DMA_INPUTS, LMEM_DMA_IN_TAG_MAX and LMEM_DMA_TAG_WIDTH are replaced by LMEM_DMA_WR_TAG_W and LMEM_DMA_RD_TAG_W. There are no other users.
  • SimX LocalMem::Config::dma_clients: each client now only writes or only reads. A client that mixes the two, or more than 32 clients, fails an assertion.
  • Golden values: Beacon lmem and tensor in beacon and beacon_asic; the perf baselines listed in the delta table.
evidence status detail
functional tests (simx / rtlsim / xrt) run XLEN 32, rtlsim and SimX: pytest ci -k "(dxa or lmem or wgmma or tensor_wg or tcu_wg or local or barrier) and not perf_gate", 171 passed (4 shards, separate build trees). xrt not run.
model_parity run model_parity-wgmma-dxa-lsu2 (new) and model_parity-wgmma-sp-dxa-lsu2 (new) pass; sparse gap 0.67 %. Also model_parity-wgmma-dxa, model_parity-wgmma-sp-dxa and model_parity-wgmma-dxa-mcast (1 LSU block, round-robin).
perf_gate run The 23 DXA/TCU/LMEM gates (-k "dxa or wgmma or tensor or tcu or lmem or local"), regenerated with --update-baselines. The 22 existing entries come out identical to master in cycles and instructions; the only change is the new perf_gate-wgmma-dxa-lsu2.
Beacon logic_gate run core, lmem and tensor, both tools, against the merge-base. No path got deeper in any of them. lmem +69 LUT / +46 FF (attributed below). core is identical.
synthesis (fpga_gate / asic_gate) not run No gate covers a WGMMA+DXA configuration. Beacon covers depth and area.
XLEN 64 build not run Left to CI. The change has no XLEN-dependent code: row widths come from LSU_MEM_WORD_SIZE, the same at both XLENs.

Self-check: ci/precheck.sh summary: precheck: 7 pass, 0 with findings, 0 fail, 0 not run

Departures from SHOULD rules: none

Design note: the V-ISO-6 justification below, and docs/designs/mlp_optimizations.md (Local-memory banks and LMEM DMA round-robin sections), updated in this PR.

V-ISO-6: a shared-unit change for the DXA and TCU

1. Goal. A DXA row write and a TCU row read go through the local memory in the same cycle. The two agents use the same banks and need nothing from each other. No extension point can do this. The banks' second port exists only inside VX_lmem_unit, and on master both agents reach the banks through the one DMA port. Any design outside the unit can only choose which of the two waits.

Today's WGMMA+DXA kernels are not DMA-bound, so the gain on master is small (item 3). An analytical model of the TMEM GEMM shows the port becomes the limit once operand fetch overlaps the MMA steps. On a 128×128×512 GEMM, DXA writes plus TCU reads come to 36,864 port cycles against 32,768 cycles of MMA work. With the split, the larger of the two is 20,480 cycles, below the MMA.

2. The isolated alternative. Master is the isolated design: one DMA port, with the arbiter in VX_mem_unit. An arbitration policy can reorder who waits but cannot serve both in one cycle, so no isolated design does better than master here. To measure what that costs, I counted the cycles in which both agents had a request and only one was served. The count came from a temporary counter on master, not committed. Config: rtlsim, ISSUE_WIDTH=2, two LSU blocks, NRC=32, 32 threads × 8 warps.

kernel cycles both waiting TCU lost DXA lost
sgemm_tcu_wg_dxa 128×128×64 1,995 991 1,004
sgemm_tcu_wg_sp_dxa 128×128×128 2,083 726 1,357

3. The gain. Same configuration, rtlsim cycles (SimX in parentheses):

kernel master this PR
sgemm_tcu_wg_dxa 128×128×64 40,269 (39,993) 39,426 (39,644), −2.1 %
sgemm_tcu_wg_sp_dxa 128×128×128 80,454 (80,764) 79,130 (79,661), −1.6 %

The port-B request register costs nothing on the dense kernel (39,426 either way) and 20 cycles on the sparse one (79,110 without it).

4. The cost to every configuration. Beacon, against the merge-base:

configuration FPGA LUT FPGA FF ASIC cells depth registers ≥ 8 levels
core (no DXA, no TCU) 127,132 → 127,132 identical 743,174 → 743,174 15 → 15 / 29 → 29 285 → 285
tensor (1 LSU block, round-robin) 260,500 → 260,100 161,727 → 161,725 838,075 → 837,473 24 → 24 / 33 → 33 526 → 526
tensor + NUM_LSU_BLOCKS=2 ISSUE_WIDTH=2 (port B) 432,721 → 432,417 293,124 → 293,148 not run 24 → 24 873 → 869
lmem unit test 18,880 → 18,949 14,361 → 14,407 120,296 → 120,509 9 → 9 / 15 → 15 16 → 16
  • No path got deeper in any of the four. The DMA arbiter in VX_mem_unit (404 LUT, both cores) is gone.
  • With two LSU blocks, 46 paths got shallower. On master, the TCU's abuf reaches the SRAM address pins combinationally, 7 levels from fetch_base_r, through the arbiter. On this branch, port B's address is 2 levels from registers. The LMEM unit's deepest path goes from 10 to 9 levels.
  • With one LSU block, the round-robin is in the LMEM unit instead of VX_mem_unit. The TCU request still reaches the DXA completion FIFO combinationally, at 8 levels, the same depth as master. This path predates this PR, and this PR does not lengthen it.
  • The lmem cost is in the delta table below. The FPGA cost is +58 LUT / +14 FF in lmem_unit (port-B mux, request register, round-robin bit) and +11 LUT / +32 FF in the unit-test wrapper, which registers the new read port like the write port.

5. Knob-off identity. With neither VX_CFG_EXT_DXA_ENABLE nor VX_CFG_TCU_WGMMA_ENABLE, the LMEM unit has no DMA logic. Beacon core is identical in both flows: area, depth and every endpoint. The perf gates of configurations without DXA or WGMMA do not move: every entry in the 23-gate run is identical to master, apart from the new one.

6. Approval. Pending: needs the maintainer's approval on this PR.

X-CFG-5: each generate branch has a case

branch in VX_lmem_unit when cases
DMA_RD_PORT_B (register + port B) DXA and WGMMA, 2+ LSU blocks model_parity-wgmma-dxa-lsu2, perf_gate-wgmma-dxa-lsu2, model_parity-wgmma-sp-dxa-lsu2
DMA_SHARED (round-robin on port A) DXA and WGMMA, 1 LSU block model_parity-wgmma-dxa, perf_gate-wgmma-dxa, perf_gate-wgmma-sp-dxa, perf_gate-wgmma-dxa-mcast*
write port only DXA, no WGMMA perf_gate-copy-*, perf_gate-sgemm2-dxa-*
read port only WGMMA, no DXA perf_gate-wgmma-fp16-ss, perf_gate-wgmma-sparse
no DMA neither lmem and core Beacon; the LMEM functional suite

Golden data re-recorded

ci/logic_gate.py -j 1 -b lmem -b tensor --update-baseline --against-rev $(git merge-base HEAD origin/master)
ci/logic_gate.py -j 1 -b lmem -b tensor --tool beacon_asic --update-baseline --against-rev $(git merge-base HEAD origin/master)
pytest ci -m perf_gate -k "dxa or wgmma or tensor or tcu or lmem or local" --update-baselines

Run with the TOOLCHAIN_REV v3.0.4 prebuilts, XLEN 32. Re-recorded by: agent at jel221's request 2026-12-03. This is the PR author's request, not a maintainer delegation under X-EV-1. If the maintainer wants a re-run by a person, it is the three commands above.

Per-entry deltas (B-3). Every change is in this PR's one commit.

entry master → this PR mechanism class
Beacon lmem (FPGA) LUT 18,880 → 18,949 (+0.4 %), FF 14,361 → 14,407 (+0.3 %) lmem_unit: per-bank port-B mux (+58 LUT); request register: valid, row address, tag (+14 FF). Wrapper: input register for the new read port (+11 LUT, +32 FF). trade-off
Beacon lmem (ASIC) cells 120,296 → 120,509 (+0.2 %), ff 23,721 → 23,767 the same logic trade-off
Beacon tensor (FPGA) LUT 260,500 → 260,100, FF 161,727 → 161,725 VX_mem_unit's two-input arbiter removed; the round-robin moved into the LMEM unit improvement
Beacon tensor (ASIC) cells 838,075 → 837,473, ff 166,953 → 166,951 the same improvement
perf_gate-wgmma-dxa-lsu2 new: 39,426 (master builds the same config at 40,269) new case for the port-B path new
the other 22 DXA/TCU/LMEM perf entries unchanged the one-LSU-block round-robin, moved into the LMEM unit, is cycle-identical to master's none

The lmem trade-off. The cost buys the −2.1 % / −1.6 % above and removes a combinational path from the TCU into the SRAM. Predicted before measuring: one mux per bank on port B's enable and address (the LUTs); one register of valid plus row address plus tag (the 14 FF); one buffer for the wrapper's second port (it registers every input port). The cheapest design that still serves a write and a read in the same cycle needs the same per-bank port-B mux. Without the request register it saves the 14 FF, but the TCU's request logic then reaches port B combinationally, which V-ISO-4 rules out. Master's shared port avoids both costs and keeps the conflict cycles of item 2.

  • 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). The re-record was run by an agent at the author's request; see above.
  • 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.

…s on port B from a request register with 2+ LSU blocks); re-record: ci/logic_gate.py -j 1 -b lmem -b tensor [--tool beacon_asic] --update-baseline --against-rev $(git merge-base HEAD origin/master), pytest ci -m perf_gate -k 'dxa or wgmma or tensor or tcu or lmem or local' --update-baselines; Re-recorded by: agent at jel221's request 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