§ 6.3. Data Movement¶
A systolic array is only as fast as the numbers arriving at it. This section covers the two ways data reaches the unit: its own copy engine, which is a second master on the bus, and an optional pipelined bus that lets accesses follow each other every cycle.
6.3.1. The copy engine¶
The unit moves data itself, in the style of a DMA (direct memory access)
engine: the processor names a source, a destination and a shape, and the
copy engine performs the transfer while the processor waits or does
something else. It is the COPY_ENGINE group inside MatrixUnit<N>
(6.4); its master port is the unit's DMA_ port.
What it copies. Bytes, between main memory and the unit's buffers, in a three-level pattern: P patches, each of R rows of B bytes.
memory address = ARG0 + p·T + r·S + c p < P, r < R, c < B
buffer byte = ARG1[15:0]·N + p·DR·N + r·B + c (DR buffer rows per patch)
A dense layer's inputs are P rows of the input matrix, each copied as R chunks of N bytes. A convolution's input window is a patch of R = 3 image rows of B = 3 × channels bytes, S apart; the next patch starts T = stride × channels bytes on. So the copy engine itself rearranges an image into the rows a matrix multiply needs ("im2col"), with no help from the processor.
How it reads. Memory answers whole aligned words. A LOAD keeps the last word it read and its address; consecutive bytes from the same word cost no new bus request. A STORE writes one byte per request, with the byte's lane in the write mask and the byte repeated on all four lanes.
| Command | Direction | Bus requests |
|---|---|---|
| LOAD | memory → activation, weight or bias buffer | one word read per new word, one cycle per byte from a held word |
| STORE | activation buffer → memory | one byte write each |
A request waits for the bus like any other; the engine has one request in flight. An answer with a non-zero status ends the command and sets the unit's error flag. A command whose P, R or B is 0 finishes without a transfer.
IO pins of MatrixCopyEngine<N>¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
CLK, RST |
Input | 1 | Clock and reset |
START, STORE_OP |
Input | 1 | Begin a command (from the sequencer); it is a STORE |
ARG0–ARG3 |
Input | 32 | The command's arguments, as above |
REQ_READY, RSP_VALID, RSP_DATA, RSP_STATUS |
Input | 1, 1, 32, 3 | The bus's answers on the unit's DMA_ port |
LOCAL_READ |
Input | 8 | The activation byte STORE sends (from STORE_SELECT) |
REQ_VALID, REQ_WRITE, REQ_ADDR, REQ_DATA, REQ_MASK |
Output | 1, 1, 32, 32, 4 | The request: a word read, or a byte write on all four lanes with its lane's mask |
RSP_READY |
Output | 1 | Waiting for an answer |
LOCAL_ADDR, LOCAL_WRITE, LOCAL_DATA |
Output | 16, 1, 8 | The buffer byte, its write enable and the byte a LOAD writes |
TARGET, STORING |
Output | 2, 1 | Which buffer a LOAD fills; a STORE runs |
DONE, FAILED |
Output | 1 | The command's last edge; it ended on an error answer |
Inside, registers hold the command's shape (PATCHES, ROWS, BYTES,
the strides, TARGET), the three counters and their addresses
(ADDRESS, ROW_ADDRESS, PATCH_ADDRESS, LOCAL, LOCAL_PATCH), the
request state (ACTIVE, WAIT) and the held word (CACHE_TAG,
CACHE_DATA, CACHE_VALID).
6.3.2. The pipelined bus¶
On the chapter-5 bus every access pays waits that are not memory time: on a zero-wait memory an instruction fetch takes three cycles (bus record):
- the router registers the request, offering it to the target one edge later, and takes the next request only after the answer has gone;
- the arbiter takes no answer in the cycle it accepts a request;
- the core offers its next fetch only in the cycle after taking an answer.
A bus with "pipelined": true in its description removes these three waits
together:
| Part | Option | Change |
|---|---|---|
BusRouter<W> |
pipelined=1 |
Takes the next request at the edge the previous answer is taken (its register stays: the address decode still has a full cycle) |
TwoPortMemoryArbiter<W> |
pipelined=1 (also the memory subsystem's own fetch/data arbiter) |
From idle, the accepted request's same-cycle answer passes straight through; the next request is accepted at the edge the current one completes |
| RV32IM core | overlapped_fetch=1 |
The fetch requester starts the next fetch in the cycle it takes an answer, for the address the PC will hold after that edge |
The core's next PC is a guess when the instruction just fetched is a
branch the predictor gets wrong. Such a fetch is discarded as any stale
fetch is: the requester compares the address it fetched with the core's PC
and drops a mismatching answer. So the overlap changes only when fetches
happen, never which instructions run; PipelinedBusTest checks that the
instruction count and the results stay the same.
The memory controller of chapter 3 already accepts a new request at the edge its current one completes, and keeps a finished answer in its response buffer; it needs no change.
What stays. A router still holds one request at a time, so a memory with wait states (SRAM's one cycle) is not fully hidden: the answer must come back before the router takes the next request. A two-deep router is left for later.
Default. Since 2026-11-13 the machines use the pipelined bus: the
descriptions in systems/ (the games machines of chapter 5 and the two
accelerator machines) set the bus's "pipelined": true, the memory
subsystem's pipelined=1 and the core's overlapped_fetch=1, together
with the array multiplier (6.1.2). The parts
themselves keep the one-request protocol as their default, so the
memory arrangements of chapter 3 and § 4.7, built from the parts without a
machine description, are unchanged. The machine option bus=single (with
multiplier=iterative) gives back the chapter-5 machine; the published
long games were recorded on it and keep it when they are replayed.
accelerator_experiment --single-bus and the runner's
pipelined_bus=false do the same for the accelerator machines; the effect
is measured in 6.6.
Examples¶
The copy engine at work is on the timelines of two scenarios: the
MatrixUnit<4> layer of 6.4, where every word read and
byte written appears on the DMA_ port, and the whole machine of
6.5, where the transfers share the memory with the
processor. Both run on the chapter-5 bus; the pipelined bus has no scenario
of its own, and its effect is measured in 6.6.
Source and tests¶
Copy engine (COPY_ENGINE in the unit);
pipelined options in the router,
the two-port arbiter,
the memory subsystem
and the core's fetch requester;
tests.
| Test | Coverage |
|---|---|
MatrixUnitTest |
LOAD gathers (dense and convolution patches), STORE scatter, a DMA error, empty counts (6.4) |
PipelinedBusTest |
The memory subsystem with FF, SRAM and DRAM, fetch port alone and both ports: random reads and writes checked against a host memory, plain and pipelined arbiter; cycles compared. Then 6,000 accesses per memory with requesters that refuse answers in a random third of the cycles (a core stalled on its other port). Whole programs (demo-cpu, demo-n4) on the plain and the pipelined bus: same results and instruction counts, fewer cycles |
PipelinedBusTest checks the memory subsystem and whole programs; the
router's pipelined=1 is exercised only inside those programs, not by a
random-traffic comparison of its own as BusInterconnectTest does for the
plain router.