Lab 01 — Roofline Analyzer
Phase: 07 — Profiling & Performance Engineering | Difficulty: ⭐⭐⭐⭐☆ | Time: 2–3 hours
The roofline model is the foundational tool for diagnosing compute-bound vs memory-bound bottlenecks.
What you build
RooflineModel— computes peak FLOPS and memory bandwidth from hardware specscompute_arithmetic_intensity— FLOPS / bytes for a set of operationsclassify_bottleneck— compute-bound vs memory-bound per layerroofline_plot— text-based roofline visualization- Analysis of transformer layers: attention (memory-bound) vs linear (compute-bound)
Key concepts
| Concept | What to understand |
|---|---|
| Ridge point | peak_FLOPS / peak_BW — arithmetic intensity where compute=memory bound |
| Memory-bound ops | Elementwise (relu, add), small matmuls, LayerNorm |
| Compute-bound ops | Large matmuls, batched GEMM |
| Implication | Memory-bound → quantize/fuse; compute-bound → tile/parallelize |
Files
| File | Purpose |
|---|---|
lab.py | Stubs with TODO markers |
solution.py | Complete working implementation |
test_lab.py | pytest suite |
requirements.txt | Dependencies |
Run
pip install -r requirements.txt
python lab.py
pytest test_lab.py -v