GPU Computing & Systems
KernelForge
Custom GPU Kernels: Fused Attention & FP8 GEMM in Triton
Problem
Standard PyTorch attention and GEMM operations repeatedly materialize large intermediate tensors to global GPU memory (HBM), bottlenecking training at memory bandwidth rather than compute throughput.
Solution
Implemented a fused attention kernel that tiles Q, K, V into on-chip SRAM computing online softmax without writing the full NxN attention matrix to HBM. Built a block-quantized FP8 GEMM kernel with per-tile scale factors.
Architecture
Triton programs on a 2D grid over sequence tiles. Each program block loads a Q tile and iterates K/V tiles from SRAM, maintains running softmax statistics for numerically stable online normalization, and accumulates weighted V without global memory I/O.
Real-World Impact
Fused attention kernel runs 2.1x faster than PyTorch SDPA at sequence length 2048. FP8 GEMM reduced memory footprint by 50% vs FP32 with less than 0.3% perplexity degradation.
Challenges Faced
Numerically stable online softmax across SRAM tiles without global reduction; FP8 scale overflow in quantized accumulation.
Key Learnings
Roofline model analysis, GPU memory hierarchy mechanics, Triton programming model, and hardware-aware optimization.