How fesens/opentpu works
openTPU is an open-source AI accelerator stack for running language models on a PCIe FPGA card, with a bit-exact simulator and kernel compiler. The principal workflow is a user request through host chat and model generation, into compiled accelerator programs and the board runtime, which returns generated tokens. Model families, quantized weights, MoE expert offload, diagnostics, and calibration are meaningful supporting capabilities. The README documents the overall stack; source-index references and excerpts support internal links. The hardware RTL and some host routes are not present in the supplied tree, so those connections are omitted.
Main entry points: generate.py Token generation · qwen3.py Dense models · board.py Board driver · kernels Accelerator kernels
Components 22
Models and kernels
- Token generation
opentpu/llm/generate.py - Dense models
opentpu/llm/qwen3.py - Hybrid models
opentpu/llm/qwen35.py - Gemma 4
opentpu/llm/gemma4.py - MoE routing
opentpu/llm/moe.py - Accelerator kernels
opentpu/kernels
Kernel compilation
- Kernel language
opentpu/language.py - Compiler
opentpu/compiler.py - Instruction set
opentpu/isa.py
Host and device
- Chat interface
opentpu/host/chat.py - Execution runtime
opentpu/runtime.py - Board driver
opentpu/host/board.py - Expert offload
opentpu/host/offload.py - DDR calibration
opentpu/host/selfcal.py - Tracing and inspection
opentpu/lens.py
Simulation and formats
- Weight quantization
opentpu/quant.py - Model formats
opentpu/llm/formats.py - ISA simulator
opentpu/isasim.py - FP32 arithmetic
opentpu/fp32.py
Other components
- User
- FPGA card
- Generated tokens
Connections 26
- User → Chat interface: submits prompt
- Chat interface → Token generation: requests generation
- Token generation → Dense models: runs model
opentpu/llm/generate.py - Token generation → Hybrid models: runs model
opentpu/llm/qwen35.py - Token generation → Gemma 4: runs model
opentpu/llm/gemma4.py - Dense models → Accelerator kernels: uses kernels
opentpu/llm/qwen3.py - Hybrid models → Accelerator kernels: uses kernels
opentpu/llm/qwen35.py - Gemma 4 → Accelerator kernels: uses kernels
opentpu/llm/gemma4.py - Dense models → Model formats: resolves formats
opentpu/llm/qwen3.py - Gemma 4 → Model formats: resolves formats
opentpu/llm/gemma4.py - Dense models → Weight quantization: quantizes weights
opentpu/llm/qwen3.py - Hybrid models → MoE routing: uses routing
opentpu/llm/qwen35.py - MoE routing → Expert offload: requests experts
opentpu/llm/moe.py - Accelerator kernels → Kernel language: expressed in
opentpu/kernels/lib.py - Kernel language → Compiler: traced by
opentpu/language.py - Compiler → Instruction set: emits instructions
opentpu/compiler.py - Instruction set → ISA simulator: executed by
opentpu/isasim.py - ISA simulator → FP32 arithmetic: uses arithmetic
opentpu/isasim.py - Token generation → Execution runtime: launches programs
- Execution runtime → Board driver: executes on
- Board driver → FPGA card: transfers over PCIe
- FPGA card → Generated tokens: returns results
- Board driver → Expert offload: services expert requests
opentpu/host/offload.py - Board driver → DDR calibration: supports calibration
opentpu/host/selfcal.py - Tracing and inspection → ISA simulator: inspects execution
opentpu/lens.py - Tracing and inspection → Execution runtime: inspects runtime
opentpu/lens.py