1---2name: gpu-architecture-fundamentals3description: This skill should be used when reasoning about GPU architecture fundamentals to guide kernel optimization choices such as memory hierarchy usage, execution model mapping, block sizing, and latency-aware tuning across HIP, Triton, and PyTorch.4---56# GPU Architecture Fundamentals78## Purpose9- Reference core GPU concepts (memory hierarchy, execution model) and typical bandwidth/latency numbers to ground optimization choices.10- Provide block size heuristics and ready-to-use checklists before writing or tuning kernels.11- Map common optimization patterns across HIP, Triton, and PyTorch to pick framework-specific tactics quickly.1213## When to Use14- Planning or reviewing kernel designs where occupancy, memory bandwidth, or latency hiding are concerns.15- Selecting grid/block shapes, deciding on shared memory usage, or checking for coalesced accesses.16- Comparing optimization levers across frameworks when porting kernels.1718## How to Use19- Recall memory hierarchy: prefer registers > shared/L1 > L2 > HBM; treat HBM as ~400–800 cycle latency, registers ~0, shared ~20–30 cycles.20- Anchor bandwidth sense-checks with table values (e.g., MI300X HBM3 ~5.3 TB/s, A100 HBM2e ~2.0 TB/s).21- Choose block sizes by operation: element-wise 256–1024 threads, reduction 256–512, matmul tiles 128x128 or 256x128, conv 32x32 or 64x64.22- Apply execution model mapping: thread ↔ element/partial tile, warp/wavefront ↔ contiguous data segments, block/workgroup ↔ tiles sharing shared memory, grid ↔ full problem coverage.23- Run the optimization checklist before finalizing kernels:24 - Ensure coalesced and vectorized memory access; avoid shared memory bank conflicts.25 - Target occupancy >50%; watch register pressure and shared memory usage to avoid spilling.26 - Fuse operations where possible; leverage mixed precision when valid.27 - Overlap transfers with compute; tune block/grid dimensions; unroll small loops.28- Use pattern summaries to pick tactics per framework:29 - Memory: HIP manual strides/shared, Triton `tl.arange`/implicit tiling, PyTorch `.contiguous()`/compiler.30 - Compute: HIP manual fusion/unroll, Triton `@triton.jit` + `tl.constexpr`, PyTorch `torch.compile`/FlashAttention.31 - Parallelism: HIP block/grid + occupancy APIs, Triton autotune + constexpr block sizes, PyTorch compiler/automatic launch config.3233## Quick Checks34- If performance regresses, compare achieved block size and occupancy to table heuristics.35- If L2/HBM traffic is high, add tiling or fusion; if shared memory stalls, check bank conflicts and tile padding.36- When switching hardware, re-evaluate bandwidth and latency assumptions and retune block sizes accordingly.