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 specs
  • compute_arithmetic_intensity — FLOPS / bytes for a set of operations
  • classify_bottleneck — compute-bound vs memory-bound per layer
  • roofline_plot — text-based roofline visualization
  • Analysis of transformer layers: attention (memory-bound) vs linear (compute-bound)

Key concepts

ConceptWhat to understand
Ridge pointpeak_FLOPS / peak_BW — arithmetic intensity where compute=memory bound
Memory-bound opsElementwise (relu, add), small matmuls, LayerNorm
Compute-bound opsLarge matmuls, batched GEMM
ImplicationMemory-bound → quantize/fuse; compute-bound → tile/parallelize

Files

FilePurpose
lab.pyStubs with TODO markers
solution.pyComplete working implementation
test_lab.pypytest suite
requirements.txtDependencies

Run

pip install -r requirements.txt
python lab.py
pytest test_lab.py -v