# vshiva27/cuda-transformer-performance architecture

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

- Interactive diagram: https://gitdiagram.com/vshiva27/cuda-transformer-performance
- Repository: https://github.com/vshiva27/cuda-transformer-performance

## Overview

This repository is a CUDA Transformer-inference kernel library and its GPT-2 integration. The user-facing inference path loads a Hugging Face model, prepares weights and cache state, then generates tokens through a Python runner, C++ bindings, and CUDA kernels. Separate branches cover CPU reference operations, kernel benchmarking against PyTorch/cuBLAS, and Nsight profiling. The README documents these capabilities; sampled source confirms selected CPU-reference and GPT-2 binding behavior, but not every benchmark or kernel call path.

Main entry points: [`llm/gpt2_ops.cpp`](https://github.com/vshiva27/cuda-transformer-performance/blob/main/llm/gpt2_ops.cpp) (PyTorch bindings), [`src/benchmark`](https://github.com/vshiva27/cuda-transformer-performance/tree/main/src/benchmark) (CUDA benchmarks), [`llm/run_gpt2.py`](https://github.com/vshiva27/cuda-transformer-performance/blob/main/llm/run_gpt2.py) (GPT-2 runner), [`kernels/gemv.cu`](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/gemv.cu) (Decode GEMV)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference Kernels"]
  node_gemv["Decode GEMV<br/>[gemv.cu]"]
  node_attention["Fused attention<br/>[attention.cu]"]
  node_layernorm["LayerNorm<br/>[layernorm.cu]"]
  node_softmax["Softmax<br/>[softmax.cu]"]
  node_matmul["GEMM variants<br/>[matmul_basic.cu]"]
  node_matmul_tiled["Tiled GEMM<br/>[matmul_tiled.cu]"]
  node_matmul_register["Register GEMM<br/>[matmul_register.cu]"]
  node_matmul_wmma["WMMA GEMM<br/>[matmul_wmma.cu]"]
  node_vectoradd["Vector add<br/>[vector_add.cu]"]
end

subgraph group_gpt2["GPT-2 Integration"]
  node_runner["GPT-2 runner<br/>[run_gpt2.py]"]
  node_bindings["PyTorch bindings<br/>[gpt2_ops.cpp]"]
end

subgraph group_evaluation["Evaluation"]
  node_cpu["CPU references<br/>[cpu_ops.cpp]"]
  node_benchmarks["CUDA benchmarks"]
  node_torchbaseline["PyTorch baseline"]
  node_profiling["Nsight profiling"]
  node_reports["Benchmark reports"]
end

node_user(("Inference user"))
node_hf["Hugging Face model"]
node_gpu(("NVIDIA GPU"))

node_user -->|"runs"| node_runner
node_runner -->|"loads and verifies"| node_hf
node_runner -->|"invokes"| node_bindings
node_bindings -->|"dispatches linear"| node_gemv
node_bindings -->|"dispatches attention"| node_attention
node_bindings -->|"dispatches normalization"| node_layernorm
node_bindings -->|"uses in integration"| node_softmax
node_gemv -->|"executes on"| node_gpu
node_attention -->|"executes on"| node_gpu
node_layernorm -->|"executes on"| node_gpu
node_softmax -->|"executes on"| node_gpu
node_matmul -->|"executes on"| node_gpu
node_matmul_tiled -->|"executes on"| node_gpu
node_matmul_register -->|"executes on"| node_gpu
node_matmul_wmma -->|"executes on"| node_gpu
node_vectoradd -->|"executes on"| node_gpu
node_cpu -->|"provides reference"| node_benchmarks
node_benchmarks -->|"times kernels"| node_gpu
node_torchbaseline -->|"provides comparison"| node_benchmarks
node_benchmarks -->|"writes measurements"| node_reports
node_gpu -->|"profiled with"| node_profiling
node_profiling -->|"produces reports"| node_reports

click node_runner "https://github.com/vshiva27/cuda-transformer-performance/blob/main/llm/run_gpt2.py"
click node_bindings "https://github.com/vshiva27/cuda-transformer-performance/blob/main/llm/gpt2_ops.cpp"
click node_gemv "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/gemv.cu"
click node_attention "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/attention.cu"
click node_layernorm "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/layernorm.cu"
click node_softmax "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/softmax.cu"
click node_matmul "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_basic.cu"
click node_matmul_tiled "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_tiled.cu"
click node_matmul_register "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_register.cu"
click node_matmul_wmma "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_wmma.cu"
click node_vectoradd "https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/vector_add.cu"
click node_cpu "https://github.com/vshiva27/cuda-transformer-performance/blob/main/src/cpu/cpu_ops.cpp"
click node_benchmarks "https://github.com/vshiva27/cuda-transformer-performance/tree/main/src/benchmark"
click node_torchbaseline "https://github.com/vshiva27/cuda-transformer-performance/blob/main/python/pytorch_baseline.py"
click node_profiling "https://github.com/vshiva27/cuda-transformer-performance/tree/main/profiling"
click node_reports "https://github.com/vshiva27/cuda-transformer-performance/tree/main/benchmarks"

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_gemv,node_attention,node_layernorm,node_softmax,node_matmul,node_matmul_tiled,node_matmul_register,node_matmul_wmma,node_vectoradd,node_user toneBlue
class node_runner,node_bindings toneAmber
class node_cpu,node_benchmarks,node_torchbaseline,node_profiling,node_reports toneMint
class node_hf,node_gpu toneIndigo
```

## Components

### Inference Kernels

- [Decode GEMV](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/gemv.cu): `kernels/gemv.cu`
- [Fused attention](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/attention.cu): `kernels/attention.cu`
- [LayerNorm](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/layernorm.cu): `kernels/layernorm.cu`
- [Softmax](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/softmax.cu): `kernels/softmax.cu`
- [GEMM variants](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_basic.cu): `kernels/matmul_basic.cu`
- [Tiled GEMM](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_tiled.cu): `kernels/matmul_tiled.cu`
- [Register GEMM](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_register.cu): `kernels/matmul_register.cu`
- [WMMA GEMM](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/matmul_wmma.cu): `kernels/matmul_wmma.cu`
- [Vector add](https://github.com/vshiva27/cuda-transformer-performance/blob/main/kernels/vector_add.cu): `kernels/vector_add.cu`

### GPT-2 Integration

- [GPT-2 runner](https://github.com/vshiva27/cuda-transformer-performance/blob/main/llm/run_gpt2.py): `llm/run_gpt2.py`
- [PyTorch bindings](https://github.com/vshiva27/cuda-transformer-performance/blob/main/llm/gpt2_ops.cpp): `llm/gpt2_ops.cpp`

### Evaluation

- [CPU references](https://github.com/vshiva27/cuda-transformer-performance/blob/main/src/cpu/cpu_ops.cpp): `src/cpu/cpu_ops.cpp`
- [CUDA benchmarks](https://github.com/vshiva27/cuda-transformer-performance/tree/main/src/benchmark): `src/benchmark`
- [PyTorch baseline](https://github.com/vshiva27/cuda-transformer-performance/blob/main/python/pytorch_baseline.py): `python/pytorch_baseline.py`
- [Nsight profiling](https://github.com/vshiva27/cuda-transformer-performance/tree/main/profiling): `profiling`
- [Benchmark reports](https://github.com/vshiva27/cuda-transformer-performance/tree/main/benchmarks): `benchmarks`

### Other components

- **Inference user**
- **Hugging Face model**
- **NVIDIA GPU**

## Connections

- Inference user → GPT-2 runner: runs (evidence: `README.md`)
- GPT-2 runner → Hugging Face model: loads and verifies (evidence: `README.md`)
- GPT-2 runner → PyTorch bindings: invokes (evidence: `llm/gpt2_ops.cpp`)
- PyTorch bindings → Decode GEMV: dispatches linear (evidence: `llm/gpt2_ops.cpp`)
- PyTorch bindings → Fused attention: dispatches attention (evidence: `llm/gpt2_ops.cpp`)
- PyTorch bindings → LayerNorm: dispatches normalization (evidence: `llm/gpt2_ops.cpp`)
- PyTorch bindings → Softmax: uses in integration (evidence: `llm/gpt2_ops.cpp`)
- Decode GEMV → NVIDIA GPU: executes on (evidence: `README.md`)
- Fused attention → NVIDIA GPU: executes on (evidence: `README.md`)
- LayerNorm → NVIDIA GPU: executes on (evidence: `README.md`)
- Softmax → NVIDIA GPU: executes on (evidence: `README.md`)
- GEMM variants → NVIDIA GPU: executes on (evidence: `README.md`)
- Tiled GEMM → NVIDIA GPU: executes on (evidence: `README.md`)
- Register GEMM → NVIDIA GPU: executes on (evidence: `README.md`)
- WMMA GEMM → NVIDIA GPU: executes on (evidence: `README.md`)
- Vector add → NVIDIA GPU: executes on (evidence: `README.md`)
- CPU references → CUDA benchmarks: provides reference (evidence: `README.md`)
- CUDA benchmarks → NVIDIA GPU: times kernels (evidence: `README.md`)
- PyTorch baseline → CUDA benchmarks: provides comparison (evidence: `README.md`)
- CUDA benchmarks → Benchmark reports: writes measurements (evidence: `README.md`)
- NVIDIA GPU → Nsight profiling: profiled with (evidence: `README.md`)
- Nsight profiling → Benchmark reports: produces reports (evidence: `README.md`)
