How dipenarathod/core-npu works
Purpose and System Boundary
Wishbone-NPU is an FPGA-resident, Wishbone B4 NPU peripheral for INT8 Q0.7 CNN/MLP inference. A RISC-V soft core writes packed tensor data and commands through memory-mapped Wishbone registers; the peripheral computes and exposes results. Reusable IP is in RTL/wb_npu.vhd, with its tensor-operation blocks in RTL/tensor_operations_base.vhd and RTL/tensor_operations_conv_dense.vhd.
Hardware NPU Core
RTL/wb_npu.vhd is the architectural entry point and Wishbone-slave boundary. It owns the register/tensor-window interface, opcode-driven control FSM, BRAM-backed operand/result storage, start/done control, and coordination of all operations. The core accepts four INT8 values per 32-bit word; the host is responsible for packing inputs, weights, biases, and reading output.
Compute Stages
The NPU delegates operation families to VHDL blocks:
• Dense and 3×3 multi-channel Conv2D, including requantization: RTL/tensor_operations_conv_dense.vhd.
• ReLU, sigmoid approximation, and two-phase softmax behavior: RTL/tensor_operations_activation.vhd.
• 2×2 max and average pooling: RTL/tensor_operations_pooling.vhd.
• Shared tensor/packing/control primitives: RTL/tensor_operations_base.vhd.
These blocks are controlled serially by one FSM rather than independent parallel engines, making BRAM capacity and FSM throughput central constraints.
FPGA / SoC Integration
The reference target is an ECP5U5MG-85F FPGA running NEORV32. Board-level integration connects the processor XBUS/Wishbone path to the NPU and is represented by FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd and FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ProcessorTop_MinimalBoot.vhd. Pin constraints and Diamond build automation are in FPGA-Setup/ECP5U5MG-Setup-Files/ECP5EVN_NEORV32_MinimalBoot.lpf and FPGA-Setup/ECP5U5MG-Setup-Files/create_neorv32_diamond.tcl. A ready bitstream exists at Prebuilt-Bitstream/ECP5-Bitstreams/ECP5EVN_NEORV32_MinimalBoot_impl1.bit.
Ada Driver and Firmware Entry Points
The host-side abstraction is the Ada wb_npu_helper library. Its top-level interface and address map are Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads and Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_address_map.ads; layer-specific command/data orchestration is split across wb_npu_helper-dense.adb, wb_npu_helper-conv2d.adb, wb_npu_helper-activation.adb, and wb_npu_helper-pooling.adb. This is the key software/hardware boundary: Ada issues MMIO writes, triggers/polls hardware, then consumes result tensors.
Runnable Ada application entry points include Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb, Ada-Files/NPU-Demos/mnist_test_14x14/src/mnist_test_14x14.adb, and Ada-Files/NPU-Demos/final_integration_test/src/final_integration_test.adb. Their .ads model/tensor files embed converted constants into firmware.
Model-to-Device Flow and Runtimes
Python/Keras notebooks train representative models; Python-Files/convert_weights.py converts weights for embedding into Ada constant arrays. Ada projects use Alire/GNAT and RISC-V cross-compilation, with NEORV32 image_gen producing UART-uploadable executables. The runtime requires the external NEORV32 Ada HAL, a specific NEORV32 fork, and an input/output helper library; FPGA synthesis uses Lattice Diamond. Hardware simulation is centered on tb/tb_wb_npu.vhd.
Main entry points: wb_npu.vhd Wishbone NPU core · mnist_test_28x28.adb Ada demo applications · wb_npu_helper.ads wb_npu_helper · neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd NEORV32 FPGA top
Components 18
Host Firmware
Ada applications and MMIO driver.
- Ada demo applications · MNIST and integration inference entry points.
Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb - wb_npu_helper · Packs tensors, issues commands, polls completion, and reads results.
Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads - NPU address map
Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_address_map.ads - Layer command routines · Dense, convolution, activation, and pooling orchestration.
Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper-dense.adb - Embedded model tensors · Converted weights and tensors compiled into firmware.
NPU Peripheral
Wishbone-attached serialized tensor accelerator.
- Wishbone NPU core · Wishbone slave, registers, tensor windows, BRAM storage, and serialized control FSM.
RTL/wb_npu.vhd - Operand/result BRAM & FSM · Stores packed INT8 tensors and serially schedules each operation.
- Tensor base primitives · Shared tensor, packing, and control primitives.
RTL/tensor_operations_base.vhd - Conv2D & dense engine · 3×3 multi-channel convolution, dense, and requantization.
RTL/tensor_operations_conv_dense.vhd - Activation engine · ReLU, sigmoid approximation, and two-phase softmax.
RTL/tensor_operations_activation.vhd - Pooling engine · 2×2 max and average pooling.
RTL/tensor_operations_pooling.vhd - NPU testbench · Hardware simulation centered on the Wishbone NPU testbench.
tb/tb_wb_npu.vhd
FPGA SoC
NEORV32 integration and deployable image.
- NEORV32 FPGA top · Connects processor XBUS/Wishbone to the NPU peripheral.
FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd - NEORV32 processor top
FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ProcessorTop_MinimalBoot.vhd - Prebuilt ECP5 bitstream · Deployable ECP5EVN NEORV32/NPU image.
Prebuilt-Bitstream/ECP5-Bitstreams/ECP5EVN_NEORV32_MinimalBoot_impl1.bit
Model & Build Flow
Model conversion, compilation, and FPGA tooling.
- Weight converter · Converts trained model weights into Ada constant arrays.
Python-Files/convert_weights.py - Ada RISC-V build · Cross-compiles firmware and produces UART-uploadable executables.
- Diamond FPGA build · Builds the ECP5 board design with pin constraints.
FPGA-Setup/ECP5U5MG-Setup-Files/create_neorv32_diamond.tcl
Connections 18
- Ada demo applications → wb_npu_helper: uses
- Ada demo applications → Embedded model tensors: links model data
- wb_npu_helper → NPU address map: addresses via
- wb_npu_helper → Layer command routines: dispatches layers
- Layer command routines → Wishbone NPU core: MMIO writes, start/poll/read
- Wishbone NPU core → Operand/result BRAM & FSM: owns
- Wishbone NPU core → Tensor base primitives: coordinates
- Operand/result BRAM & FSM → Conv2D & dense engine: feeds serialized operands
- Operand/result BRAM & FSM → Activation engine: feeds serialized operands
- Operand/result BRAM & FSM → Pooling engine: feeds serialized operands
- Wishbone NPU core → NEORV32 FPGA top: Wishbone peripheral
- NEORV32 processor top → NEORV32 FPGA top: instantiated in
- Weight converter → Embedded model tensors: generates
- Ada demo applications → Ada RISC-V build: cross-compiled by
- Ada RISC-V build → NEORV32 processor top: UART-loaded onto
- Diamond FPGA build → NEORV32 FPGA top: synthesizes
- Diamond FPGA build → Prebuilt ECP5 bitstream: produces
- NPU testbench → Wishbone NPU core: verifies