Skip to content

Commit e043c08

Browse files
LessUpCopilot
andcommitted
fix: finalize whitepaper rebuild safeguards
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 961c0f8 commit e043c08

14 files changed

Lines changed: 248 additions & 53 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const base = rawBase
99
: `/${rawBase}/`
1010
: '/sgemm-optimization/'
1111

12+
const asset = (relativePath: string) => `${base}${relativePath.replace(/^\/+/, '')}`
13+
1214
function localeNav(prefix: '/en/' | '/zh/') {
1315
if (prefix === '/en/') {
1416
return [
@@ -183,9 +185,9 @@ export default withMermaid(defineConfig({
183185
head: [
184186
['meta', { name: 'theme-color', content: '#76b900' }],
185187
['meta', { property: 'og:type', content: 'website' }],
186-
['link', { rel: 'icon', type: 'image/svg+xml', href: '/sgemm-optimization/favicon.svg' }],
187-
['link', { rel: 'icon', type: 'image/png', sizes: '32x32', href: '/sgemm-optimization/favicon-32x32.png' }],
188-
['link', { rel: 'apple-touch-icon', sizes: '180x180', href: '/sgemm-optimization/apple-touch-icon.png' }],
188+
['link', { rel: 'icon', type: 'image/svg+xml', href: asset('favicon.svg') }],
189+
['link', { rel: 'icon', type: 'image/png', sizes: '32x32', href: asset('favicon-32x32.png') }],
190+
['link', { rel: 'apple-touch-icon', sizes: '180x180', href: asset('apple-touch-icon.png') }],
189191
],
190192

191193
ignoreDeadLinks: [

docs/en/architecture/index.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ SGEMM optimization on modern NVIDIA hardware is a sequence of bottleneck-class m
2222

2323
| Component | Layer | Primary responsibility |
2424
|-----------|-------|------------------------|
25-
| `src/main.cu` | Driver | Dispatch, size validation, timing harness, output |
26-
| `src/kernels/naive.cuh` | Kernel | FP32 baseline with full global-memory load cost |
27-
| `src/kernels/tiled.cuh` | Kernel | Cooperative tile load into shared memory; SMEM reuse |
28-
| `src/kernels/bank_free.cuh` | Kernel | Padding eliminates shared-memory bank conflicts |
29-
| `src/kernels/double_buffer.cuh` | Kernel | Async prefetch overlaps next-tile staging with active compute |
30-
| `src/kernels/tensor_core.cuh` | Kernel | WMMA fragment accumulation on hardware-aligned tiles |
31-
| `src/utils/cuda_check.cuh` | Utility | CUDA error checking and RAII device-resource guards |
32-
| `tests/test_sgemm.cu` | Test | Correctness verification under reference tolerance |
25+
| `src/main.cu` | Driver | Entry point that delegates CLI parsing and benchmark orchestration |
26+
| `src/cli_parser.cuh` | Driver support | Parses mode flags, shapes, and runtime options into `BenchmarkConfig` |
27+
| `src/benchmark_runner.cuh` | Driver support | Runs configured benchmark and verification flows through one binary |
28+
| `src/kernels/naive_sgemm.cuh` | Kernel | FP32 baseline with full global-memory load cost |
29+
| `src/kernels/tiled_sgemm.cuh` | Kernel | Cooperative tile load into shared memory; SMEM reuse |
30+
| `src/kernels/bank_conflict_free_sgemm.cuh` | Kernel | Padding eliminates shared-memory bank conflicts |
31+
| `src/kernels/double_buffer_sgemm.cuh` | Kernel | Overlaps next-tile staging with active compute |
32+
| `src/kernels/tensor_core_sgemm.cuh` | Kernel | WMMA fragment accumulation on hardware-aligned tiles |
33+
| `src/utils/cuda_utils.cuh` | Utility | CUDA error macros, RAII device-memory wrappers, device metadata |
34+
| `src/utils/verify.cuh` | Utility | cuBLAS-backed correctness verification and tolerance policy |
35+
| `tests/test_sgemm.cu` | Test | GPU-side correctness verification under cuBLAS reference tolerance |
3336

3437
## Memory-hierarchy data flow
3538

@@ -88,7 +91,7 @@ The project separates what two different environments can prove:
8891

8992
| Claim | Local CUDA GPU | Hosted CI |
9093
|-------|----------------|-----------|
91-
| Compilation succeeds || ✓ (structure check only) |
94+
| Compilation succeeds || |
9295
| Output correctness vs. cuBLAS |||
9396
| Benchmark performance claims |||
9497
| Repository structure and docs |||

docs/en/architecture/system-blueprint.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ This page is a full component-level blueprint of the SGEMM optimization system.
1818

1919
| Component | Role | Constraints |
2020
|---|---|---|
21-
| `main.cu` entry | Parses arguments, selects kernel variant, routes to benchmarking or correctness check | Must not hard-code a variant; selection is runtime |
22-
| `kernels/sgemm_naive.cuh` | Baseline FP32, one thread per output element | Establishes the cost model; no shared memory |
23-
| `kernels/sgemm_tiled.cuh` | Tiled FP32 with shared-memory staging | Tile size is a compile-time template parameter |
24-
| `kernels/sgemm_bank_free.cuh` | Tiled FP32 with padding to eliminate bank conflicts | Padding is the only structural difference from tiled |
25-
| `kernels/sgemm_double_buffer.cuh` | Overlapped staging and compute using double buffering | Requires at least two staging buffers in shared memory |
26-
| `kernels/sgemm_tensor_core.cuh` | WMMA-based computation with FP32 entry path | Guarded by device capability and shape divisibility |
27-
| `utils/cuda_check.h` | RAII-based error propagation for CUDA API and kernel calls | Throws `std::runtime_error` on failure; no silent returns |
28-
| `utils/matrix.h` | Host-side matrix initialization and reference computation | Row-major layout; reference uses CPU BLAS or naive FP64 loop |
21+
| `src/main.cu` | Parses arguments, delegates to `CliParser` and `BenchmarkRunner` | Must keep one runtime-controlled entry path |
22+
| `src/cli_parser.cuh` | Maps CLI flags to benchmark/verification modes | Shape labels and mode switches stay centralized |
23+
| `src/benchmark_runner.cuh` | Routes each configured run through benchmarking and reporting | Shared host orchestration keeps cross-kernel comparisons consistent |
24+
| `src/kernels/naive_sgemm.cuh` | Baseline FP32, one thread per output element | Establishes the cost model; no shared memory |
25+
| `src/kernels/tiled_sgemm.cuh` | Tiled FP32 with shared-memory staging | Tile size is a compile-time template parameter |
26+
| `src/kernels/bank_conflict_free_sgemm.cuh` | Tiled FP32 with padding to eliminate bank conflicts | Padding is the only structural difference from tiled |
27+
| `src/kernels/double_buffer_sgemm.cuh` | Overlapped staging and compute using double buffering | Requires two staging buffers in shared memory |
28+
| `src/kernels/tensor_core_sgemm.cuh` | WMMA-based computation for aligned Tensor Core shapes | Guarded by device capability and shape divisibility |
29+
| `src/kernels/tensor_core_fallback.cuh` | Safe mixed-precision entry and fallback logic | Must preserve FP32 correctness on unsupported shapes |
30+
| `src/utils/cuda_utils.cuh` | CUDA error macros, RAII device memory, device metadata | Uses `CUDA_CHECK` / `CUBLAS_CHECK`; no silent failure path |
31+
| `src/utils/verify.cuh` | cuBLAS-backed oracle verification and tolerance policy | Reference is computed against cuBLAS on the active GPU |
2932
| `tests/test_sgemm.cu` | cuBLAS-backed oracle correctness suite | Runs only on GPU; not included in hosted CI |
3033
| Docs site | Narrative layer — architecture, academy, validation, research | VitePress with bilingual routes; no runtime GPU dependency |
3134

@@ -56,7 +59,7 @@ Correctness check against cuBLAS oracle (local GPU only)
5659

5760
### RAII error handling
5861

59-
All CUDA API calls and kernel launches are wrapped in `cudaCheck()`. This ensures that any failure path immediately terminates with a traceable error rather than silently propagating incorrect results through the pipeline.
62+
All CUDA API calls and kernel launches are wrapped in `CUDA_CHECK`, and cuBLAS calls are wrapped in `CUBLAS_CHECK`. This ensures that any failure path immediately terminates with a traceable error rather than silently propagating incorrect results through the pipeline.
6063

6164
**Consequence:** Test code cannot accidentally swallow an error and then compare incorrect output against the cuBLAS oracle, which would make a failing kernel appear to pass.
6265

@@ -85,7 +88,7 @@ The blueprint explicitly separates compile-time-verifiable invariants from runti
8588
| Invariant class | Verifiable where |
8689
|---|---|
8790
| File structure, docs, OpenSpec alignment | Hosted CI |
88-
| CUDA code compiles without warning | Hosted CI (compile-only) |
91+
| CUDA code compiles and runs on a real CUDA toolchain | Local GPU-capable machine |
8992
| Correctness under cuBLAS oracle | Local GPU run |
9093
| Benchmark numbers and speedup ratios | Local GPU run with named hardware |
9194

docs/public/figures/whitepaper-system-light.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/tests/architecture-routes.test.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'node:test'
22
import assert from 'node:assert/strict'
3-
import { existsSync, readFileSync } from 'node:fs'
3+
import { existsSync, readFileSync, readdirSync } from 'node:fs'
44
import path from 'node:path'
55
import { fileURLToPath } from 'node:url'
66

@@ -47,11 +47,14 @@ for (const locale of ['en', 'zh']) {
4747
test(`${locale} curated figures use the shared theme-aware component`, () => {
4848
const homepage = readFileSync(path.join(docsRoot, locale, 'index.md'), 'utf8')
4949
const architecture = readFileSync(path.join(docsRoot, locale, 'architecture', 'index.md'), 'utf8')
50+
const blueprint = readFileSync(path.join(docsRoot, locale, 'architecture', 'system-blueprint.md'), 'utf8')
5051

5152
assert.equal(homepage.includes('<ThemedFigure'), true)
5253
assert.equal(architecture.includes('<ThemedFigure'), true)
54+
assert.equal(blueprint.includes('<ThemedFigure'), true)
5355
assert.equal(homepage.includes('<picture>'), false)
5456
assert.equal(architecture.includes('<picture>'), false)
57+
assert.equal(blueprint.includes('<picture>'), false)
5558
})
5659
}
5760

@@ -65,3 +68,15 @@ test('whitepaper figure assets exist for both light and dark themes', () => {
6568
test('shared theme-aware figure component exists', () => {
6669
assert.equal(existsSync(path.join(docsRoot, '.vitepress', 'components', 'ThemedFigure.vue')), true)
6770
})
71+
72+
test('figure SVGs do not contain malformed spaced hex colors', () => {
73+
const figureDir = path.join(docsRoot, 'public', 'figures')
74+
75+
for (const file of readdirSync(figureDir)) {
76+
if (!file.endsWith('.svg'))
77+
continue
78+
79+
const svg = readFileSync(path.join(figureDir, file), 'utf8')
80+
assert.equal(/#[0-9A-Fa-f]{2,}\s+[0-9A-Fa-f]+/.test(svg), false, `${file} contains a malformed hex color`)
81+
}
82+
})

docs/zh/architecture/index.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ title: 架构概述
2222

2323
| 组件 | 层次 | 主要职责 |
2424
|------|------|----------|
25-
| `src/main.cu` | 驱动层 | 分发、尺寸验证、计时框架、输出 |
26-
| `src/kernels/naive.cuh` | Kernel | FP32 基线,承受完整全局内存加载代价 |
27-
| `src/kernels/tiled.cuh` | Kernel | 协作式 tile 加载入共享内存;SMEM 复用 |
28-
| `src/kernels/bank_free.cuh` | Kernel | Padding 消除共享内存 bank 冲突 |
29-
| `src/kernels/double_buffer.cuh` | Kernel | 异步预取将下一 tile 的 staging 与当前计算重叠 |
30-
| `src/kernels/tensor_core.cuh` | Kernel | 在硬件对齐的 tile 上执行 WMMA fragment 累加 |
31-
| `src/utils/cuda_check.cuh` | 工具 | CUDA 错误检查与 RAII 设备资源守卫 |
32-
| `tests/test_sgemm.cu` | 测试 | 在参考误差容限内验证正确性 |
25+
| `src/main.cu` | 驱动层 | 程序入口,负责把 CLI 解析和 benchmark 编排接起来 |
26+
| `src/cli_parser.cuh` | 驱动支撑 | 把模式标志、shape 和运行参数解析成 `BenchmarkConfig` |
27+
| `src/benchmark_runner.cuh` | 驱动支撑 | 用同一个二进制执行 benchmark 与 verification 流程 |
28+
| `src/kernels/naive_sgemm.cuh` | Kernel | FP32 基线,承受完整全局内存加载代价 |
29+
| `src/kernels/tiled_sgemm.cuh` | Kernel | 协作式 tile 加载入共享内存;SMEM 复用 |
30+
| `src/kernels/bank_conflict_free_sgemm.cuh` | Kernel | Padding 消除共享内存 bank 冲突 |
31+
| `src/kernels/double_buffer_sgemm.cuh` | Kernel | 将下一 tile 的 staging 与当前计算重叠 |
32+
| `src/kernels/tensor_core_sgemm.cuh` | Kernel | 在硬件对齐的 tile 上执行 WMMA fragment 累加 |
33+
| `src/utils/cuda_utils.cuh` | 工具 | CUDA 错误宏、RAII 设备内存封装与设备信息 |
34+
| `src/utils/verify.cuh` | 工具 | 基于 cuBLAS 的正确性校验与容差策略 |
35+
| `tests/test_sgemm.cu` | 测试 | 基于 GPU 和 cuBLAS 参考的正确性测试 |
3336

3437
## 内存层级数据流
3538

@@ -88,7 +91,7 @@ Memory Flow 页面将以具体的地址、stride、tile 维度和加载模式呈
8891

8992
| 主张 | 本地 CUDA GPU | 托管 CI |
9093
|------|---------------|---------|
91-
| 编译成功 || ✓(仅结构检查)|
94+
| 编译成功 || |
9295
| 输出正确性 vs. cuBLAS |||
9396
| Benchmark 性能结论 |||
9497
| 仓库结构与文档 |||

docs/zh/architecture/system-blueprint.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ title: 系统蓝图
1818

1919
| 组件 | 作用 | 约束 |
2020
|---|---|---|
21-
| `main.cu` 入口 | 解析参数、选择 kernel 变体、路由到 benchmark 或正确性检查 | 不得硬编码变体,选择在运行时完成 |
22-
| `kernels/sgemm_naive.cuh` | 基线 FP32,每个线程处理一个输出元素 | 建立代价模型;不使用共享内存 |
23-
| `kernels/sgemm_tiled.cuh` | 使用共享内存 staging 的 tiled FP32 | tile 大小是编译期模板参数 |
24-
| `kernels/sgemm_bank_free.cuh` | 通过 padding 消除 bank 冲突的 tiled FP32 | Padding 是与 tiled 版本的唯一结构差异 |
25-
| `kernels/sgemm_double_buffer.cuh` | 使用双缓冲重叠 staging 与 compute | 共享内存中至少需要两个 staging buffer |
26-
| `kernels/sgemm_tensor_core.cuh` | 基于 WMMA 的计算,带 FP32 入口路径 | 受设备能力和 shape 整除性保护 |
27-
| `utils/cuda_check.h` | CUDA API 和 kernel 调用的 RAII 错误传播 | 失败时抛出 `std::runtime_error`,不静默返回 |
28-
| `utils/matrix.h` | 主机侧矩阵初始化与参考计算 | 行主序布局;参考使用 CPU BLAS 或 naive FP64 循环 |
21+
| `src/main.cu` | 解析参数,并委托给 `CliParser``BenchmarkRunner` | 必须保持单一的运行时入口路径 |
22+
| `src/cli_parser.cuh` | 把 CLI 标志映射到 benchmark / verification 模式 | shape 标签和模式开关集中管理 |
23+
| `src/benchmark_runner.cuh` | 将每次配置好的运行路由到 benchmark 与结果报告 | 统一主机侧编排保证跨 kernel 对比一致 |
24+
| `src/kernels/naive_sgemm.cuh` | 基线 FP32,每个线程处理一个输出元素 | 建立代价模型;不使用共享内存 |
25+
| `src/kernels/tiled_sgemm.cuh` | 使用共享内存 staging 的 tiled FP32 | tile 大小是编译期模板参数 |
26+
| `src/kernels/bank_conflict_free_sgemm.cuh` | 通过 padding 消除 bank 冲突的 tiled FP32 | Padding 是与 tiled 版本的唯一结构差异 |
27+
| `src/kernels/double_buffer_sgemm.cuh` | 使用双缓冲重叠 staging 与 compute | 共享内存中需要两个 staging buffer |
28+
| `src/kernels/tensor_core_sgemm.cuh` | 面向对齐 Tensor Core shape 的 WMMA 计算 | 受设备能力和 shape 整除性保护 |
29+
| `src/kernels/tensor_core_fallback.cuh` | 安全的混合精度入口与回退逻辑 | 必须在不满足条件时保持 FP32 正确性 |
30+
| `src/utils/cuda_utils.cuh` | CUDA 错误宏、RAII 设备内存与设备信息 | 使用 `CUDA_CHECK` / `CUBLAS_CHECK`,不允许静默失败 |
31+
| `src/utils/verify.cuh` | 基于 cuBLAS 的 oracle 校验与容差策略 | 参考结果在活跃 GPU 上通过 cuBLAS 计算 |
2932
| `tests/test_sgemm.cu` | 基于 cuBLAS oracle 的正确性测试套件 | 只在 GPU 上运行;不包含在托管 CI 中 |
3033
| Docs 站点 | 叙事层——架构、学院、验证、研究 | VitePress 双语路由;无运行时 GPU 依赖 |
3134

@@ -56,7 +59,7 @@ cudaMemcpy D→H
5659

5760
### RAII 错误处理
5861

59-
所有 CUDA API 调用和 kernel 启动都通过 `cudaCheck()` 包装。这确保任何失败路径都会立即以可追踪的错误终止,而不会把错误结果静默地传递下去。
62+
所有 CUDA API 调用和 kernel 启动都通过 `CUDA_CHECK` 包装,cuBLAS 调用则通过 `CUBLAS_CHECK` 包装。这确保任何失败路径都会立即以可追踪的错误终止,而不会把错误结果静默地传递下去。
6063

6164
**影响:** 测试代码不会意外吞掉错误然后用错误输出与 cuBLAS oracle 比较,避免了"失败的 kernel 看起来通过了测试"的问题。
6265

@@ -85,7 +88,7 @@ Tensor Core 变体在提交 WMMA 计算之前检查设备能力和 shape 整除
8588
| 约束类别 | 可验证环境 |
8689
|---|---|
8790
| 文件结构、文档、OpenSpec 对齐 | 托管 CI |
88-
| CUDA 代码编译无警告 | 托管 CI(仅编译) |
91+
| CUDA 代码在真实 CUDA 工具链上完成编译与运行 | 本地 GPU 机器 |
8992
| cuBLAS oracle 正确性 | 本地 GPU 运行 |
9093
| Benchmark 数字和加速比 | 带命名硬件的本地 GPU 运行 |
9194

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schema: spec-driven
2+
created: 2026-05-18

0 commit comments

Comments
 (0)