Deterministic, zero-allocation (#![no_std]) Rust simulation of a 256-core
(16 × 16) weight-stationary systolic NPU clocked at 500 MHz (0.256 TOPS). Built
as a transparent, cycle-accurate state machine to inspect INT8 wavefronts,
pipeline utilization, and quantization behavior.
The crate has zero dependencies, forbids unsafe, and every clock edge is a
pure state transition. Integration tests and benchmarks are separate crates and
may use std.
# Build the no_std library
cargo build
# Run unit + integration tests (debug and optimized)
cargo test
cargo test --release
# Lints and formatting
cargo fmt --check
cargo clippy --all-targets -- -D warnings
# Verify the portable no_std target
cargo build --target wasm32-unknown-unknown
# Run the manual workload benchmark table
cargo bench --bench workloads
The benchmark target is declared with harness = false and prints a table
covering a small dense GEMM, a 3×3 valid convolution, and a larger GEMM. It
validates every simulator result against a naive scalar i32 reference once
before timing, warms up, and reports the median of five runs.
These are defined once in src/lib.rs and re-used everywhere else.
| Constant | Value | Meaning |
|---|---|---|
DIM |
16 | Edge length of the square array (rows and columns) |
CLOCK_HZ |
500,000,000 | Virtual clock frequency (500 MHz) |
CYCLE_NS |
2.0 | Nanoseconds per virtual cycle |
MACS_PER_CYCLE |
256 | Raw array MACs per tick (DIM * DIM) |
LOAD_CYCLES |
16 | Ticks to shift a full weight tile into the array |
FILL_CYCLES |
15 | Pipeline fill ticks for one compute wave (DIM - 1) |
COMPUTE_CYCLES |
47 | Compute ticks per tile, including the output-pin stage (3 * DIM - 1) |
TILE_COMPUTE_CYCLES |
47 | Alias of COMPUTE_CYCLES |
TILE_TOTAL_CYCLES |
63 | Weight load + compute for one tile (4 * DIM - 1) |
The simulated NPU is a 16 × 16 grid of identical 8-byte MacCore finite-state
machines. Each core holds an INT8 activation latch, a stationary INT8 weight,
and an i32 partial-sum accumulator.
k; column = output channel n. Core
(k, n) parks weight B[k][n] and the array computes
C[m][n] = Σ_k A[m][k] * B[k][n].i8 values. Partial sums flow north →
south as i32 values, exiting through a south output-pin register.VirtualNpu::step snapshots the entire core grid
before committing any register, so no value can cross more than one wire in a
tick. This makes wavefronts exactly inspectable.t, south_outputs()[n] holds C[m][n]
for m = t - 16 - n when 0 <= m < 16. The last useful output is ready after
tick 46, hence 47 compute ticks per tile.useful_macs counts MACs (a full 16 × 16 × 16 tile is 4096,
not 8192).src/scheduler.rs provides two allocation-free drivers over caller-owned
buffers:
gemm_i8(npu, a, b, c, m, n, k) — row-major m×k by k×n into an m×n
accumulator. Tiling order is K-tile → N-tile → M-tile, so each weight tile is
loaded once and reused across all M tiles. Dimensions need not be multiples of
16; out-of-range reads are zero and out-of-range writes are skipped.conv3x3(npu, img, kernel, out, h, w) — valid (no) padding, stride 1, 3×3
convolution lowered to implicit im2col. K = 9 is padded to 16 and N = 1
to 16; one weight tile is loaded and output positions are processed in tiles
of 16. The output is (h - 2) × (w - 2), row-major.Both schedulers reset the datapath before each tile’s compute phase, leaving
stationary weights intact. They report only real (padding-excluded) MACs:
valid_m × valid_n × valid_k per GEMM tile and valid_positions × 9 per
convolution tile, so a fully-populated 16 × 16 × 16 GEMM tile contributes 4096.
concept.mddocs/DECISIONS.md is authoritative where it disagrees with concept.md. The
main deliberate deviations are:
src/core.rs is named src/mac.rs so it does not shadow the core
crate under no_std.16 * 128 * 128 = 262_144, which fits in i32.u8 → i8 mapping is p as i16 - 128, applied by the caller or
benchmark.See docs/DECISIONS.md for the full contract and rationale.