An AI accelerator
on a $25 FPGA

openTPU's instruction set, ported to the Sipeed Tang Nano 20K. Language models run with their weights streamed straight off the SD card, and every result matches the ISA simulator bit for bit.

GW2AR-18 · 20,736 LUT4 83% LUTs · 39/46 BSRAM core 48 MHz (58.2 MHz Fmax) SD 4-bit, 48 MHz, CRC-checked 1 GiB virtual DRAM over 8 MiB SDRAM

It tells stories

Real logs from the board, replayed. Every token reads the whole model image from the SD card, through a 64 KiB line cache in SDRAM, into a core that executes one instruction at a time.


  

Replayed faster than real time; the speeds are in the logs (results). Raw logs: examples/tangnano20k/results/.

The silicon

Where nextpnr placed every cell of the design on the GW2AR-18, and the wires it routed, from the bitstream's own placement (pnr.json). Hover a tile; click a module to light it up.

How it works

openTPU's own microarchitecture needs five times this FPGA. This port keeps the ISA and its exact arithmetic and rebuilds everything under it to fit.

Host PC compiler · tokenizer UART link 2 Mbaud · BL616 GW2AR-18 FPGA lite core · openTPU ISA sequencer MXU (int) VPU fp32 FMA quantizer TMEM · ACT RAM memory system · 1 GiB virtual DRAM page table + TLB · 16 × 64 KiB SD line cache copy-on-write pages · the card is never written SDRAM 8 MiB cache · COW pages · tables SD card model image · 4-bit · CRC16

One multiply-add does everything

A single pipelined fp32 multiply-add serves every vector op: add is a·1+c, multiply is a·b+(−0), and exp2, reciprocal, rsqrt and log2 are the ISA's fixed sequences on it. Row sums keep the ISA's 64 interleaved partials, so the bits match.

Exact integer matmul

MM accumulates int8 / int4 / fp4 / nvfp4 products exactly in 48-bit integers, four rows at a time, then applies the fp32 epilogue — the simulator's result, bit for bit.

The SD card as DRAM

The model image is one file on a FAT card. A page table maps the 1 GiB address space onto it; 64 KiB lines stream into SDRAM with CMD18; anything written gets a copy-on-write page. 46 block RAMs, 8 MiB of SDRAM, and a 300 MB model.

Trust, but verify the card

Every 512-byte block's CRC16 is checked on all four data lines. A bad or stalled block restarts the read from that block; if a block still fails, the host refuses the result instead of printing wrong tokens.

Results

Measured on the board, 2026-10-18: Tang Nano 20K, an SDHC card in 48 MHz high-speed mode, the core at 48 MHz. A token costs the image size over the card's ~10.9 MB/s.

ModelWeightsImageDecodeTokens
stories42M (llama2.c, TinyStories)int847 MiB 0.22 tok/s48/48 = simulator · 47/48 = Hugging Face fp32
SmolLM2-135M-Instructfp4, int8 head100 MiB0.08 tok/s "The capital of France is Paris. It is a city that is known for its"
SmolLM2-360M-Instructfp4, int8 head239 MiB— simulator: 8/8 = Hugging Face, "The capital of France is Paris."

SD card throughput

24 MHz: 4.5–8.5 MB/s · 48 MHz high speed: 10.6–10.9 MB/s, on a 2 GB SDSC card and an SDHC card. sdtune.py finds the clock phase and sampling edge.

Where the time goes

Streaming the weights: the core waits for the card. Prompts prefill four tokens per pass over the weights, so a 37-token chat prompt costs about ten passes.

Verified, layer by layer

The ISA simulator is the reference. Everything below it is checked against it bit for bit.

  1. Random ISA programs on the RTL (Verilator) against the simulator: every VOP, reductions, QACT / QST, MM in four weight formats with every flag.
  2. A SmolLM2-shaped network on the RTL (2 layers, full 49K vocabulary): logits bit-exact in int8, int4, fp4, nvfp4.
  3. The whole virtual board — SDRAM and SD card models, UART over TCP — with the host stack: bit-exact, also with the card model stalling every 5th read and corrupting every 97th block (417 restarts).
  4. On the board: bring-up checks, an ISA softmax bit-exact against the simulator, and the chats above.

Quick start

A prebuilt bitstream is in the repo; building one needs the open-source OSS CAD Suite.

# load the bitstream (SRAM; -f to flash)
openFPGALoader -b tangnano20k boards/tangnano20k/prebuilt/tang_top.fs

# a model image for the card
hf download HuggingFaceTB/SmolLM2-135M-Instruct --local-dir models/SmolLM2-135M-Instruct
python tools/tang/sdimage.py models/SmolLM2-135M-Instruct --wformat fp4 --head-format int8 --out SMOL135.IMG
# copy SMOL135.IMG to a freshly formatted FAT16 / FAT32 / exFAT card, insert it

python tools/tang/bringup.py --port COM6 --image SMOL135.IMG --speed
python tools/tang/sdtune.py  --port COM6           # prints e.g. --sd hs,1,2,1
python tools/tang/chat.py models/SmolLM2-135M-Instruct --port COM6 --image SMOL135.IMG \
    --wformat fp4 --head-format int8 --sd hs,1,2,1

# no board? the whole board in Verilator
bash sim/tang/build.sh && python tools/tang/board_sim_test.py

What fits

Llama-family models with hidden size up to ~1K and head_dim, hidden and FFN in multiples of 64 (zero-padding fixes an odd FFN). TMEM (8K words) and IMEM (512 instructions) are the limits.

What doesn't (yet)

TinyLlama-1.1B and Qwen3-0.6B need ~2× the TMEM this FPGA has; stories110M's decode step is 583 instructions; GPT-Neo models (TinyStories-1M/33M) aren't in the compiler.