Papers
Topics
Authors
Recent
Search
2000 character limit reached

FlashAttention-3 Kernels

Updated 16 May 2026
  • FlashAttention-3 kernels are GPU-optimized attention implementations that leverage Hopper features, advanced pipelined execution, and FP8 quantization to boost LLM performance.
  • They employ warp specialization and a two-stage GEMM–softmax pipeline to achieve up to 1.7× speedup and maintain robust numerical accuracy.
  • Compiler integration and memory hierarchy optimizations further enhance efficiency, setting a new reference design for modern transformer computations on NVIDIA GPUs.

FlashAttention-3 kernels are a class of state-of-the-art GPU-optimized attention implementations that leverage Hopper architecture features such as asynchrony, advanced memory hierarchies, and low-precision support to maximize throughput and efficiency for LLM inference and training. Building on previous FlashAttention variants, FlashAttention-3 incorporates new kernel-level techniques — warp specialization, two-stage pipelined execution of matrix multiplications and softmax, and FP8 block quantization with incoherent processing — to achieve up to 1.7× speedup over FlashAttention-2, 75% peak hardware utilization on NVIDIA H100, and robust accuracy for both FP16 and FP8 numerics. These kernels set the reference for modern attention computation in LLM systems, with ongoing research extending their efficiency for edge cases such as low-head-count decoding and modern cache hierarchies (Shah et al., 2024, Font et al., 19 Mar 2026, Zhu et al., 22 Jan 2026).

1. Architectural Principles of FlashAttention-3 Kernels

FlashAttention-3 is designed to address both computational and memory-bound bottlenecks in the transformer attention mechanism. The canonical operation consists of computing a dot-product similarity (QKᵀ), applying a stable softmax, and multiplying by value vectors (softmax(QKᵀ)V), with all intermediate steps memory- and compute-intensive for long contexts and large batch sizes. The kernel organizes computation into rectangular tiles across the query, key, and value axes. On Hopper, it splits each thread block into producer and consumer warps:

  • Producer warps: Issue asynchronous TMA (Tensor Memory Accelerator) loads to pull Q, K, V tiles from HBM to shared memory without stalling main CUDA cores.
  • Consumer warps: Execute fused GEMM and softmax pipelines via warpgroup GEMM (WGMMA) instructions, interleaving computation of QKᵀ, softmax, and the final PV projection with blockwise asynchrony.
  • Circular shared-memory buffer: Employed to enable seamless pipelining, with barrier-like fast synchronization primitives (__sync_warpgroup) rather than global atomics.

This scheme enables maximum utilization of independent hardware pipelines—for example, hiding softmax exponentials under Tensor Core GEMM compute—so that both compute-bound and memory-bound phases overlap at scale (Shah et al., 2024).

2. Advanced Kernel Techniques: Asynchrony, GEMM–Softmax Pipelining, FP8 Quantization

The core methodologies in FlashAttention-3 include:

  • Warp-specialized Producer/Consumer Role Partitioning: The kernel statically allocates warps to asynchronous memory movement (TMA), freeing consumer warps to focus on the inner-product and reduction phases. The two groups handshake over a circular s-stage buffer.
  • 2-Stage GEMM–Softmax Pipeline: The softmax operation, traditionally a bottleneck, is overlapped with the blockwise (QKᵀ and PV) GEMMs in adjacent tiles. A ping-pong warpschedule enables softmax computations on one tile to execute concurrently with GEMMs on another, utilizing the memory-function unit (MFU) and Tensor Core resources concurrently. The effect is a significant reduction in cycles wasted on non-overlappable operations.
  • FP8 Block Quantization & Incoherent Processing: Hopper’s FP8 WGMMA requires k-major input with per-block scaling, achieved via:
    • On-the-fly in-kernel transpose and byte-permute mapping.
    • Per-block dynamic scaling to prevent outlier clipping.
    • Hadamard-based incoherent processing—mixing Q/K channels via orthonormal matrices fused with rotary embeddings—that preserves attention semantics while decorrelating value magnitudes, reducing quantization error by 2.6× for FP8 relative to naïve per-tensor scaling.

All steps are realized within a single scheduling domain and CUDA stream, with kernel pseudocode leveraging mma_async, commit, wait_group, and custom spinwaits for buffer handoff (Shah et al., 2024).

3. SM Occupancy and Sequence-Aware Dispatch Heuristics

Despite FlashAttention-3’s hardware-aware optimizations, Hopper kernels can underutilize SMs, particularly for autoregressive decoding with low head count ("low-head-count", as in MQA or GQA with small HKVH_{KV}). In such cases, the standard dispatch heuristic historically forced no sequence splitting (s=1) for context lengths LK512L_K\leq512, based on the assumption that parallel overhead outweighed gains for short sequences.

This leads to severe occupancy collapse—for example, Batch=1, HKV=1H_{KV}=1 launches only 4 CTAs on an H100 (132 SMs), yielding 3% SM utilization and a 20–25% latency penalty. The newly introduced sequence-aware split policy addresses this bottleneck by:

  • Applying case-based guards: s=1 for LK384L_K\leq384 or sufficient tile count; s=3 for the “low-tile boundary” (LK=512L_K=512, BatchHKV<4Batch\cdot H_{KV}<4).
  • Guaranteeing minimum CTA count sufficient to saturate αSMcount\alpha\cdot SM_{count}, with α0.51.0\alpha\sim0.5–1.0.
  • Demonstrated increases in kernel-level efficiency of 21–24% for short, low-head-count regimes, with no regressions in other shapes (Font et al., 19 Mar 2026).

Table: Split Heuristic Guards in FlashAttention-3

Condition Split Value (s) Target
nblk3nblk\leq3 (LK384L_K\leq384) 1 Short contexts
LK512L_K\leq5120, LK512L_K\leq5121 1 Enough tiles for occupancy
LK512L_K\leq5122, LK512L_K\leq5123 3 Low-tile boundary (least occupancy loss)

4. Automatic Kernel Discovery and Compiler Integration

Nautilus, an auto-scheduling tensor compiler, demonstrates that the sequence of high-level rewrites, tiling, loop transformation, and pipelining structuring that defines FlashAttention-3 can be discovered end-to-end from a mathematical specification. Starting from the operator:

LK512L_K\leq5124

Nautilus applies:

  • Algebraic fusions (streaming and in-place softmax)
  • Tiling into LK512L_K\leq5125 subblocks, mapping tiles to CTAs
  • Register tiling, double-buffered shared memory movement, warp reductions, and vectorized load/store
  • Guided autotuning and beam-search over the schedule space, targeting compute–bandwidth balance

Across >150 evaluations on GH200 and RTX 5090, Nautilus-generated kernels are within 1–5% of hand-written FlashAttention-3, and sometimes outperform via hardware-tailored tile shapes. This confirms the universality of the core tiling + fusion template underlying FlashAttention-3, and implies rapid back-end adaptation of the technique on future GPU generations (Zhao et al., 16 Apr 2026).

5. Memory Hierarchy Optimizations: L2 Cache-Aware Scan Patterns

Recent memory hierarchy analysis on new GPU architectures (e.g., NVIDIA GB10) shows that the default cyclic K/V scan in CuTile/FlashAttention kernels induces long reuse distances, resulting in high non-compulsory L2 misses once the K/V working set exceeds cache capacity. The sawtooth wavefront reordering modifies inner-KV scan order to alternate forward and backward passes per tile, reducing average and worst-case L2 reuse distances by half. Empirically, this halved L2 non-compulsory miss rate corresponds to throughput improvements of 50–67% on GB10 for large sequence lengths, with increases in kernel throughput of up to 60%. Integration requires minimal code change—a parity-based switch of scan direction within CTA loops—without altering tiling or warp-mapping (Zhu et al., 22 Jan 2026).

6. Comparative Performance and Numerical Accuracy

Comprehensive benchmarking demonstrates the following for FlashAttention-3 on NVIDIA H100:

  • Throughput (FP16): Forward kernel performance scales from ~620 TFLOPs/s (1 k seq) to ~560 TFLOPs/s (16 k seq), a 1.7×–1.65× speedup over FlashAttention-2. FP8 achieves up to ~1.2 PFLOPs/s (70% utilization).
  • Occupancy fixes: Sequence-aware split improves short context/low-head-count latency by ≈21–24%, with no regression for large or dense shapes (Font et al., 19 Mar 2026).
  • Numerical accuracy: RMSE of FlashAttention-3 kernels is consistently lower than baselines; for FP8, per-block scale and incoherent processing reduce RMSE by 2.6× over standard per-tensor scaling (Shah et al., 2024).

Table: Representative Kernel Metrics on Hopper (Batch=1, Head=128)

Variant Throughput (TFLOPs/s) RMSE (w.r.t. FP64)
FlashAttention-2 FP16 350–420 LK512L_K\leq5126
FlashAttention-3 FP16 560–640 LK512L_K\leq5127 (1.7× lower vs. baseline FP16)
FlashAttention-3 FP8 1,100–1,200 LK512L_K\leq5128 (2.6× lower vs. baseline FP8)

7. Open Questions and Future Enhancements

Areas identified for further study include:

  • Autotuning or mapping of optimal split factors s across short and edge-case sequence regimes to further improve occupancy without manual heuristics (Font et al., 19 Mar 2026).
  • Runtime adaptation of split policy via SM occupancy counters or real-time latency feedback.
  • Extending sequence-aware splitting logic to non-decode or multi-batch attention modes.
  • Exploring cross-layer fusion post-splitting for deeper kernel composition.
  • Hardware-specific memory hierarchy optimizations (e.g., sawtooth wavefront), and their interaction with compiler-generated kernel layouts on future architectures (Zhu et al., 22 Jan 2026).

By systematically integrating hardware-level asynchrony, fine-grained pipelined tiling, memory hierarchy-aware scan patterns, and low-precision numerics, FlashAttention-3 kernels define the leading practices for high-performance attention computation on contemporary NVIDIA GPUs (Shah et al., 2024, Font et al., 19 Mar 2026, Zhao et al., 16 Apr 2026, Zhu et al., 22 Jan 2026).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to FlashAttention-3 Kernels.