Your First Week
Plan on one day to get a working environment and see the array run, and one week to make a first real change. Read the introduction and the systolic tile first.
Day 1: the environment
Section titled “Day 1: the environment”You need Python 3.10+, just, and
OSS-CAD-SUITE for Verilator, Yosys and
GTKWave. Set OSS_CAD_SUITE if it is not in /opt/oss-cad-suite.
The development environment has the details.
git clone https://github.com/stillwater-sc/systars.gitcd systars./bin/setup-dev-env.sh # or: just setup, if OSS-CAD-SUITE is installedsource .venv/bin/activatejust check-toolsTo start on the Python side only, a plain virtual environment is enough:
pip install amaranth numpy pytest pytest-subtests and export PYTHONPATH=src. Without
Yosys, the unit tests that need synthesis are skipped.
Day 1: see it run
Section titled “Day 1: see it run”just test-unitruns the unit tests. For a quick first run:pytest tests/unit/test_pe.py tests/unit/test_stream_buffer.py tests/unit/test_systolic_array.py.python examples/gemm/08_rtl_wavefront.py --stage 1 --svg s1.svgrecords a 2x2 array from the RTL, checks it against the predicted wavefront and writes an animation; open it in a browser. Then try--stage 2,--stage 3and--dataflow ws.- Read the wavefront animation page: its three animations are the quickest way into the timing.
python examples/gemm/07_isa_matmul.pyprints the command stream of a Matmul, C[10x4] = A[10x4] @ B[4x4] on a 4x4 array (below).just genwrites every RTL target intogen/, andpython3 -m systars.targets listlists them. Look at what Amaranth emits for the PE.just test-cocotbruns the RTL tests on Verilator.
Reading a command stream
Section titled “Reading a command stream”Example 07 prints three output tiles of the same shape:
CONFIG rs1=0x0 # select OSLOAD dram=0x10000000 local=0x00000000 rows=4 stride=4 row_bytes=4 # A rows 0-3LOAD dram=0x20000000 local=0x00000008 rows=4 stride=4 row_bytes=4 # B, corner-turnedCOMPUTE rs1=0x0 rd=0x80000000 k_dim=4 # bit 31 of rd: the CombinerSTORE dram=0x30000000 local=0x80000000 rows=4 stride=16 row_bytes=16 # int32 rows of C... the same for A rows 4-7 (L2 slot 0x4, Combiner 0x80000004)... and for rows 8-9 (rows=2), back in slot 0x0Ask three questions of it: which slot each command fills or reads, which cmd_sync flags make
the third tile wait until the first has released slot 0x0, and why the second tile does not
wait at all. The printout shows neither the LOAD opcodes (B’s is a TRANSPOSE) nor
cmd_sync, so read src/systars/isa/matmul.py beside it. The example runs the instruction
against a stand-in controller and checks the command counts only; the unit and cocotb tests
check the numbers.
Week 1: exercises
Section titled “Week 1: exercises”Each one ends in something you can check. Do them in order.
- Predict a result clock. PE(i, j)’s OS result leaves the north edge in clock
s + K + j + 2i(core/pe.py). Predict the clocks for a 4x4 array with K = 4, then confirm with08_rtl_wavefront.py --grid 2 2 --tile 2 2 --n 4. - Break the skew and watch it fail. On a scratch branch, change the order in which the
Streamer loads the L1 buffers (
controller/streamer.py). Runtests/unit/test_wavefront.pyandtests/unit/test_streamer.py, read the failures, then revert. - Measure double buffering. Find where
tests/unit/test_credits.pycomparesbuffers=1withbuffers=2(907 against 744 cycles for 8x8x16 on 4x4). Change the shape and explain the new numbers. - Trace one slot. Pick an L2 slot in the command stream above and write down its state
(FREE, OWNED, READY, READING) after each command. Check yourself against
controller/sync.py. - Run a Matmul with a bias in WS. Copy a case from
tests/unit/test_matmul.py, setCONFIG_DATAFLOWto WS and a bias row, and check the result against numpy. - Synthesize. Run
just synth ecp5, thenjust synth polarfire, and compare the PE’s resource counts with the PolarFire plan.
How correctness is established
Section titled “How correctness is established”Five layers, each catching what the one before cannot. A change is done when the layers it touches pass.
| Layer | Where | Tool | What it proves |
|---|---|---|---|
| Unit and integration | tests/unit/ |
pytest, Amaranth simulator | Component behaviour and cycle timing (result clocks, no bubbles, the 2R - 1 drain); GEMMs end to end through SystolicTop; Matmul and Conv2d against numpy in every dataflow |
| Independent models | tests/unit/_axi.py, _isa.py, test_credits.py |
Python reference models | The AXI rules (no burst across 4 KB); a Python model of SystolicTop for the ISA; a cycle-by-cycle slot monitor (credits conserved, no tile used before its token) |
| Wavefront check | wavefront.py, test_wavefront.py |
Amaranth simulator | Every PE in every clock matches the wavefront equation; the committed SVGs are current |
| RTL simulation | verif/cocotb/tests/ |
cocotb, Verilator | The generated Verilog, including Matmul and Conv2d on the 4x4 systolic_top target in OS, WS and IS |
| Synthesis | just synth <target> |
Yosys (generic, iCE40, ECP5, PolarFire) | The targets map onto device cells; resource counts |
When you add tests:
- Check every other byte. End-to-end tests verify the result and that every byte of L3 outside it is untouched.
- Start from random memory.
test_no_read_before_writefills the scratchpad and the Combiner with random data, since memories on hardware have no reset value. - Assert the error flags. A valid schedule never raises
l1_errororsync_error.
A new cocotb suite goes in both just test-cocotb and the rtl-tests matrix in
.github/workflows/test.yml. A change to the fabric, the Streamer’s schedule or the renderer
needs just wavefronts, with the regenerated SVGs committed.
Codebase map
Section titled “Codebase map”Not everything under src/systars/ is on the path to SystolicTop. Some modules predate the
registered fabric and the CSP rework, and three packages model other architectures.
| Path | Status | What it is |
|---|---|---|
config.py, targets.py, top.py |
Current | Configuration, the RTL target list, the compute tile |
core/ |
Current | PE, PEArray, SystolicArray |
memory/scratchpad.py, combiner.py, stream_buffer.py, local_addr.py |
Current | L2, the Combiner, L1, local address encoding |
controller/streamer.py, result_path.py, blockmover.py, blockmover_in.py, blockmover_out.py, sync.py |
Current | The Streamer, the result path, the BlockMover and its legs, credits and tokens |
blockmover/reader.py, writer.py, axi.py |
Current | The AXI burst engines behind the BlockMover |
isa/ |
Current | Matmul, Conv2d, the command port |
wavefront.py |
Current | RTL tracing, checking and SVG rendering |
util/commands.py |
Current | BlockMoverOpcode, ExecOpcode and command helpers |
memory/skew_buffer.py |
Legacy | The skew-register approach; used only by test_sram_read_scheduler.py and example 05 |
controller/blockmover_in_transpose.py, blockmover/strided_reader.py |
Legacy | An earlier transposing load; SystolicTop turns corners in the BlockMover |
blockmover/descriptor_engine.py |
Not integrated | BlockMover descriptor chains (design); tested, not wired into SystolicTop |
loop/, arithmetic/ |
Empty | Placeholders for planned components |
stencil/ |
Side package | A line-buffer stencil machine for 2D convolution |
simt/, simd/maspar/ |
Side package | Models of an NVIDIA-style SM and a MasPar SIMD array, with animations and energy estimates |
In examples/gemm/, 02 and 03 animate the textbook model, 05 uses the legacy skew buffer and
06 the legacy transposing load. Example 07 (an ISA command stream) and 08 (the current SystolicArray RTL) reflect the
current design, so start there; the integrated tile runs in tests/unit/test_gemm_systolic.py,
tests/unit/test_matmul.py and the cocotb systolic_top suite.
docs/sessions/ holds dated development logs: useful history, not specifications.
House rules
Section titled “House rules”- Use KPU and CSP terms (credits, push, tile-ready tokens, L1/L2/L3), never cache terms.
- New components are
lib.wiring.Componentsubclasses whose docstring states their ports and timing: the docstrings are the specification. - Pages are plain Markdown in
docs/; the site indocs-site/is generated, and a broken link fails its build. See the development workflow. - Run
just checkbefore every push; CI runs the same recipes. - Look terms up in the glossary.