# rohankiani/risc-v-tinyml-accelerator architecture

> Architecture diagram of the GitHub repository rohankiani/risc-v-tinyml-accelerator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohankiani/risc-v-tinyml-accelerator
- Repository: https://github.com/rohankiani/risc-v-tinyml-accelerator

## Overview

This repository implements an FPGA TinyML inference system: a RISC-V processor starts and waits for a serialized INT8 MLP accelerator, which uses on-chip parameter and input memories. The software model provides quantized reference inference and hardware initialization data. The README documents the main integration and dataflow; RTL excerpts were not provided, so internal hardware-module connections are not asserted.

Main entry points: [`rtl/accelerator/MLP_top.sv`](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/MLP_top.sv) (MLP controller), [`software/python_model.py`](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/software/python_model.py) (Quantized model), [`rtl/top/risc_v_processor.sv`](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/top/risc_v_processor.sv) (Processor integration), [`rtl/risc-v/instruction_decoder.sv`](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/instruction_decoder.sv) (Instruction decode)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model and reference"]
  node_python["Quantized model<br/>[python_model.py]"]
end

subgraph group_cpu["RISC-V processor"]
  node_cpu_top["Processor integration"]
  node_decode["Instruction decode"]
  node_control["Pipeline control<br/>[control_unit.sv]"]
  node_alu["ALU datapath<br/>[ALU.sv]"]
  node_registers["Register file<br/>[register_file.sv]"]
  node_program["Instruction execution<br/>[instruction_mem.sv]"]
end

subgraph group_accelerator["TinyML accelerator"]
  node_mlp["MLP controller<br/>[MLP_top.sv]"]
  node_address["Address generation<br/>[addr_gen.sv]"]
  node_mac["INT8 MAC<br/>[MAC_unit.sv]"]
  node_requant["Requantization<br/>[requantizer.sv]"]
end

subgraph group_memory["On-chip memories"]
  node_input_mem[("Input BRAM<br/>[input_bram.xci]")]
  node_weight_mem[("Weight BRAM<br/>[weights_bram.xci]")]
  node_bias_mem[("Bias BRAM<br/>[bias_bram.xci]")]
end

node_engineer(("System user"))
node_har_data["UCI-HAR data<br/>[train.csv]"]

node_engineer -->|"prepares model"| node_python
node_har_data -->|"trains and evaluates"| node_python
node_python -->|"exports input data"| node_input_mem
node_python -->|"exports weights"| node_weight_mem
node_python -->|"exports biases"| node_bias_mem
node_program -->|"fetches instructions"| node_decode
node_decode -->|"starts on custom instruction"| node_mlp
node_control -->|"stalls during execution"| node_cpu_top
node_mlp -->|"reads input"| node_input_mem
node_mlp -->|"reads weights"| node_weight_mem
node_mlp -->|"reads biases"| node_bias_mem
node_mlp -->|"signals completion and result"| node_cpu_top
node_cpu_top -->|"selects accelerator result"| node_alu
node_alu -->|"writes back result"| node_registers

click node_har_data "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/dataset/UCI-HAR_dataset/train.csv"
click node_python "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/software/python_model.py"
click node_cpu_top "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/top/risc_v_processor.sv"
click node_decode "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/instruction_decoder.sv"
click node_control "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/control_unit.sv"
click node_alu "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/ALU.sv"
click node_registers "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/register_file.sv"
click node_program "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/instruction_mem.sv"
click node_mlp "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/MLP_top.sv"
click node_address "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/addr_gen.sv"
click node_mac "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/MAC_unit.sv"
click node_requant "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/requantizer.sv"
click node_input_mem "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/ip/input_bram/input_bram.xci"
click node_weight_mem "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/ip/weights_bram/weights_bram.xci"
click node_bias_mem "https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/ip/bias_bram/bias_bram.xci"

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_python,node_engineer toneBlue
class node_cpu_top,node_decode,node_control,node_alu,node_registers,node_program toneAmber
class node_mlp,node_address,node_mac,node_requant toneMint
class node_input_mem,node_weight_mem,node_bias_mem toneRose
class node_har_data toneTeal
```

## Components

### Model and reference

- [Quantized model](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/software/python_model.py): `software/python_model.py`

### RISC-V processor

- [Processor integration](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/top/risc_v_processor.sv): `rtl/top/risc_v_processor.sv`
- [Instruction decode](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/instruction_decoder.sv): `rtl/risc-v/instruction_decoder.sv`
- [Pipeline control](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/control_unit.sv): `rtl/risc-v/control_unit.sv`
- [ALU datapath](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/ALU.sv): `rtl/risc-v/ALU.sv`
- [Register file](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/register_file.sv): `rtl/risc-v/register_file.sv`
- [Instruction execution](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/risc-v/instruction_mem.sv): `rtl/risc-v/instruction_mem.sv`

### TinyML accelerator

- [MLP controller](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/MLP_top.sv): `rtl/accelerator/MLP_top.sv`
- [Address generation](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/addr_gen.sv): `rtl/accelerator/addr_gen.sv`
- [INT8 MAC](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/MAC_unit.sv): `rtl/accelerator/MAC_unit.sv`
- [Requantization](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/rtl/accelerator/requantizer.sv): `rtl/accelerator/requantizer.sv`

### On-chip memories

- [Input BRAM](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/ip/input_bram/input_bram.xci): `ip/input_bram/input_bram.xci`
- [Weight BRAM](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/ip/weights_bram/weights_bram.xci): `ip/weights_bram/weights_bram.xci`
- [Bias BRAM](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/ip/bias_bram/bias_bram.xci): `ip/bias_bram/bias_bram.xci`

### Other components

- **System user**
- [UCI-HAR data](https://github.com/rohankiani/risc-v-tinyml-accelerator/blob/main/dataset/UCI-HAR_dataset/train.csv): `dataset/UCI-HAR_dataset/train.csv`

## Connections

- System user → Quantized model: prepares model (evidence: `README.md`)
- UCI-HAR data → Quantized model: trains and evaluates (evidence: `README.md`)
- Quantized model → Input BRAM: exports input data (evidence: `README.md`)
- Quantized model → Weight BRAM: exports weights (evidence: `README.md`)
- Quantized model → Bias BRAM: exports biases (evidence: `README.md`)
- Instruction execution → Instruction decode: fetches instructions (evidence: `README.md`)
- Instruction decode → MLP controller: starts on custom instruction (evidence: `README.md`)
- Pipeline control → Processor integration: stalls during execution (evidence: `README.md`)
- MLP controller → Input BRAM: reads input (evidence: `README.md`)
- MLP controller → Weight BRAM: reads weights (evidence: `README.md`)
- MLP controller → Bias BRAM: reads biases (evidence: `README.md`)
- MLP controller → Processor integration: signals completion and result (evidence: `README.md`)
- Processor integration → ALU datapath: selects accelerator result (evidence: `README.md`)
- ALU datapath → Register file: writes back result (evidence: `README.md`)
