BLAS Levels 1, 2, 3 — and which one earns its GPU keep
Once you have vectors and matrices, the operations BLAS organizes everything around are just three:
| Op | Level | Signature | Kernel names | Typical use |
|---|---|---|---|---|
| AXPY | BLAS-1 | y ← α·x + y | SAXPY, VectorAdd | Bias add, residual skip connection |
| GEMV | BLAS-2 | y ← A·x + y | MatVec, DenseInference | Single-token autoregressive inference |
| GEMM | BLAS-3 | C ← α·A·B + β·C | matmul, mma, wmma | Self-attention, batched inference, training |
Why does BLAS Level 3 matter so much more than 1 and 2? Arithmetic intensity. AXPY does ~1 FLOP per byte loaded — every operation requires a fresh DRAM trip. GEMV is similar. GEMM, by contrast, uses each loaded element O(k) times, so it has the FLOPs/byte ratio that GPUs are built to crush.
Roofline rule of thumb:
- Low FLOPs/byte (< 4) — you're bandwidth-bound. Your kernel waits on DRAM. AXPY, GEMV, element-wise ops live here.
- High FLOPs/byte (> 8) — you're compute-bound. ALUs / Tensor Cores are saturated. Tiled GEMM lives here.
This is why a single-token decode (GEMV-shaped: activation × weight) on a 7B model runs at like 50 tokens/s on an RTX 4090, while a batch of 64 tokens (GEMM-shaped) runs at 800. The math is the same, the FLOPs/byte ratio is what changed.