Thinking in Rooflines: Interactive Notes on GPU Efficiency

A starter post demonstrating interactive React islands, Expressive Code, Mermaid diagrams, sidenotes, and KaTeX math.

#systems#gpu#meta

When optimizing ML kernels or distributed training loops, most performance bugs boil down to one question: are we waiting on tensor cores, or are we waiting on memory?Williams, Waterman, and Patterson (2009) introduced the Roofline model to visualize the transition between memory-bandwidth-bound and compute-bound regimes on a single log-log plot.

This sample post serves as a live kitchen sink for luosuu.github.io/blog — built with Astro and MDX so you can combine calm, publication-style prose with interactive visualizations.

Arithmetic Intensity

For a dense projection Y=XWY = X W with activations X∈RM×KX \in \mathbb{R}^{M \times K} and weights W∈RK×NW \in \mathbb{R}^{K \times N}, the total floating-point operations and bytes moved between HBM and SRAM are:

AI(M,K,N)=2MKNb⋅(MK+KN+MN)\text{AI}(M, K, N) = \frac{2 M K N}{b \cdot (M K + K N + M N)}

where bb is the element size in bytes (b=2b = 2 for bf16, b=1b = 1 for fp8). When MM is small (for instance, single-request autoregressive decode or sparse MoE experts with small routed token counts), KNK N dominates the denominator and the kernel becomes strongly memory-bound.

Interactive Roofline Explorer

Drag the sliders below to see how batch/token count MM, hidden dimension DD, and precision shift a GEMM across the H100 ridge point. Because this is an Astro React island hydrated with client:visible, it only ships JS when scrolled into view.

H100 SXM (989 TFLOP/s · 3.35 TB/s)
Memory-bound (41% peak)
11010010001101001000ridge 295 FLOP/BArithmetic Intensity (FLOP / Byte)Attained TFLOP/s
AI: 120.5 FLOP/B
Attained: 404 TFLOP/s
HBM Traffic: 35.7 MB
Interactive H100 SXM Roofline for a square GEMM (K = N = D). Lowering precision from BF16 to FP8 doubles peak compute and pushes the ridge point right, requiring larger token batches to stay compute-bound.

Syntax-Highlighted Code Blocks

Expressive Code renders clean syntax highlighting with filenames, line highlights, and copy buttons — synced automatically with light and dark mode.

bench_gemm.py
import torch
def measure_tflops(m: int, k: int, n: int, iters: int = 50) -> float:
a = torch.randn((m, k), device="cuda", dtype=torch.bfloat16)
b = torch.randn((k, n), device="cuda", dtype=torch.bfloat16)
torch.cuda.synchronize()
start, end = torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True)
start.record()
for _ in range(iters):
_ = a @ b
end.record()
torch.cuda.synchronize()
secs = start.elapsed_time(end) / 1e3 / iters
return (2 * m * k * n) / secs / 1e12
metrics.rs
pub fn arithmetic_intensity(m: usize, k: usize, n: usize, elem_bytes: usize) -> f64 {
let flops = (2 * m * k * n) as f64;
let bytes = ((m * k + k * n + m * n) * elem_bytes) as f64;
flops / bytes
}

Architecture Diagrams with Mermaid

Any fenced mermaid code block renders directly into a clean diagram card and re-themes automatically if the reader toggles dark mode:

flowchart LR
    A[Router Gate] --> B[Token Dispatch<br/>All-to-All]
    B --> C[Local Expert GEMMs<br/>Grouped BF16 / FP8]
    C --> D[Token Combine<br/>All-to-All]
    D --> E[Residual Add + Norm]

Feel free to edit or replace this post under src/content/posts/ when you publish your first article.

Citation

If you find this post useful in your work, you can cite it as:

@misc{zhong2026rooflineandsys,
  author = {Tianle Zhong},
  title  = {Thinking in Rooflines: Interactive Notes on GPU Efficiency},
  year   = {2026},
  url    = {https://luosuu.github.io/blog/posts/roofline-and-systems-notes/}
}