lodolite-livive-net

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, test, and benchmark

# 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.

Public constants

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)

Architecture

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.

Schedulers

src/scheduler.rs provides two allocation-free drivers over caller-owned buffers:

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.

Deviations from concept.md

docs/DECISIONS.md is authoritative where it disagrees with concept.md. The main deliberate deviations are:

  1. 47 compute cycles come from an explicit south output-pin register, not from 46 pipeline ticks. Reported total-cycle and virtual-time figures include weight load (one 16-tick tile load for A/B, 64 loads for C); compute-only figures are shown alongside them.
  2. src/core.rs is named src/mac.rs so it does not shadow the core crate under no_std.
  3. Per-core footprint is 8 bytes (not ~12); the full grid is about 2 KiB. The original “~12 bytes / ~3 KB” text was approximate.
  4. No saturation is implemented or reachable. The specification’s use of “saturation” is treated as exercising extreme values; the accumulator bound is 16 * 128 * 128 = 262_144, which fits in i32.
  5. Scenario B uses valid padding (62 × 62 output), which is what yields 241 output tiles.
  6. Grayscale u8 → i8 mapping is p as i16 - 128, applied by the caller or benchmark.

See docs/DECISIONS.md for the full contract and rationale.