Skip to content

Commit d3126c3

Browse files
committed
docs: optimize GitHub Pages landing page - English, badges, architecture, benchmarks
1 parent 3381902 commit d3126c3

1 file changed

Lines changed: 82 additions & 34 deletions

File tree

index.md

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,100 @@ title: SGEMM Optimization
55

66
# SGEMM Optimization: From Naive to Tensor Core
77

8-
从零手写极致优化的矩阵乘法 — HPC 领域的 "Hello World"。渐进式优化 CUDA SGEMM,展示 GPU 编程核心优化技术。
8+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
9+
![CUDA](https://img.shields.io/badge/CUDA-11.0+-76B900?logo=nvidia&logoColor=white)
10+
![C++](https://img.shields.io/badge/C%2B%2B-17-00599C?logo=c%2B%2B&logoColor=white)
911

10-
## 实测性能 (RTX 3060 Laptop, 1024×1024)
12+
Hand-written, progressively optimized CUDA matrix multiplication — the "Hello World" of HPC. Five kernel variants demonstrate core GPU optimization techniques, from a naive triple loop to **Tensor Core WMMA reaching 40% of cuBLAS throughput**.
1113

12-
| Kernel | GFLOPS | vs cuBLAS |
13-
|--------|--------|-----------|
14-
| cuBLAS (参考) | 5727 | 100% |
15-
| Tensor Core (WMMA) | 2300 | 40.2% |
16-
| Tiled (32×32) | 753 | 13.1% |
17-
| Double Buffer | 701 | 12.2% |
18-
| Bank Conflict Free | 673 | 11.8% |
19-
| Naive | 604 | 10.6% |
14+
## Benchmark Results (RTX 3060 Laptop, 1024×1024)
2015

21-
## 优化路线
16+
| Kernel | GFLOPS | vs cuBLAS | Key Technique |
17+
|--------|--------|-----------|---------------|
18+
| **cuBLAS** (reference) | 5727 | 100% ||
19+
| **Tensor Core** (WMMA) | 2300 | 40.2% | FP16 → FP32 mixed precision |
20+
| **Tiled** (32×32) | 753 | 13.1% | Shared memory blocking |
21+
| **Double Buffer** | 701 | 12.2% | Compute-memory overlap |
22+
| **Bank Conflict Free** | 673 | 11.8% | Shared memory padding (+1) |
23+
| **Naive** | 604 | 10.6% | One thread per output element |
2224

23-
| 版本 | 关键技术 |
24-
|------|----------|
25-
| Naive | 每线程计算一个输出元素 |
26-
| Tiled | 共享内存分块,数据复用 |
27-
| Bank Conflict Free | 共享内存 padding (+1) |
28-
| Double Buffer | 计算与访存重叠 |
29-
| Tensor Core | WMMA API,FP16→FP32 |
25+
*All kernels verified against cuBLAS (allclose: rtol=1e-3, atol=1e-4; Tensor Core: rtol=5e-2)*
3026

31-
## 快速开始
27+
## Optimization Roadmap
28+
29+
```
30+
Naive (604) ──▶ Tiled (753) ──▶ Bank-Free (673) ──▶ Double Buffer (701)
31+
32+
Tensor Core (2300) ◀──┘
33+
```
34+
35+
| Stage | What Changes | Why It Helps |
36+
|-------|-------------|--------------|
37+
| **Naive → Tiled** | Load tiles into shared memory | Data reuse reduces global memory traffic by TILE_SIZE× |
38+
| **Tiled → Bank-Free** | Pad shared memory `[32][33]` | Eliminates 32-way bank conflicts on column access |
39+
| **Bank-Free → Double Buffer** | Two shared-memory buffers | Overlaps next-tile load with current-tile compute |
40+
| **→ Tensor Core** | WMMA API `mma_sync` | Dedicated matrix units, ~8× peak over CUDA cores |
41+
42+
## Key Optimization Details
43+
44+
**Memory Coalescing** — Naive accesses matrix B columns non-contiguously (stride = N). Tiled loading ensures warp-wide coalesced reads (stride = 1), improving bandwidth utilization from ~12.5% to near 100%.
45+
46+
**Shared Memory Tiling** — Each tile is loaded once from global memory and reused TILE_SIZE times in shared memory. Global memory traffic drops from O(N³) to O(N³/TILE_SIZE).
47+
48+
**Tensor Core (WMMA)** — A single warp cooperatively executes a 16×16×16 matrix multiply using `nvcuda::wmma` fragments. FP16 inputs with FP32 accumulation provide ~8× peak FLOPS over standard CUDA cores on Ampere.
49+
50+
**Roofline Analysis** — SGEMM arithmetic intensity ≈ N/3 for square matrices. Small matrices (N < 256) are memory-bound; large matrices (N > 1024) are compute-bound.
51+
52+
## Quick Start
3253

3354
```bash
34-
# 编译 (根据 GPU 架构调整)
55+
# Build (adjust GPU arch for your hardware)
3556
make GPU_ARCH=sm_86
3657

37-
# 运行基准测试
38-
./build/sgemm_benchmark
39-
40-
# 或直接
58+
# Run benchmark suite
4159
make benchmark
4260
```
4361

44-
## 技术栈
62+
### Sample Output
4563

46-
| 类别 | 技术 |
47-
|------|------|
48-
| 语言 | CUDA C++17 |
49-
| 构建 | Makefile |
50-
| 依赖 | cuBLAS, Google Test (可选) |
51-
| GPU | SM 70+ (Volta → Hopper) |
64+
```
65+
Kernel | Dimensions | Time | Performance | Pass
66+
-----------------------------------------------------------------------
67+
cuBLAS | 1024 x 1024 x 1024 | 0.375ms | 5726 GFLOPS | PASS
68+
Naive | 1024 x 1024 x 1024 | 3.553ms | 604 GFLOPS | PASS
69+
Tiled (32x32) | 1024 x 1024 x 1024 | 2.853ms | 753 GFLOPS | PASS
70+
Bank Conflict Free | 1024 x 1024 x 1024 | 3.190ms | 673 GFLOPS | PASS
71+
Double Buffer | 1024 x 1024 x 1024 | 3.064ms | 701 GFLOPS | PASS
72+
Tensor Core (WMMA) | 1024 x 1024 x 1024 | 0.934ms | 2300 GFLOPS | PASS
73+
```
74+
75+
## Testing
76+
77+
Property-based tests with Google Test:
78+
79+
| Property | What It Verifies |
80+
|----------|-----------------|
81+
| Numerical correctness | All kernels match cuBLAS output |
82+
| Tensor Core tolerance | Correct under relaxed FP16 tolerance |
83+
| Error detection | Verification system catches injected errors |
84+
| Dimension invariance | All kernels handle arbitrary aligned sizes |
5285

53-
## 链接
86+
## Tech Stack
87+
88+
| Category | Technology |
89+
|----------|------------|
90+
| Language | CUDA C++17 |
91+
| Build | Makefile |
92+
| Dependencies | cuBLAS, Google Test (optional) |
93+
| GPU | Compute Capability 7.0+ (Volta → Hopper) |
94+
95+
## References
96+
97+
- [CUDA C++ Programming Guide](https://docs.nvidia.com/cuda/cuda-c-programming-guide/)
98+
- [How to Optimize a CUDA Matmul Kernel](https://siboehm.com/articles/22/CUDA-MMM) — Simon Boehm
99+
- [CUTLASS](https://github.com/NVIDIA/cutlass) — NVIDIA's high-performance GEMM library
100+
- [Roofline Model](https://crd.lbl.gov/divisions/amcr/computer-science-amcr/par/research/roofline/)
101+
102+
---
54103

55-
- [GitHub 仓库](https://github.com/LessUp/sgemm-optimization)
56-
- [README](README.md)
104+
[View on GitHub](https://github.com/LessUp/sgemm-optimization) · [README](README.md)

0 commit comments

Comments
 (0)