# dipenarathod/core-npu architecture

> Architecture diagram of the GitHub repository dipenarathod/core-npu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dipenarathod/core-npu
- Repository: https://github.com/dipenarathod/core-npu

## Overview

#### 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: [`RTL/wb_npu.vhd`](https://github.com/dipenarathod/core-npu/blob/main/RTL/wb_npu.vhd) (Wishbone NPU core), [`Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb`](https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb) (Ada demo applications), [`Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads`](https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads) (wb_npu_helper), [`FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd`](https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd) (NEORV32 FPGA top)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host Firmware"]
  node_apps["Ada demo applications<br/>Ada firmware"]
  node_driver["wb_npu_helper<br/>Ada driver<br/>[wb_npu_helper.ads]"]
  node_address_map["NPU address map<br/>Ada MMIO map"]
  node_layer_orchestration["Layer command routines<br/>Ada implementations"]
  node_model_constants["Embedded model tensors<br/>Ada constants"]
end

subgraph group_npu["NPU Peripheral"]
  node_npu_core["Wishbone NPU core<br/>VHDL peripheral<br/>[wb_npu.vhd]"]
  node_storage_fsm[("Operand/result BRAM &amp; FSM<br/>core subsystem")]
  node_base_ops["Tensor base primitives<br/>VHDL shared IP"]
  node_conv_dense["Conv2D &amp; dense engine<br/>VHDL compute IP"]
  node_activations["Activation engine<br/>VHDL compute IP"]
  node_pooling["Pooling engine<br/>VHDL compute IP"]
  node_simulation["NPU testbench<br/>VHDL simulation<br/>[tb_wb_npu.vhd]"]
end

subgraph group_fpga["FPGA SoC"]
  node_soc_top["NEORV32 FPGA top<br/>VHDL board integration"]
  node_processor_top["NEORV32 processor top<br/>VHDL SoC integration"]
  node_bitstream["Prebuilt ECP5 bitstream<br/>FPGA image"]
end

subgraph group_flow["Model &amp; Build Flow"]
  node_weight_converter["Weight converter<br/>Python tool<br/>[convert_weights.py]"]
  node_firmware_build["Ada RISC-V build<br/>Alire/GNAT + image_gen"]
  node_fpga_build["Diamond FPGA build<br/>Lattice build automation"]
end

node_apps -->|"uses"| node_driver
node_apps -->|"links model data"| node_model_constants
node_driver -->|"addresses via"| node_address_map
node_driver -->|"dispatches layers"| node_layer_orchestration
node_layer_orchestration -->|"MMIO writes, start/poll/read"| node_npu_core
node_npu_core -->|"owns"| node_storage_fsm
node_npu_core -->|"coordinates"| node_base_ops
node_storage_fsm -->|"feeds serialized operands"| node_conv_dense
node_storage_fsm -->|"feeds serialized operands"| node_activations
node_storage_fsm -->|"feeds serialized operands"| node_pooling
node_npu_core -->|"Wishbone peripheral"| node_soc_top
node_processor_top -->|"instantiated in"| node_soc_top
node_weight_converter -->|"generates"| node_model_constants
node_apps -->|"cross-compiled by"| node_firmware_build
node_firmware_build -.->|"UART-loaded onto"| node_processor_top
node_fpga_build -->|"synthesizes"| node_soc_top
node_fpga_build -->|"produces"| node_bitstream
node_simulation -.->|"verifies"| node_npu_core

click node_apps "https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb"
click node_driver "https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads"
click node_address_map "https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_address_map.ads"
click node_layer_orchestration "https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper-dense.adb"
click node_npu_core "https://github.com/dipenarathod/core-npu/blob/main/RTL/wb_npu.vhd"
click node_base_ops "https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_base.vhd"
click node_conv_dense "https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_conv_dense.vhd"
click node_activations "https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_activation.vhd"
click node_pooling "https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_pooling.vhd"
click node_soc_top "https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd"
click node_processor_top "https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ProcessorTop_MinimalBoot.vhd"
click node_bitstream "https://github.com/dipenarathod/core-npu/blob/main/Prebuilt-Bitstream/ECP5-Bitstreams/ECP5EVN_NEORV32_MinimalBoot_impl1.bit"
click node_weight_converter "https://github.com/dipenarathod/core-npu/blob/main/Python-Files/convert_weights.py"
click node_fpga_build "https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/create_neorv32_diamond.tcl"
click node_simulation "https://github.com/dipenarathod/core-npu/blob/main/tb/tb_wb_npu.vhd"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_apps,node_driver,node_address_map,node_layer_orchestration,node_model_constants toneBlue
class node_npu_core,node_storage_fsm,node_base_ops,node_conv_dense,node_activations,node_pooling,node_simulation toneAmber
class node_soc_top,node_processor_top,node_bitstream toneMint
class node_weight_converter,node_firmware_build,node_fpga_build toneRose
```

## Components

### Host Firmware

Ada applications and MMIO driver.

- [Ada demo applications](https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb): Ada firmware · MNIST and integration inference entry points. · `Ada-Files/NPU-Demos/mnist_test_28x28/src/mnist_test_28x28.adb`
- [wb_npu_helper](https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads): Ada driver · Packs tensors, issues commands, polls completion, and reads results. · `Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper.ads`
- [NPU address map](https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_address_map.ads): Ada MMIO map · `Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_address_map.ads`
- [Layer command routines](https://github.com/dipenarathod/core-npu/blob/main/Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper-dense.adb): Ada implementations · Dense, convolution, activation, and pooling orchestration. · `Ada-Files/NPU-Library/wb_npu_helper/src/wb_npu_helper-dense.adb`
- **Embedded model tensors**: Ada constants · Converted weights and tensors compiled into firmware.

### NPU Peripheral

Wishbone-attached serialized tensor accelerator.

- [Wishbone NPU core](https://github.com/dipenarathod/core-npu/blob/main/RTL/wb_npu.vhd): VHDL peripheral · Wishbone slave, registers, tensor windows, BRAM storage, and serialized control FSM. · `RTL/wb_npu.vhd`
- **Operand/result BRAM & FSM**: core subsystem · Stores packed INT8 tensors and serially schedules each operation.
- [Tensor base primitives](https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_base.vhd): VHDL shared IP · Shared tensor, packing, and control primitives. · `RTL/tensor_operations_base.vhd`
- [Conv2D & dense engine](https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_conv_dense.vhd): VHDL compute IP · 3×3 multi-channel convolution, dense, and requantization. · `RTL/tensor_operations_conv_dense.vhd`
- [Activation engine](https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_activation.vhd): VHDL compute IP · ReLU, sigmoid approximation, and two-phase softmax. · `RTL/tensor_operations_activation.vhd`
- [Pooling engine](https://github.com/dipenarathod/core-npu/blob/main/RTL/tensor_operations_pooling.vhd): VHDL compute IP · 2×2 max and average pooling. · `RTL/tensor_operations_pooling.vhd`
- [NPU testbench](https://github.com/dipenarathod/core-npu/blob/main/tb/tb_wb_npu.vhd): VHDL simulation · Hardware simulation centered on the Wishbone NPU testbench. · `tb/tb_wb_npu.vhd`

### FPGA SoC

NEORV32 integration and deployable image.

- [NEORV32 FPGA top](https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ECP5EVN_BoardTop_MinimalBoot.vhd): VHDL board integration · 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](https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ProcessorTop_MinimalBoot.vhd): VHDL SoC integration · `FPGA-Setup/ECP5U5MG-Setup-Files/Part-3-Connecting-the-NPU-to-the-NEORV32/neorv32_ProcessorTop_MinimalBoot.vhd`
- [Prebuilt ECP5 bitstream](https://github.com/dipenarathod/core-npu/blob/main/Prebuilt-Bitstream/ECP5-Bitstreams/ECP5EVN_NEORV32_MinimalBoot_impl1.bit): FPGA image · 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](https://github.com/dipenarathod/core-npu/blob/main/Python-Files/convert_weights.py): Python tool · Converts trained model weights into Ada constant arrays. · `Python-Files/convert_weights.py`
- **Ada RISC-V build**: Alire/GNAT + image_gen · Cross-compiles firmware and produces UART-uploadable executables.
- [Diamond FPGA build](https://github.com/dipenarathod/core-npu/blob/main/FPGA-Setup/ECP5U5MG-Setup-Files/create_neorv32_diamond.tcl): Lattice build automation · Builds the ECP5 board design with pin constraints. · `FPGA-Setup/ECP5U5MG-Setup-Files/create_neorv32_diamond.tcl`

## Connections

- 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
