# hqbaoanh/neural-network-operator-optimization architecture

> Architecture diagram of the GitHub repository hqbaoanh/neural-network-operator-optimization, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hqbaoanh/neural-network-operator-optimization
- Repository: https://github.com/hqbaoanh/neural-network-operator-optimization

## Overview

This is a C++ GEMM optimization library: callers provide row-major float matrices and choose among progressively optimized kernels, from a naive loop through cache blocking and packed SIMD. The principal workflow is kernel selection, then computation; threaded variants divide work across threads, while the SIMD path packs panels and dispatches to an architecture-specific micro-kernel. The graph includes the documented ARM NEON and x86 AVX2 alternatives. Evidence is limited to the README and sampled source/index references; no ONNX Runtime integration is implemented in the shown runtime.

Main entry points: [`include/gemm.h`](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/include/gemm.h) (GEMM API), [`src/kernels.cpp`](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/kernels.cpp) (Kernel registry), [`src/gemm_simd.cpp`](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_simd.cpp) (Packed GEMM), [`src/gemm_blocked_mt.cpp`](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked_mt.cpp) (Threaded blocked)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_stages["Kernel stages"]
  node_naive["Naive kernel<br/>[gemm_naive.cpp]"]
  node_reordered["Reordered kernel<br/>[gemm_reordered.cpp]"]
  node_blocked["Blocked kernel<br/>[gemm_blocked.cpp]"]
  node_blockedrows["Blocked row worker<br/>[gemm_blocked.cpp]"]
  node_blockedmt["Threaded blocked"]
end

subgraph group_simd["Packed SIMD"]
  node_simd["Packed GEMM<br/>[gemm_simd.cpp]"]
  node_neon["NEON micro-kernel<br/>[microkernel_neon.h]"]
  node_avx2["AVX2 micro-kernel<br/>[microkernel_avx2.h]"]
  node_simdmt["Threaded SIMD<br/>[gemm_simd.cpp]"]
end

subgraph group_runtime["Kernel runtime"]
  node_api["GEMM API<br/>[gemm.h]"]
  node_threads["Thread helpers<br/>[threads.cpp]"]
  node_internals["Kernel internals<br/>[gemm_internal.h]"]
  node_registry["Kernel registry<br/>[kernels.cpp]"]
end

node_caller(("GEMM caller"))

node_caller -->|"calls"| node_api
node_api -->|"declares"| node_naive
node_api -->|"declares"| node_reordered
node_api -->|"declares"| node_blocked
node_api -->|"declares"| node_blockedmt
node_api -->|"declares"| node_simd
node_api -->|"declares"| node_simdmt
node_registry -->|"registers"| node_naive
node_registry -->|"registers"| node_reordered
node_registry -->|"registers"| node_blocked
node_registry -->|"registers"| node_blockedmt
node_registry -->|"registers"| node_simd
node_registry -->|"registers"| node_simdmt
node_blocked -->|"calls"| node_blockedrows
node_blockedmt -->|"dispatches"| node_blockedrows
node_blockedmt -->|"dispatches"| node_threads
node_simdmt -->|"calls"| node_simd
node_simdmt -->|"dispatches"| node_threads
node_simd -->|"calls"| node_neon
node_simd -->|"calls"| node_avx2
node_blocked -->|"uses"| node_internals
node_blockedmt -->|"uses"| node_internals
node_simd -->|"uses"| node_internals
node_threads -->|"uses"| node_internals

click node_api "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/include/gemm.h"
click node_naive "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_naive.cpp"
click node_reordered "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_reordered.cpp"
click node_blocked "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked.cpp"
click node_blockedrows "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked.cpp"
click node_blockedmt "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked_mt.cpp"
click node_simd "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_simd.cpp"
click node_neon "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/microkernel_neon.h"
click node_avx2 "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/microkernel_avx2.h"
click node_simdmt "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_simd.cpp"
click node_threads "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/threads.cpp"
click node_internals "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_internal.h"
click node_registry "https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/kernels.cpp"

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_naive,node_reordered,node_blocked,node_blockedrows,node_blockedmt toneBlue
class node_simd,node_neon,node_avx2,node_simdmt toneAmber
class node_api,node_threads,node_internals,node_registry toneMint
class node_caller toneIndigo
```

## Components

### Kernel stages

- [Naive kernel](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_naive.cpp): `src/gemm_naive.cpp`
- [Reordered kernel](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_reordered.cpp): `src/gemm_reordered.cpp`
- [Blocked kernel](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked.cpp): `src/gemm_blocked.cpp`
- [Blocked row worker](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked.cpp): `src/gemm_blocked.cpp`
- [Threaded blocked](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_blocked_mt.cpp): `src/gemm_blocked_mt.cpp`

### Packed SIMD

- [Packed GEMM](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_simd.cpp): `src/gemm_simd.cpp`
- [NEON micro-kernel](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/microkernel_neon.h): `src/microkernel_neon.h`
- [AVX2 micro-kernel](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/microkernel_avx2.h): `src/microkernel_avx2.h`
- [Threaded SIMD](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_simd.cpp): `src/gemm_simd.cpp`

### Kernel runtime

- [GEMM API](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/include/gemm.h): `include/gemm.h`
- [Thread helpers](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/threads.cpp): `src/threads.cpp`
- [Kernel internals](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/gemm_internal.h): `src/gemm_internal.h`
- [Kernel registry](https://github.com/hqbaoanh/neural-network-operator-optimization/blob/main/src/kernels.cpp): `src/kernels.cpp`

### Other components

- **GEMM caller**

## Connections

- GEMM caller → GEMM API: calls (evidence: `README.md`)
- GEMM API → Naive kernel: declares (evidence: `include/gemm.h`)
- GEMM API → Reordered kernel: declares (evidence: `include/gemm.h`)
- GEMM API → Blocked kernel: declares (evidence: `include/gemm.h`)
- GEMM API → Threaded blocked: declares (evidence: `include/gemm.h`)
- GEMM API → Packed GEMM: declares (evidence: `include/gemm.h`)
- GEMM API → Threaded SIMD: declares (evidence: `include/gemm.h`)
- Kernel registry → Naive kernel: registers (evidence: `src/kernels.cpp`)
- Kernel registry → Reordered kernel: registers (evidence: `src/kernels.cpp`)
- Kernel registry → Blocked kernel: registers (evidence: `src/kernels.cpp`)
- Kernel registry → Threaded blocked: registers (evidence: `src/kernels.cpp`)
- Kernel registry → Packed GEMM: registers (evidence: `src/kernels.cpp`)
- Kernel registry → Threaded SIMD: registers (evidence: `src/kernels.cpp`)
- Blocked kernel → Blocked row worker: calls (evidence: `src/gemm_blocked.cpp`)
- Threaded blocked → Blocked row worker: dispatches (evidence: `src/gemm_blocked_mt.cpp`)
- Threaded blocked → Thread helpers: dispatches (evidence: `src/gemm_blocked_mt.cpp`)
- Threaded SIMD → Packed GEMM: calls (evidence: `src/gemm_simd.cpp`)
- Threaded SIMD → Thread helpers: dispatches (evidence: `src/gemm_simd.cpp`)
- Packed GEMM → NEON micro-kernel: calls (evidence: `src/gemm_simd.cpp`)
- Packed GEMM → AVX2 micro-kernel: calls (evidence: `src/gemm_simd.cpp`)
- Blocked kernel → Kernel internals: uses (evidence: `src/gemm_blocked.cpp`)
- Threaded blocked → Kernel internals: uses (evidence: `src/gemm_blocked_mt.cpp`)
- Packed GEMM → Kernel internals: uses (evidence: `src/gemm_simd.cpp`)
- Thread helpers → Kernel internals: uses (evidence: `src/threads.cpp`)
