§ 01
PROBLEM
PROBLEM
What it had to solve.
PyTorch's default attention is easy to reach for but leaves performance on the table — especially at long context, where the quadratic memory access dominates latency.
End-to-end CUDA implementation of scaled dot-product attention and FFN layers on NVIDIA A100. Profiled compute- vs memory-bound regimes against cuBLAS and PyTorch native ops.

PyTorch's default attention is easy to reach for but leaves performance on the table — especially at long context, where the quadratic memory access dominates latency.
Three kernel variants were implemented: a naive baseline, a tiled shared-memory version, and a fused softmax-matmul. Each was profiled with Nsight Compute to characterize the compute-vs-memory split across sequence lengths.
Fused kernel hit 42% of A100 peak FLOPs at 4K context, outperforming PyTorch native by 1.4× and landing within 15% of cuBLAS for representative workloads.