How sushantgagneja/ultra-low-latency-ml-inference-on-fpga works
This is a low-latency FPGA market-tick inference system with a separate model-training toolchain. In the live path, a host gateway receives Binance ticks, computes metadata, and sends packed data over UDP; ESP32 firmware forwards it over SPI, and FPGA logic extracts features, quantizes them, and runs the BNN before signaling completion to the firmware. The README also documents model training, RTL generation, historical backtesting, and performance auditing. Several internal RTL connections are documented at subsystem level only, so edges use the README as evidence rather than implying unsampled module calls.
Main entry points: main.c Firmware orchestration · tick_parser.v SPI tick parser · hw_quantizer.v Feature quantizer · bnn_top.v Inference top
Components 21
Market gateway
- Tick gateway
scripts/gateway/main.go
ESP32 firmware
- UDP listener
esp32_firmware/main/udp_server.c - Firmware orchestration
esp32_firmware/main/main.c - SPI DMA interface
esp32_firmware/main/spi_interface.c
FPGA inference
- SPI tick parser
rtl/microstructure/tick_parser.v - OFI engine
rtl/microstructure/ofi_engine.v - VWAP engine
rtl/microstructure/vwap_engine.v - Lee-Ready engine
rtl/microstructure/lee_ready.v - Feature quantizer
rtl/microstructure/hw_quantizer.v - Temporal memory
rtl/microstructure/bram_microstructure.v - Inference top
rtl/bnn_top.v - Unrolled BNN
rtl/bnn_core_unrolled.v - XNOR popcount
rtl/xnor_popcount.v
Model pipeline
- Ternary model training
scripts/train_twn_pytorch.py - BookTicker retraining
scripts/retrain_bookticker.py - RTL generator
scripts/generate_bnn_rtl.py - Legacy BNN training
train_bnn_standalone.py
Backtest and audit
- Historical backtest
scripts/historical_backtest.py - Performance audit
monitoring/bnn_trading_monitor.py - Audit records
monitoring/sample_bnn_audit.jsonl
Other components
- Binance feed
Connections 23
- Binance feed → Tick gateway: streams ticks
README.md - Tick gateway → UDP listener: sends UDP
README.md - Firmware orchestration → UDP listener: starts listener
esp32_firmware/main/main.c - UDP listener → Firmware orchestration: queues ticks
README.md - Firmware orchestration → SPI DMA interface: transmits ticks
README.md - SPI DMA interface → SPI tick parser: sends SPI frame
README.md - SPI tick parser → OFI engine: provides tick data
README.md - SPI tick parser → VWAP engine: provides tick data
README.md - SPI tick parser → Lee-Ready engine: provides tick data
README.md - OFI engine → Feature quantizer: provides feature
README.md - VWAP engine → Feature quantizer: provides feature
README.md - Lee-Ready engine → Feature quantizer: provides feature
README.md - Feature quantizer → Temporal memory: updates memory
README.md - Temporal memory → Inference top: provides features
README.md - Inference top → Unrolled BNN: dispatches inference
README.md - Unrolled BNN → XNOR popcount: uses logic
README.md - Inference top → Firmware orchestration: signals completion
README.md - Ternary model training → RTL generator: supplies model
README.md - BookTicker retraining → RTL generator: exports weights
scripts/retrain_bookticker.py - Legacy BNN training → Historical backtest: provides model
scripts/historical_backtest.py - BookTicker retraining → Historical backtest: provides features
scripts/historical_backtest.py - Firmware orchestration → Performance audit: emits audit events
- Performance audit → Audit records: records metrics