# michaela1224/sda_code architecture

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

- Interactive diagram: https://gitdiagram.com/michaela1224/sda_code
- Repository: https://github.com/michaela1224/sda_code

## Overview

SDA_code is an HLS implementation of low-bit stable-diffusion acceleration for edge FPGAs. Its user-facing workflow is a host-driven layer computation: provide activations, weights, bias/scale data and layer parameters, then receive results in DDR. The code supports convolution/matrix-multiply paths and post-processing such as normalization, softmax, GELU and shortcut handling. The sampled top-level excerpt confirms activation extraction and stream-oriented processing, but omits much of the wiring; uncertain stage-to-stage links are therefore left out.

Main entry points: [`block_top.cpp`](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp) (Layer compute top), [`block_top.h`](https://github.com/michaela1224/sda_code/blob/main/block_top.h) (Compute interface), [`sa_tools.h`](https://github.com/michaela1224/sda_code/blob/main/sa_tools.h) (Systolic array), [`load_param.h`](https://github.com/michaela1224/sda_code/blob/main/load_param.h) (Parameter loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Accelerator interface"]
  node_top["Layer compute top<br/>[block_top.cpp]"]
  node_api["Compute interface<br/>[block_top.h]"]
end

subgraph group_compute["Low-bit compute"]
  node_extract["Activation extraction<br/>[block_top.cpp]"]
  node_sa["Systolic array<br/>[sa_tools.h]"]
  node_lowbit["Packed low-bit MAC<br/>[sa_tools.h]"]
  node_conv["Convolution path<br/>[block_top.cpp]"]
  node_mm["Matrix multiply path<br/>[block_top.cpp]"]
end

subgraph group_post["Post-processing"]
  node_norm["Normalization<br/>[block_top.cpp]"]
  node_softmax["Softmax<br/>[block_top.cpp]"]
  node_gelu["GELU / SiLU<br/>[block_top.cpp]"]
  node_shortcut["Shortcut handling<br/>[block_top.cpp]"]
  node_quant["Quantization paths<br/>[block_top.cpp]"]
end

subgraph group_support["Data and stream support"]
  node_param["Parameter loading<br/>[load_param.h]"]
  node_buffers["Layer state buffers<br/>[param_sa.h]"]
  node_streams["Stream routing<br/>[stream_tools.h]"]
  node_config["Hardware parameters<br/>[config.h]"]
end

node_host(("Host / caller"))
node_ddr[("DDR buffers")]

node_host -->|"invokes"| node_api
node_api -->|"declares entry"| node_top
node_ddr -->|"provides buffers"| node_top
node_top -->|"writes results"| node_ddr
node_top -->|"calls extraction"| node_extract
node_top -->|"selects path"| node_conv
node_top -->|"selects path"| node_mm
node_top -->|"routes processing"| node_norm
node_top -->|"routes processing"| node_softmax
node_top -->|"routes processing"| node_gelu
node_top -->|"routes shortcut"| node_shortcut
node_top -->|"routes processing"| node_quant
node_top -->|"loads parameters"| node_param
node_extract -->|"streams activations"| node_sa
node_sa -->|"uses packed MAC"| node_lowbit
node_param -->|"fills buffers"| node_buffers
node_streams -.->|"routes streams"| node_top
node_config -->|"sets dimensions"| node_top

click node_top "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_api "https://github.com/michaela1224/sda_code/blob/main/block_top.h"
click node_extract "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_sa "https://github.com/michaela1224/sda_code/blob/main/sa_tools.h"
click node_lowbit "https://github.com/michaela1224/sda_code/blob/main/sa_tools.h"
click node_conv "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_mm "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_norm "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_softmax "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_gelu "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_shortcut "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_quant "https://github.com/michaela1224/sda_code/blob/main/block_top.cpp"
click node_param "https://github.com/michaela1224/sda_code/blob/main/load_param.h"
click node_buffers "https://github.com/michaela1224/sda_code/blob/main/param_sa.h"
click node_streams "https://github.com/michaela1224/sda_code/blob/main/stream_tools.h"
click node_config "https://github.com/michaela1224/sda_code/blob/main/config.h"

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_top,node_api toneBlue
class node_extract,node_sa,node_lowbit,node_conv,node_mm,node_ddr toneAmber
class node_norm,node_softmax,node_gelu,node_shortcut,node_quant toneMint
class node_param,node_buffers,node_streams,node_config toneRose
class node_host toneIndigo
```

## Components

### Accelerator interface

- [Layer compute top](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [Compute interface](https://github.com/michaela1224/sda_code/blob/main/block_top.h): `block_top.h`

### Low-bit compute

- [Activation extraction](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [Systolic array](https://github.com/michaela1224/sda_code/blob/main/sa_tools.h): `sa_tools.h`
- [Packed low-bit MAC](https://github.com/michaela1224/sda_code/blob/main/sa_tools.h): `sa_tools.h`
- [Convolution path](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [Matrix multiply path](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`

### Post-processing

- [Normalization](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [Softmax](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [GELU / SiLU](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [Shortcut handling](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`
- [Quantization paths](https://github.com/michaela1224/sda_code/blob/main/block_top.cpp): `block_top.cpp`

### Data and stream support

- [Parameter loading](https://github.com/michaela1224/sda_code/blob/main/load_param.h): `load_param.h`
- [Layer state buffers](https://github.com/michaela1224/sda_code/blob/main/param_sa.h): `param_sa.h`
- [Stream routing](https://github.com/michaela1224/sda_code/blob/main/stream_tools.h): `stream_tools.h`
- [Hardware parameters](https://github.com/michaela1224/sda_code/blob/main/config.h): `config.h`

### Other components

- **Host / caller**
- **DDR buffers**

## Connections

- Host / caller → Compute interface: invokes
- Compute interface → Layer compute top: declares entry
- DDR buffers → Layer compute top: provides buffers
- Layer compute top → DDR buffers: writes results
- Layer compute top → Activation extraction: calls extraction
- Layer compute top → Convolution path: selects path
- Layer compute top → Matrix multiply path: selects path
- Layer compute top → Normalization: routes processing
- Layer compute top → Softmax: routes processing
- Layer compute top → GELU / SiLU: routes processing
- Layer compute top → Shortcut handling: routes shortcut
- Layer compute top → Quantization paths: routes processing
- Layer compute top → Parameter loading: loads parameters
- Activation extraction → Systolic array: streams activations
- Systolic array → Packed low-bit MAC: uses packed MAC
- Parameter loading → Layer state buffers: fills buffers
- Stream routing → Layer compute top: routes streams
- Hardware parameters → Layer compute top: sets dimensions
