# suchuankai/cnn-hw-accelerator architecture

> Architecture diagram of the GitHub repository suchuankai/cnn-hw-accelerator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suchuankai/cnn-hw-accelerator
- Repository: https://github.com/suchuankai/cnn-hw-accelerator

## Overview

##### Project type and purpose
- This is a hardware-accelerated CNN inference project (a mixed-signal/software stack) that implements the first Conv-ReLU-MaxPool layer of a quantized Fashion-MNIST model in RTL, inspired by the Eyeriss architecture.
- Top-level folders:
- software – quantization, model prep, data generators
- hardware – RTL for “no_clock_gating” and “clock_gating” variants, simulation scripts, synthesis TCL
- unit test – isolated block-level verilog tests (e.g., PE_array, DualSram)

##### File structure
- hardware/… contains two major variants:
a) no_clock_gating
b) clock_gating
Within each:
- function_sim – behavioral Verilog + testbench + data files
- gate_sim – post-synthesis simulation files + SDF + testbench
- syn_file – synthesis constraints (Top.sdc, dc_syn.tcl, Top_syn.ddc)
- Major RTL submodules under function_sim:
- FIFO (handles 64-bit ifmap buffering)
- PE_array (9-PE systolic layout, each PE does MAC)
- psumBuf (accumulates partial sums, applies ReLU + right-shift quantization, does horizontal max-pool)
- convBuf (buffers two rows of 4-wide outputs, does vertical max-pool)
- weightBuf, biasBuf, controller, rowSelect, rowRf, demux1_3
- software/…:
- gen.py, padding.py, quantilize.ipynb produce padded ifmap, quantized weights, bias, model files (.txt, .dat)

##### README for additional insights
- Schedule chart: how many cycles per convolution window

##### Detail without over-fragmenting
- Nine RTL modules as distinct blocks
- Host-to-RTL interaction (data files → testbench)
- Cycle counts or quantization parameters near relevant blocks

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Software Host
    SW["Software Host\n(PyTorch, Python)"]:::software
    SW -->|"generates .txt/.dat"| TopNCG["Top (no_clk_gating)"]:::compute
    SW -->|"generates .txt/.dat"| TopCG["Top (clk_gating)"]:::compute

    %% Hardware Pipeline
    subgraph "Hardware Pipeline"
        FIFO["FIFO (ifmap buffer)"]:::buffer
        WeightBuf["WeightBuf"]:::buffer
        BiasBuf["BiasBuf"]:::buffer
        PE_Array["PE_Array\n(9 MAC units)"]:::compute
        PsumBuf["PsumBuf\n(ReLU + horiz max-pool)"]:::compute
        ConvBuf["ConvBuf\n(vert max-pool)"]:::compute
        Output["Output Reg / Checker"]:::compute

        FIFO -->|"64-bit window"| PE_Array
        WeightBuf -->|"8-bit weights"| PE_Array
        PE_Array -->|"partial sums"| PsumBuf
        PsumBuf -->|"pooled rows"| ConvBuf
        ConvBuf -->|"pooled outputs"| Output
    end

    %% Controller
    Controller["Controller\n(clock, reset,\ncontrol signals)"]:::control
    Controller -.-> FIFO
    Controller -.-> WeightBuf
    Controller -.-> BiasBuf
    Controller -.-> PE_Array
    Controller -.-> PsumBuf
    Controller -.-> ConvBuf
    Controller -.-> Output

    %% Click Events
    click SW "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/software/gen.py"
    click SW "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/software/padding.py"
    click SW "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/software/quantilize.ipynb"
    click TopNCG "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/Top.v"
    click TopCG "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/Top.v"
    click FIFO "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/FIFO.v"
    click FIFO "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/FIFO.v"
    click WeightBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/weightBuf.v"
    click WeightBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/weightBuf.v"
    click BiasBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/biasBuf.v"
    click BiasBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/biasBuf.v"
    click PE_Array "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/PE_array.v"
    click PE_Array "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/PE_array.v"
    click PsumBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/psumBuf.v"
    click PsumBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/psumBuf.v"
    click ConvBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/convBuf.v"
    click ConvBuf "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/convBuf.v"
    click Controller "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/no_clock_gating/function_sim/controller.v"
    click Controller "https://github.com/suchuankai/cnn-hw-accelerator/blob/main/hardware/clock_gating/function_sim/controller.v"

    %% Styles
    classDef software fill:#cccccc,stroke:#333,stroke-width:1px
    classDef compute fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef buffer fill:#98FB98,stroke:#333,stroke-width:1px
    classDef control fill:#FFA500,stroke:#333,stroke-width:1px
```
