Skip to content

cuDNN Linear Attention: Optimized Mamba-2, GDN, GDP, KDA, and GDN-2 Kernels for NVIDIA GPUs

Joshua Park, Jingze Cui, Sherry Jiang, Mengyu Guo, Anerudhan Gopal, Vedaanta Agarwalla, Timmy Liu, Yu-Jung Chen, Yang Xu

cs.CL

Abstract

Linear attention replaces the softmax attention of Transformers with a fixed-size recurrent state, so that the runtime of prefill grows linearly rather than quadratically with the sequence length and the runtime of every decode step is constant in it. Many recent models have adopted a hybrid architecture where some layers swap dense attention for linear attention variants. cuDNN now ships optimized fused kernels for five linear attention variants, Mamba-2, Gated DeltaNet (GDN), Gated DeltaProduct (GDP), Kimi Delta Attention (KDA), and Gated DeltaNet-2 (GDN-2), on Blackwell (SM100, SM103), covering the training forward and backward passes. All of the kernels are open source and ship in cuDNN at https://github.com/NVIDIA/cudnn-frontend. In this paper, we walk through the optimizations that produce speedups over the state-of-the-art baselines. We start the kernel design from a single persistent kernel per pass. Then, in low B⋅HB \cdot H settings, where a grid of one CTA per (batch, head) pair does not cover the SMs, we use intra-card context parallelism (intra-card CP) or a split of the value dimension (split-dvd_v), both introduced by prior work in FlashQLA. We also fuse the other components that surround the linear attention operation in the block, the L2 normalization of the queries and keys and the gate and write-strength transforms, in both the forward and the backward pass. On GB200, the fused kernels for the four delta-rule variants run up to 7.1×7.1\times faster than the reference Triton implementations in the forward pass and up to 8.1×8.1\times in the backward pass, up to 3.2×3.2\times faster than FlashQLA, and up to 6.1×6.1\times faster than FlashKDA. The Mamba-2 kernels run up to 15.9×15.9\times faster than FLA and up to 4.2×4.2\times faster than mamba_ssm in the forward pass, and up to 6.9×6.9\times and 5.5×5.5\times in the backward pass.

Create a lesson

Metadata

Comments
35 pages, 22 figures, 12 tables