FPGA and hardware · Simulation
Simulated systolic-array MNIST accelerator in SystemVerilog
A weight-stationary systolic array in SystemVerilog, a grid of multiply-accumulate cells wired only to their neighbors, runs a quantized 784-32-16-10 MNIST network end to end in simulation.
Over 200 test images, all 2,000 logits and 9,600 hidden activations match a Python golden model bit for bit. It has not run on a physical FPGA.
The problem
A dense layer is a long run of multiply-accumulates (MACs). This 784-32-16-10 MNIST network needs 25,760 per image.
An N×N systolic array runs up to N² of them per cycle with wires only between neighbors. Weights stay in the processing elements (PEs), activations move east and partial sums move south.
A 4×4 array holds one tile of 16 of the first layer's 25,088 weights, so that layer needs 1,568 weight swaps. Any idle cycle around a swap is paid 1,568 times.
What I built
I trained the network in PyTorch and quantized it to INT8. A pure-integer NumPy golden model defines each operation, and the RTL must match it bit for bit.
The SystemVerilog is parameterized by array size N. A skew buffer delays row r by r cycles, so each column's sum meets the right activation.
My first verified version stopped the array to load each weight tile. I then gave every PE a shadow weight register that loads while the array computes. A 1-bit swap token travels with the data and promotes shadow to active, so a tile swap costs one cycle. That added 9 cells per PE, about 1%.
The testbench compares every hidden activation and logit with the golden model. The browser visualizer runs a JavaScript copy of the RTL that matches the Verilog trace on all 16,271 frames of one inference.
Results
Cycle counts and value checks come from Icarus Verilog simulation.
The float network scores 96.63% on the 10,000 MNIST test images, and the INT8 model 96.53%. The RTL ran the first 200 images at batch 16, and all 2,000 logits and 9,600 hidden activations matched the golden model.
The 4×4 array needs 16,270 cycles per image at batch 1 and 1,852 at batch 16. At batch 16 that is 13.9 times fewer than one MAC per cycle, a baseline I calculated and did not build. Before the shadow registers, batch 16 took 3,095 cycles.
The same RTL at 8×8 needs 495 cycles at batch 16, 52 times fewer than that baseline, and stays bit-exact on those images.
Yosys and nextpnr placed and routed the 4×4 design for a Lattice ECP5-85k and reported 65.1 MHz. That netlist was incomplete: the testbench loads the weights, so Yosys removed the weight and bias memories and tied every PE weight to zero.
The value checks caught two RTL bugs: every PE row loaded the previous row's weights, and a rounding constant made negative sums unsigned.
Limits and next steps
Nothing here ran on an FPGA. Place and route covered only the 4×4 design, with no pinout or bitstream. That netlist had no weights, so 65.1 MHz is not a valid timing figure.
Cycle counts exclude image loading, 784 cycles per image through the test port. Batch 1 is only 1.58 times better than the baseline, because each tile waits for its weights to load.
Next I would overlap each block's requantize pass with the next preload, an estimated 10 to 15% gain at batch 16.
Ask a question about this project
An AI assistant answers from this site's text. It can be wrong; this page is the source.


