Skip to main content
Home › Categories › Artificial Intelligence & Computing › GPU Parallel Programming: SIMT Execution, Warps, Shared SRAM, and the Roofline Model

GPU Parallel Programming: SIMT Execution, Warps, Shared SRAM, and the Roofline Model

Author: ZUVDEX Team 4 min read
gpu programming cuda warps shared memory simt warps streaming multiprocessors sm global hbm memory coalescing shared sram bank conflicts tiling arithmetic intensity roofline model cuda streams graphs triton kernels

Whereas a CPU dedicates vast die area to deep out-of-order branch predictors and giant L3 caches so a few sequential threads suffer minimal latency, a Graphics Processing Unit (GPU) dedicates its silicon to hundreds of Streaming Multiprocessors (SMs / Compute Units) running tens of thousands of lightweight threads in lockstep **Single Instruction, Multiple Threads (SIMT)** groups called **Warps**. Mastering warp divergence, coalesced HBM transactions, on-chip Shared SRAM tiling, and Samuel Williams’s Roofline Model unlocks 10×–50× faster custom AI and scientific kernels.

Key Highlights

  • GPUs hide 400-cycle HBM memory latency NOT with giant caches alone, but via zero-overhead hardware context switching across dozens of resident 32-thread Warps per Streaming Multiprocessor.
  • Memory Coalescing is rule #1 of GPU bandwidth: when 32 threads in a warp read 32 adjacent 4-byte floats, hardware merges them into a single 128-byte HBM sector burst; strided random reads waste up to 96% of memory bandwidth.
  • Tiled Matrix Multiplication (`GEMM`) and `FlashAttention` stage blocks of matrices from slow HBM into fast on-SM Shared Memory (`SRAM`) and Tensor Core registers, reusing each fetched byte dozens of times.
  • The **Roofline Model** plots Kernel Throughput (FLOPs/sec) against **Arithmetic Intensity** (`FLOPs / HBM Byte Moved`), immediately diagnosing whether a kernel is Memory-Bandwidth-Bound or Compute-Bound.

Warps, Coalescing, Shared SRAM Tiling, and the Roofline Ridge Point

Consider an accelerator with `1,000 TFLOPS` of BF16 Tensor Core compute and `3.35 TB/s` of HBM bandwidth: its Roofline ridge point sits at `1,000 / 3.35 ≈ 298 FLOPs per byte`. Any operation performing fewer than ~298 math operations per byte read from HBM—including LayerNorm, RoPE, Softmax, activation functions, and batch-size-1 LLM token decoding—is **100% Memory-Bandwidth-Bound**: buying faster ALUs does nothing unless you fuse kernels to keep intermediate tensors in registers/SRAM!

Inside each Streaming Multiprocessor, all 32 threads of a Warp execute the exact same instruction simultaneously. If an `if (x > 0) … else …` branch splits threads within the same warp ("warp divergence"), hardware executes both paths serially with inactive lanes masked off—whereas branches aligned cleanly across whole 32-thread boundaries suffer zero divergence penalty.

GPU Bottleneck Symptom in Profiler (Nsight / rocprof) Engineering Fix
Uncoalesced Global HBM Access Low HBM throughput despite memory stalls; 32 sectors/request Transpose to contiguous layout so adjacent threadIdx.x reads adjacent addresses
Kernel Launch Overhead Gaps of 5–15 μs between tiny 2 μs Python ops Capture execution into `CUDA Graphs` or fuse ops via `torch.compile` / `Triton`
Register Spilling to Local Memory Unexpected HBM traffic ("lmem") inside tight loops Tune block size / max registers per thread to preserve SM occupancy
Shared SRAM Bank Conflicts 32 threads hitting same modulo-32 4-byte SRAM bank Pad shared-memory tile stride by +1 element (`tile[32][33]`) or swizzle XOR indices

Asynchronous Tensor Memory Accelerators (TMA) and CUDA Graphs

Modern Hopper and Blackwell GPUs add dedicated hardware Tensor Memory Accelerators (TMA) and warp-specialized producer–consumer pipelines (used in FlashAttention-3): dedicated producer warps DMA-prefetch the next HBM matrix tile asynchronously into Shared SRAM while consumer warps keep Tensor Cores 100% busy on the current tile.

  • Never call `.item()`, `.cpu()`, or `torch.cuda.synchronize()` inside a training or inference loop—blocking the host CPU stalls the asynchronous GPU command queue completely!
  • Overlap data transfers (`cudaMemcpyAsync` on pinned `pin_memory=True` host pages) on a separate CUDA Stream concurrently with compute kernels.
  • Profile with NVIDIA Nsight Compute / PyTorch Profiler before guessing optimizations—check whether SM Compute or HBM DRAM throughput is near ceiling.

References & Sources

  • Kirk, David B.; Hwu, Wen-mei W.; El Hajj, Izzat — Programming Massively Parallel Processors: A Hands-on Approach (4th ed.), Morgan Kaufmann.
  • Williams, Samuel; Waterman, Andrew; Patterson, David (2009) — Roofline: An Insightful Visual Performance Model for Multicore Architectures, Communications of the ACM.
  • Tillet, Philippe; Kung, H. T.; Cox, David (2019) — Triton: An Intermediate Language and Compiler for Tiled Neural Network Computations, ACM MAPL.