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 with activations and weights , the total floating-point operations and bytes moved between HBM and SRAM are:
where is the element size in bytes ( for bf16, for fp8). When is small (for instance, single-request autoregressive decode or sparse MoE experts with small routed token counts), dominates the denominator and the kernel becomes strongly memory-bound.
Interactive Roofline Explorer
Drag the sliders below to see how batch/token count , hidden dimension , 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.
Syntax-Highlighted Code Blocks
Expressive Code renders clean syntax highlighting with filenames, line highlights, and copy buttons — synced automatically with light and dark mode.
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 / 1e12pub 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/}
}