Allanatrix commited on
Commit
76121e5
·
verified ·
1 Parent(s): 1104322

Add interactive PyC kernel performance lab

Browse files

Documentation-first Gradio Space covering 19 CUDA kernels and performance-engineering tradeoffs.

Files changed (4) hide show
  1. README.md +15 -7
  2. app.py +75 -0
  3. kernels.json +156 -0
  4. requirements.txt +1 -0
README.md CHANGED
@@ -1,13 +1,21 @@
1
  ---
2
- title: Pyc Kernel Lab
3
- emoji: 📊
4
- colorFrom: indigo
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 6.25.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: PyC CUDA Kernel Lab
3
+ emoji: ⚡
4
+ colorFrom: gray
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 5.49.1
 
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
+ # PyC CUDA Kernel Lab
14
+
15
+ An interactive map of 19 CUDA kernel prototypes and the performance-engineering
16
+ ideas behind them: tiling, Tensor Cores, asynchronous staging, CTA geometry,
17
+ and library ceilings.
18
+
19
+ The Space is documentation-first. It does not compile or execute CUDA kernels.
20
+ The source release and selected evidence are available at
21
+ [`AethronPhantom/pyc-kernels`](https://huggingface.co/datasets/AethronPhantom/pyc-kernels).
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+
4
+ import gradio as gr
5
+
6
+
7
+ ROOT = Path(__file__).parent
8
+ manifest = json.loads((ROOT / "kernels.json").read_text())
9
+ kernels = manifest["kernels"]
10
+
11
+ EVIDENCE = {
12
+ "hopper_tensor_core_fp16": "H100, 1024³: 0.105 ms, 20.473 TFLOPS (correctness lane).",
13
+ "hopper_tensor_core_bf16": "H100, 1024³: 0.102 ms, 21.024 TFLOPS (correctness lane).",
14
+ "hopper_cublaslt_bf16": "H100, 4096³: 0.162 ms, 846.466 TFLOPS (cuBLASLt control lane).",
15
+ "hopper_tensor_core_bf16_async_square_k64": "H100, 4096³: 0.9252 ms in the captured async square-K64 profile.",
16
+ }
17
+
18
+
19
+ def rows():
20
+ return [
21
+ [
22
+ k["name"],
23
+ ", ".join(k.get("tags", [])),
24
+ k["source"],
25
+ EVIDENCE.get(k["name"], "See the published performance evidence; no summary number is asserted here."),
26
+ ]
27
+ for k in kernels
28
+ ]
29
+
30
+
31
+ def explain(name):
32
+ k = next(item for item in kernels if item["name"] == name)
33
+ tags = ", ".join(k.get("tags", []))
34
+ return (
35
+ f"### {k['name']}\n\n"
36
+ f"{k.get('description', 'No description supplied.')}\n\n"
37
+ f"**Source:** `{k['source']}`\n\n"
38
+ f"**Tags:** {tags}\n\n"
39
+ f"**Evidence:** {EVIDENCE.get(name, 'No compact summary is asserted for this entry.')}\n\n"
40
+ f"**Compile command**\n```text\n{k.get('compile_cmd', '')}\n```\n\n"
41
+ f"**Run command**\n```text\n{k.get('run_cmd', '') or '(compile-only)'}\n```"
42
+ )
43
+
44
+
45
+ with gr.Blocks(title="PyC CUDA Kernel Lab", theme=gr.themes.Soft()) as demo:
46
+ gr.Markdown(
47
+ "# PyC CUDA Kernel Lab\n"
48
+ "### 19 kernels · one optimization story\n\n"
49
+ "This is a documentation and performance-engineering map, not a live CUDA runner. "
50
+ "The useful question is not only *which kernel is fastest?* but *which bottleneck "
51
+ "did each change target?*"
52
+ )
53
+ gr.Markdown(
54
+ "## How to read the progression\n"
55
+ "- **Tiling and reuse:** move data from global memory into shared memory and reuse it.\n"
56
+ "- **Tensor Cores:** use WMMA fragments for FP16/BF16 matrix math.\n"
57
+ "- **Feed the math pipe:** `cp.async`, double buffering, padding, and wider CTAs target exposed load/synchronization cost.\n"
58
+ "- **Shape is a control knob:** warp assignment, CTA M×N geometry, and K-stage depth change work per synchronization.\n"
59
+ "- **Ceiling/control:** cuBLASLt separates custom-kernel limitations from the hardware/library ceiling."
60
+ )
61
+ gr.Markdown("## Kernel catalog")
62
+ gr.Dataframe(rows(), headers=["Kernel", "Tags", "Source", "Evidence"], interactive=False, wrap=True)
63
+ selector = gr.Dropdown([k["name"] for k in kernels], value=kernels[0]["name"], label="Inspect a kernel")
64
+ detail = gr.Markdown(explain(kernels[0]["name"]))
65
+ selector.change(explain, selector, detail)
66
+ gr.Markdown(
67
+ "## Measurement discipline\n"
68
+ "Treat each number as a receipt: record GPU model, architecture, CUDA version, matrix shape, "
69
+ "warmup/repeat policy, correctness checks, and whether the reference path was enabled. "
70
+ "A kernel that wins one shape is not automatically a general winner."
71
+ )
72
+
73
+
74
+ if __name__ == "__main__":
75
+ demo.launch()
kernels.json ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "kernels": [
3
+ {
4
+ "name": "matrix_mult",
5
+ "source": "kernels/prototypes/baseline/matmul/kernel.cu",
6
+ "description": "CUDA matrix multiplication kernel (compile-only baseline).",
7
+ "tags": ["cuda", "matmul"],
8
+ "compile_cmd": "{nvcc} -O3 -c {source} -o {build_dir}/{name}.o",
9
+ "run_cmd": ""
10
+ },
11
+ {
12
+ "name": "tokenizer_kernel",
13
+ "source": "kernels/prototypes/experimental/tokenizer_matmul/kernel.cu",
14
+ "description": "Experimental tokenizer/matrix CUDA kernel file.",
15
+ "tags": ["cuda", "tokenizer", "experimental"],
16
+ "compile_cmd": "{nvcc} -O2 -c {source} -o {build_dir}/{name}.o",
17
+ "run_cmd": ""
18
+ },
19
+ {
20
+ "name": "ada_gemm",
21
+ "source": "kernels/prototypes/ada/gemm/kernel.cu",
22
+ "description": "Ada-focused FP32 shared-memory GEMM prototype with standalone correctness and timing harness.",
23
+ "tags": ["cuda", "matmul", "ada", "sm89", "prototype"],
24
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -gencode arch=compute_89,code=sm_89 -gencode arch=compute_89,code=compute_89 {source} -o {build_dir}/{name}",
25
+ "run_cmd": "{build_dir}/{name} 1024 1024 1024 10 50"
26
+ },
27
+ {
28
+ "name": "ada_gemm_k64_warp32_async",
29
+ "source": "kernels/prototypes/ada/gemm_k64_warp32_async/kernel.cu",
30
+ "description": "Ada FP32 GEMM winner with 64x64x64 tiles, 32x8 threads, and cp.async double-buffered shared-memory stages.",
31
+ "tags": ["cuda", "matmul", "ada", "sm89", "prototype", "fp32", "vectorized", "winner", "k64", "warp32", "async", "cpasync"],
32
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -gencode arch=compute_89,code=sm_89 -gencode arch=compute_89,code=compute_89 {source} -o {build_dir}/{name}",
33
+ "run_cmd": "{build_dir}/{name} 1024 1024 1024 10 50"
34
+ },
35
+ {
36
+ "name": "ada_tensor_core_fp16",
37
+ "source": "kernels/prototypes/ada/tensor_core/kernel.cu",
38
+ "description": "Ada Tensor Core FP16 GEMM prototype with WMMA-backed 32x64x16 correctness and timing harness.",
39
+ "tags": ["cuda", "matmul", "ada", "sm89", "prototype", "tensor-core", "fp16"],
40
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_ADA_TENSOR_CORE_USE_BF16=0 -gencode arch=compute_89,code=sm_89 -gencode arch=compute_89,code=compute_89 {source} -o {build_dir}/{name}",
41
+ "run_cmd": "{build_dir}/{name} 1024 1024 1024 10 50"
42
+ },
43
+ {
44
+ "name": "ada_tensor_core_bf16",
45
+ "source": "kernels/prototypes/ada/tensor_core/kernel.cu",
46
+ "description": "Ada Tensor Core BF16 GEMM prototype with WMMA-backed 32x64x16 correctness and timing harness.",
47
+ "tags": ["cuda", "matmul", "ada", "sm89", "prototype", "tensor-core", "bf16"],
48
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_ADA_TENSOR_CORE_USE_BF16=1 -gencode arch=compute_89,code=sm_89 -gencode arch=compute_89,code=compute_89 {source} -o {build_dir}/{name}",
49
+ "run_cmd": "{build_dir}/{name} 1024 1024 1024 10 50"
50
+ },
51
+ {
52
+ "name": "hopper_tensor_core_fp16",
53
+ "source": "kernels/prototypes/hopper/tensor_core/kernel.cu",
54
+ "description": "Hopper Tensor Core FP16 GEMM prototype with a 64x64x16 WMMA tile and larger per-block warpgroup-style work.",
55
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "fp16"],
56
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=0 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
57
+ "run_cmd": "{build_dir}/{name} 1024 1024 1024 5 20"
58
+ },
59
+ {
60
+ "name": "hopper_tensor_core_bf16",
61
+ "source": "kernels/prototypes/hopper/tensor_core/kernel.cu",
62
+ "description": "Hopper Tensor Core BF16 GEMM prototype with a 64x64x16 WMMA tile and larger per-block warpgroup-style work.",
63
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16"],
64
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
65
+ "run_cmd": "{build_dir}/{name} 1024 1024 1024 5 20"
66
+ },
67
+ {
68
+ "name": "hopper_tensor_core_bf16_perf",
69
+ "source": "kernels/prototypes/hopper/tensor_core/kernel.cu",
70
+ "description": "Hopper BF16 baseline perf lane at 4096^3 with reference disabled to isolate steady-state Tensor Core throughput.",
71
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "perf", "next-loop"],
72
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
73
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
74
+ },
75
+ {
76
+ "name": "hopper_tensor_core_bf16_warp2n",
77
+ "source": "kernels/prototypes/hopper/tensor_core/kernel.cu",
78
+ "description": "Hopper BF16 perf lane with 8 warps per CTA and each warp computing two N fragments to increase work per warp.",
79
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "perf", "next-loop", "warp2n"],
80
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_WARP_COL_TILES=2 -DPYC_HOPPER_TC_WARP_ROW_GROUPS=4 -DPYC_HOPPER_TC_WARP_COL_GROUPS=2 -DPYC_HOPPER_TC_SHARED_PAD_A=8 -DPYC_HOPPER_TC_SHARED_PAD_B=8 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
81
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
82
+ },
83
+ {
84
+ "name": "hopper_tensor_core_bf16_k32",
85
+ "source": "kernels/prototypes/hopper/tensor_core/kernel.cu",
86
+ "description": "Hopper BF16 perf lane with a 64x64x32 shared-memory stage to cut synchronization frequency across K.",
87
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "perf", "next-loop", "k32"],
88
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_TILE_K=32 -DPYC_HOPPER_TC_SHARED_PAD_A=8 -DPYC_HOPPER_TC_SHARED_PAD_B=8 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
89
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
90
+ },
91
+ {
92
+ "name": "hopper_tensor_core_bf16_warp2n_k32",
93
+ "source": "kernels/prototypes/hopper/tensor_core/kernel.cu",
94
+ "description": "Hopper BF16 perf lane combining 8-warp CTAs, two N fragments per warp, padded shared-memory strides, and 32-wide K staging.",
95
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "perf", "next-loop", "warp2n", "k32"],
96
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_WARP_COL_TILES=2 -DPYC_HOPPER_TC_WARP_ROW_GROUPS=4 -DPYC_HOPPER_TC_WARP_COL_GROUPS=2 -DPYC_HOPPER_TC_TILE_K=32 -DPYC_HOPPER_TC_SHARED_PAD_A=8 -DPYC_HOPPER_TC_SHARED_PAD_B=8 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
97
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
98
+ },
99
+ {
100
+ "name": "hopper_cublaslt_bf16",
101
+ "source": "kernels/prototypes/hopper/cublaslt_bf16/kernel.cu",
102
+ "description": "Hopper cuBLASLt BF16 GEMM control lane for measuring the hardware-native library ceiling before a custom TMA/WGMMA implementation lands.",
103
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "cublaslt", "bf16", "control", "ceiling"],
104
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -lcublasLt -lcublas -o {build_dir}/{name}",
105
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
106
+ },
107
+ {
108
+ "name": "hopper_cublaslt_bf16_check",
109
+ "source": "kernels/prototypes/hopper/cublaslt_bf16/kernel.cu",
110
+ "description": "Smaller Hopper cuBLASLt BF16 correctness lane with reference enabled.",
111
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "cublaslt", "bf16", "correctness"],
112
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -lcublasLt -lcublas -o {build_dir}/{name}",
113
+ "run_cmd": "{build_dir}/{name} 512 512 512 2 10 0"
114
+ },
115
+ {
116
+ "name": "hopper_tensor_core_bf16_async",
117
+ "source": "kernels/prototypes/hopper/tensor_core_async/kernel.cu",
118
+ "description": "Hopper BF16 async WMMA lane with cp.async double-buffered staging, 64x64x32 tiles, and four fragments per warp to cut exposed feed bubbles.",
119
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "async", "cpasync", "double-buffered"],
120
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
121
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
122
+ },
123
+ {
124
+ "name": "hopper_tensor_core_bf16_async_wide",
125
+ "source": "kernels/prototypes/hopper/tensor_core_async/kernel.cu",
126
+ "description": "Hopper BF16 async WMMA lane widened to a 64x128x32 CTA so each stage amortizes more scheduling overhead before the WGMMA/TMA path lands.",
127
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "async", "cpasync", "double-buffered", "wide"],
128
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_WARP_COL_GROUPS=4 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
129
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
130
+ },
131
+ {
132
+ "name": "hopper_tensor_core_bf16_async_wide_k64",
133
+ "source": "kernels/prototypes/hopper/tensor_core_async/kernel.cu",
134
+ "description": "Hopper BF16 async WMMA lane keeping the 64x128 CTA but doubling stage depth to 64 so each stage amortizes more feed and loop overhead.",
135
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "async", "cpasync", "double-buffered", "wide", "k64", "gap-close"],
136
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_WARP_COL_GROUPS=4 -DPYC_HOPPER_TC_TILE_K=64 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
137
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
138
+ },
139
+ {
140
+ "name": "hopper_tensor_core_bf16_async_square",
141
+ "source": "kernels/prototypes/hopper/tensor_core_async/kernel.cu",
142
+ "description": "Hopper BF16 async WMMA lane widened into a 128x128x32 CTA so the square 4096^3 regime gets more work per CTA before switching stages.",
143
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "async", "cpasync", "double-buffered", "square", "gap-close"],
144
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_WARP_ROW_GROUPS=4 -DPYC_HOPPER_TC_WARP_COL_GROUPS=4 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
145
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
146
+ },
147
+ {
148
+ "name": "hopper_tensor_core_bf16_async_square_k64",
149
+ "source": "kernels/prototypes/hopper/tensor_core_async/kernel.cu",
150
+ "description": "Hopper BF16 async WMMA square lane with a 128x128x64 CTA to test the last cheap work-per-stage lever before the WGMMA/TMA path takes over.",
151
+ "tags": ["cuda", "matmul", "hopper", "sm90", "prototype", "tensor-core", "bf16", "async", "cpasync", "double-buffered", "square", "k64", "gap-close"],
152
+ "compile_cmd": "{nvcc} -O3 -std=c++17 -lineinfo -DPYC_HOPPER_TENSOR_CORE_USE_BF16=1 -DPYC_HOPPER_TC_WARP_ROW_GROUPS=4 -DPYC_HOPPER_TC_WARP_COL_GROUPS=4 -DPYC_HOPPER_TC_TILE_K=64 -gencode arch=compute_90,code=sm_90 -gencode arch=compute_90,code=compute_90 {source} -o {build_dir}/{name}",
153
+ "run_cmd": "{build_dir}/{name} 4096 4096 4096 3 30 1"
154
+ }
155
+ ]
156
+ }
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio==5.49.1