# qshen3/cnn-fpga architecture

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

- Interactive diagram: https://gitdiagram.com/qshen3/cnn-fpga
- Repository: https://github.com/qshen3/cnn-fpga

## Overview

This repository provides Verilog modules for CNN inference on FPGA, rather than a complete training or deployment system. The documented example wires convolution, max pooling, optional ReLU activation, and fully connected layers into a classification path; average pooling is another documented feature. The README describes the modules as fully parallel and without pipelining. No source excerpts were available, so the internal relationships of the arithmetic and convolution helper modules are not asserted; workflow edges reflect only the README example.

Main entry points: [`src/Conv2d.v`](https://github.com/qshen3/cnn-fpga/blob/master/src/Conv2d.v) (2D Convolution), [`src/Max_pool.v`](https://github.com/qshen3/cnn-fpga/blob/master/src/Max_pool.v) (Max Pooling), [`src/Relu_activation.v`](https://github.com/qshen3/cnn-fpga/blob/master/src/Relu_activation.v) (ReLU Activation), [`src/FullConnect.v`](https://github.com/qshen3/cnn-fpga/blob/master/src/FullConnect.v) (Fully Connected)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_convolution["Convolution"]
  node_conv2d["2D Convolution<br/>[Conv2d.v]"]
  node_conv_kernel["Convolution Kernel<br/>[ConvKernel.v]"]
end

subgraph group_feature_ops["Feature Operations"]
  node_max_pool["Max Pooling<br/>[Max_pool.v]"]
  node_avg_pool["Average Pooling<br/>[Avg_pool.v]"]
  node_relu_activation["ReLU Activation<br/>[Relu_activation.v]"]
end

subgraph group_classifier["Classification"]
  node_full_connect["Fully Connected<br/>[FullConnect.v]"]
end

subgraph group_primitives["Arithmetic Primitives"]
  node_max_primitive["Maximum Primitive<br/>[Max.v]"]
  node_avg_primitive["Average Primitive<br/>[Avg.v]"]
  node_relu_primitive["ReLU Primitive<br/>[Relu.v]"]
  node_mult["Multiplier<br/>[Mult.v]"]
end

node_input(("Feature Input"))
node_result(("Classification Result"))

node_input -->|"provides data"| node_conv2d
node_conv2d -->|"feeds features"| node_max_pool
node_max_pool -->|"feeds features"| node_relu_activation
node_relu_activation -->|"feeds next layer"| node_conv2d
node_conv2d -->|"feeds features"| node_max_pool
node_max_pool -->|"feeds features"| node_relu_activation
node_relu_activation -->|"feeds features"| node_full_connect
node_full_connect -->|"feeds next layer"| node_full_connect
node_full_connect -->|"produces result"| node_result

click node_conv2d "https://github.com/qshen3/cnn-fpga/blob/master/src/Conv2d.v"
click node_conv_kernel "https://github.com/qshen3/cnn-fpga/blob/master/src/ConvKernel.v"
click node_max_pool "https://github.com/qshen3/cnn-fpga/blob/master/src/Max_pool.v"
click node_avg_pool "https://github.com/qshen3/cnn-fpga/blob/master/src/Avg_pool.v"
click node_relu_activation "https://github.com/qshen3/cnn-fpga/blob/master/src/Relu_activation.v"
click node_full_connect "https://github.com/qshen3/cnn-fpga/blob/master/src/FullConnect.v"
click node_max_primitive "https://github.com/qshen3/cnn-fpga/blob/master/src/Max.v"
click node_avg_primitive "https://github.com/qshen3/cnn-fpga/blob/master/src/Avg.v"
click node_relu_primitive "https://github.com/qshen3/cnn-fpga/blob/master/src/Relu.v"
click node_mult "https://github.com/qshen3/cnn-fpga/blob/master/src/Mult.v"

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_conv2d,node_conv_kernel toneBlue
class node_max_pool,node_avg_pool,node_relu_activation toneAmber
class node_full_connect toneMint
class node_max_primitive,node_avg_primitive,node_relu_primitive,node_mult toneRose
class node_input,node_result toneIndigo
```

## Components

### Convolution

- [2D Convolution](https://github.com/qshen3/cnn-fpga/blob/master/src/Conv2d.v): `src/Conv2d.v`
- [Convolution Kernel](https://github.com/qshen3/cnn-fpga/blob/master/src/ConvKernel.v): `src/ConvKernel.v`

### Feature Operations

- [Max Pooling](https://github.com/qshen3/cnn-fpga/blob/master/src/Max_pool.v): `src/Max_pool.v`
- [Average Pooling](https://github.com/qshen3/cnn-fpga/blob/master/src/Avg_pool.v): `src/Avg_pool.v`
- [ReLU Activation](https://github.com/qshen3/cnn-fpga/blob/master/src/Relu_activation.v): `src/Relu_activation.v`

### Classification

- [Fully Connected](https://github.com/qshen3/cnn-fpga/blob/master/src/FullConnect.v): `src/FullConnect.v`

### Arithmetic Primitives

- [Maximum Primitive](https://github.com/qshen3/cnn-fpga/blob/master/src/Max.v): `src/Max.v`
- [Average Primitive](https://github.com/qshen3/cnn-fpga/blob/master/src/Avg.v): `src/Avg.v`
- [ReLU Primitive](https://github.com/qshen3/cnn-fpga/blob/master/src/Relu.v): `src/Relu.v`
- [Multiplier](https://github.com/qshen3/cnn-fpga/blob/master/src/Mult.v): `src/Mult.v`

### Other components

- **Feature Input**
- **Classification Result**

## Connections

- Feature Input → 2D Convolution: provides data (evidence: `README.md`)
- 2D Convolution → Max Pooling: feeds features (evidence: `README.md`)
- Max Pooling → ReLU Activation: feeds features (evidence: `README.md`)
- ReLU Activation → 2D Convolution: feeds next layer (evidence: `README.md`)
- 2D Convolution → Max Pooling: feeds features (evidence: `README.md`)
- Max Pooling → ReLU Activation: feeds features (evidence: `README.md`)
- ReLU Activation → Fully Connected: feeds features (evidence: `README.md`)
- Fully Connected → Fully Connected: feeds next layer (evidence: `README.md`)
- Fully Connected → Classification Result: produces result (evidence: `README.md`)
