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⋅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-dv), 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× faster than the reference Triton implementations in the forward pass and up to 8.1× in the backward pass, up to 3.2× faster than FlashQLA, and up to 6.1× faster than FlashKDA. The Mamba-2 kernels run up to 15.9× faster than FLA and up to 4.2× faster than mamba_ssm in the forward pass, and up to 6.9× and 5.5× in the backward pass.
Figures & tables
Figure 1: Data-dependent decay.
decay α
erase gate β
write gate w
updates per token
Mamba-2
scalar
none
scalar ( Δt )
1
GDN
scalar
scalar
tied to β
1
GDP
scalar
scalar per update
tied to β
nh
KDA
per key channel
scalar
tied to β
1
GDN-2
per key channel
per key channel
per value channel
1
Table 1: The five variants and how finely their gates are resolved.
MMA
M
N
K
K@KT
C
C
dqk
Q@KT
C
C
dqk
K@S
C
dv
dqk
Q@S
C
dv
dqk
T@Y
C
dv
C
A@U
C
dv
C
Table 2: Natural token-major shapes of the forward’s seven MMAs per chunk.
MMA
M
N
K
K@KT
C
C
dqk
unchanged
Q@KT
C
C
dqk
unchanged
ST@KT
dv
C
dqk
swap-AB
ST@QT
dv
C
dqk
swap-AB
YT@TT
dv
C
C
swap-AB
UT@AT
dv
C
C
swap-AB
Table 3: The same seven MMAs after swap-AB.
Figure 2: The stacked score MMA for GDN. K and Q share the right operand KT , so one M=128 MMA yields both KKT and QKT .
MMA
M
N
K
[K;Q]@KT
128
64
128
fused pair
ST@KT
128
64
128
swap-AB
ST@QT
128
64
128
swap-AB
YT@TT
128
64
64
swap-AB
UT@AT
128
64
64
swap-AB
U′T@K
128
128
64
swap-AB
Table 4: The GDN and GDP forward’s six MMAs per chunk after swap-AB and stacking, at C=64 .
Figure 3: The blockwise inverse of M[t] and how it occupies a warpgroup. Top Left : The diagram shows one 64×64M[t] with the blocks for each of steps 1 to 4, colored by step. Top Right : The diagram shows which of the four warps have work in each step when one chunk is inverted at a time. Steps 1, 3, and 4 have work for only two warps, so warps 2 and 3 sit idle. Bottom : The diagram shows the same schedule for a chunk pair. Warps 0 and 1 invert M[t] while warps 2 and 3 invert M[t+1] . All four warps are busy in every step.
Figure 4: The blockwise inverse of one 16×16I+N for KDA and GDN-2. Left : The diagram shows the blocks each step touches. Step 1 inverts the four 4×4 diagonal blocks by the two-term series, step 2 corrects two 4×4 blocks into 8×8 inverses, and step 3 corrects one 8×8 block. Right : The diagram shows the six dependent MMA stages of the register-MMA warp, colored by step, with the product each stage forms.
Figure 5: Checkpointing every n=4C tokens. Sckpt[0] is the incoming state, and the final state is a separate output.
Figure 6: Forward kernel breakdown. FLA runs five steps that communicate through global memory. FlashKDA runs a chunk-parallel preparation kernel and a recurrence kernel. FlashQLA runs one fused kernel after a separate gate cumsum and inverse kernel. Ours is a single persistent kernel with the gate scan, the inverse, and every per-chunk MMA inside of it.
Figure 7: Backward kernel breakdown. FLA runs seven steps, two of which recompute forward intermediates. FlashQLA fuses the main backward pass into one kernel with a separate state recompute kernel and a reverse cumsum kernel. Ours fuses the state recompute and all eighteen backward MMAs into a single persistent kernel. FlashKDA has no backward.
Warps
Role
0–3
compute group 0: runs the KKT and QKT epilogues and the 64×64 blockwise inverse that yields T
4–7
compute group 1: computes Y=V−KS , downcasts U , runs the O epilogue, and rescales S
8
gate warp: loads the gate logits and β and runs the prefix scan into Γ , Λ , and γ
9
TMA warp: loads the Q , K , and V tiles
10
MMA warp: issues every tcgen05 MMA
11
epilogue warp: stores O and the state checkpoints
Table 5: Warp roles of the GDN and GDP forward kernel.
Figure 8: The GDN and GDP forward pipeline over a chunk pair. Blue is chunk t , orange chunk t+1 , and gray the next pair. Purple is the blockwise inverse of Section 4.4 , labeled with its steps. The MMA warp issues the next pair’s two fused [K;Q]KT MMAs after the U MMA of chunk t and after its state update, where it would otherwise wait for the U downcast and for the S epilogue that restages the state. Compute group 0 works one pair ahead, as it is on the critical path.
Warps
Role
0–7
compute group 0, two ping-pong warpgroups: runs the per-channel gate prefix scan, computes the decay-folded operands Q , K , K , and K , and runs the S epilogue for the first half of the key channels
8–11
compute group 1: stages Y and U , runs the S epilogue for the second half of the key channels, and runs the O epilogue
12
register-MMA warp: computes KKT and the blockwise inverse that yields T
13
MMA warp: issues every tcgen05 MMA
14
TMA warp: loads the Q , K , V , and gate tiles and stages β one chunk ahead
15
epilogue warp: computes A on register MMAs and stores O and the state checkpoints
Table 6: Warp roles of the KDA and GDN-2 forward kernel.
Figure 9: The KDA and GDN-2 forward pipeline over a single main-loop iteration. Blue is chunk t , gray chunk t−1 , orange chunk t+1 , and yellow chunk t+2 , and the red dashed box is a wait of the MMA warp. Compute group 0 is drawn as its two ping-pong groups of four warps, which alternate chunks. In this iteration, warps 4 to 7 finish chunk t+1 ’s gate scan and decay-folded operands, and warps 0 to 3 run chunk t+2 ’s.
P
forward
backward
≥3
intra-card CP (Section 6.1 )
intra-card CP
2 , dv=128
split- dv (Section 6.2 )
intra-card CP
2 , dv=64
split-K (Section 6.3 )
intra-card CP
1
split-K
split-K
<1
tail (Section 6.4 )
same
Table 7: The plan per number of segments P . Split-K applies to GDN and GDP only, and KDA and GDN-2 run uncut where it is listed.
Figure 11: Intra-card CP in the forward pass. Every segment is summarized from a zero initial state and from an identity initial state, the summaries are chained in fp32 to recover each segment’s true incoming state Sj , and the main kernel then runs the segments as independent sequences.
Figure 12: Split- dv in swap-AB orientation. The two CTAs own the two halves of the value rows of ST and of the value-side tiles, and both load or compute the shared operands.
MMA
M
N
K
K@KT
C
C
dqk
shared
Q@KT
C
C
dqk
shared
ST@KT
dv/2
C
dqk
split
ST@QT
dv/2
C
dqk
split
YT@TT
dv/2
C
C
split
UT@AT
dv/2
C
C
split
Table 8: The seven MMAs of Table 3 per CTA under split- dv .
Figure 13: Split-K in the forward pass on a toy sequence. CTA 0 runs the tokens before the cut and writes their outputs. CTA 1 starts from a zero state at the beginning of the warmup, only accumulates the state through it, and writes outputs from the cut onward.
Figure 14: LPT scheduling on a toy example. Suppose we have eight work items of lengths 2, 2, 2, 2, 2, 2, 8, and 6 chunks on four CTAs. Each CTA takes the next item as it is free. In the naive order, the two long items start last, so one CTA finishes at 10 and another at 8 while the other two idle from 4. Sorted longest first (LPT), the long items start at the beginning. The total time is now the length of the longest item, which is optimal for this case.
Figure 15: Wave quantization on a toy machine with four SMs and five tiles of eight chunks. Left : With one CTA per tile, the second wave keeps one SM busy while three idle. Right : The four tiles of the full wave run together, and the leftover tile is cut into four segments by the plan of Table 7 .
Figure 16: Intra-card CP in the backward pass. Each segment’s backward summary kernel produces Gj from a zero outgoing gradient. Mj is reused from the forward to recover the true dSj . Then, we run the main kernel started from dSj .
Ours
Transform
Pass
FLA
FlashQLA
FlashKDA
GDN, GDP
KDA, GDN-2
L2 normalization
forward
separate
separate
preparation
separate
fused
backward
separate
separate
–
fused
fused
write strength
forward
separate
–
preparation
fused
fused
backward
separate
–
–
fused
fused
gate
forward
cumsum
–
–
fused
–
Table 9: Location of each transform in each implementation and pass. Separate means kernels of its own around the recurrence, fused means inside the recurrence kernels, and preparation and cumsum name FlashKDA’s preparation kernel and FLA’s gate cumsum kernel. A dash marks a transform the implementation does not provide.
Library
Version
Commit
FLA
0.6.0
9f38d249
mamba_ssm
2.3.2.post1
e9594ce1
FlashQLA
0.1.3
da06429d
FlashKDA
master
7afb9f45
cuDNN Frontend
1.34.0
develop
Table 10: The library versions for the performance numbers below.
Figure 17: Forward throughput at B=1 and H=16 on GB200 sweeping over the sequence length in tokens. dqk=128 throughout, and dv=128 except for GDP ( nh=3 ) and Mamba-2 at dv=64 . The label above each group is the speedup of Ours over FLA.
Figure 18: Backward throughput at B=1 and H=16 on GB200 sweeping over the sequence length in tokens, at the same head dimensions as Figure 17 . The label above each group is its speedup over FLA.
Figure 19: Forward throughput at B=4 on GB200 sweeping over the sequence length in tokens. H=64 for Mamba-2 ( Hqk=8 ), GDN ( Hqk=16 ), and GDN-2, H=40 for GDP, and H=96 for KDA, at the head dimensions of Figure 17 . The label above each group is the speedup of Ours over FLA.
Figure 20: Backward throughput at B=4 on GB200 sweeping over the sequence length in tokens, at the same head counts and dimensions as Figure 19 . The label above each group is its speedup over FLA.
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Warps
Role
0–3
compute group 0: runs the KKT and QKT epilogues and the 64×64 blockwise inverse that yields T , and reduces the M terms of dβ and dg and the state term of dg
4–7
compute group 1: rescales dS , runs the dV and dQ epilogues, and reduces the Y terms of dβ and dg and the Q terms of dg
8–11
compute group 2: rescales the inter-chunk dK , reduces the K terms of dg , and runs the dK epilogue
12
MMA warp: issues every tcgen05 MMA
13
TMA warp: loads the Q , K , V , and dO tiles and the entering state from the checkpoint series
14
gate warp: loads the gate logits and β and stores dg and dβ
Appendix
Table 11: Warp roles of the GDN and GDP backward kernel.
Figure 21: The GDN and GDP backward pipeline. Blue is chunk t , gray chunk t+1 , and purple the blockwise inverse.
Warps
Role
0–3
compute group 0: runs the per-channel gate prefix scan and computes the decay-folded operands Q , K , and K
4–7
compute group 1: rescales dS , stages Y , dU , U , dY , and −β⊙dY , runs the dV epilogue (and the dw epilogue for GDN-2), and reduces and stores dβ for KDA
8–11
compute group 2: forms the dγ dot products and runs the dQ , dK , and dg epilogues (and the per-channel dβ epilogue for GDN-2) with the dA diagonal, the L2-norm backward, and the reverse cumulative sum
12
register-MMA warp: computes KKT , the blockwise inverse that yields T , dM , and the β term of dβ
13
MMA warp: issues every tcgen05 MMA
14
TMA warp: loads the Q , K , V , dO , and gate tiles and the entering state from the checkpoint series
Appendix
Table 12: Warp roles of the KDA and GDN-2 backward kernel.
Figure 22: The KDA and GDN-2 backward pipeline. Blue is chunk t , gray chunk t+1 , visited before it, and orange chunk t−1 , visited next.