Introduction
Gated DeltaNet (GDN) [1] and Kimi Delta Attention (KDA) [2] are linear-attention operators with a matrix state per head that is updated by a gated delta rule. Per token, with the state ,
where the decay is one scalar per head and token for GDN and one value per channel for KDA. Prefill applies this recurrence to a whole prompt batch: variable-length sequences packed along the token axis.
The standard way to make this fast is the chunkwise form of the delta rule [3]: split a sequence into chunks, turn the products of rank-one updates inside a chunk into a small triangular solve, and carry the state only from chunk to chunk. That leaves two kinds of work with opposite characters. Everything that does not depend on the state (gates, cumulative decays, the chunk's Gram matrices and the triangular solve) is parallel over every chunk of the batch, and it is dominated by memory traffic. The state chain is serial over the chunks of a sequence, and its latency is set by the longest sequence times the cost of one chunk. Which of the two dominates depends on the batch: a few short sequences make the chain short and the fixed costs visible, a packed batch of thousands of tokens over many heads makes the traffic dominant, and one long sequence over few heads makes the chain the critical path while most of the GPU sits idle. The question of this task is how to decompose the operator so that latency stays low across all of these, for both operators.
The field's answers are a set of specialised kernels: the FLA chunk kernels the starter calls, FlashKDA's two-kernel forward for KDA, contest kernels that dispatch between several kernel families by batch shape, and GDN kernels with context parallelism, which split a long sequence across SMs, such as the one in FlashInfer [4]. We propose a single decomposition, written from scratch in CUDA, that serves both operators and every batch shape, with one planner that chooses how to cut the work for each batch.
Method
Throughout, a chunk has tokens. Within a chunk let be the cumulative log-decay (a vector over the key channels for KDA, a scalar for GDN) and the decay over the whole chunk. With the decayed operands
the strictly lower Gram matrix , the lower matrix and
one chunk maps the state to
Only the products that involve , directly or through , are on the serial chain. , , , , and depend on the inputs alone. Our decomposition is built around that split.
Prepare: all state-independent work, parallel over chunks
The prepare kernel runs one CTA per group of consecutive chunks and per head. It reads the raw , , gate and inputs (every strided access to them happens here) and computes the gates, the cumulative decays, the two Gram matrices on tensor cores and the triangular solve. For KDA it also normalises and , as the operator definition requires. Its output is one contiguous operand block per (chunk, head) of 13,824 bytes, holding , , , , and in 16-bit floating point (fp32 for ), laid out "fragment major": the bytes one lane feeds to one tensor-core instruction are adjacent, so the consumer loads each operand with one conflict-free shared-memory read per instruction and no reshuffling.
The triangular solve is a forward substitution, one column of per lane, on the matrix in fp32:
if (isA) {
// forward substitution, one column of T per lane
const int m = lane & 15;
float t[C];
#pragma unroll
for (int i = 0; i < C; ++i) t[i] = (i == m) ? 1.f : 0.f;
#pragma unroll
for (int nt = 0; nt < 2; ++nt) {
const int j0 = 8 * nt + 2 * tig;
sm.Abuf[g8][j0] = acc[nt][0];
sm.Abuf[g8][j0 + 1] = acc[nt][1];
sm.Abuf[g8 + 8][j0] = acc[nt][2];
sm.Abuf[g8 + 8][j0 + 1] = acc[nt][3];
}
__syncwarp();
#pragma unroll
for (int jx = 0; jx < C; ++jx) {
const float tj = sm.beta[jx] * t[jx];
t[jx] = tj;
#pragma unroll
for (int i = jx + 1; i < C; ++i) t[i] -= sm.Abuf[i][jx] * tj;
}The chunk size is tied to the numerics. For KDA the decay sits inside the Gram inner product, so and are formed from -scaled and -scaled keys. The operator's bounded "safe gate" keeps each per-token log-decay above , so within a 16-token chunk , which stays inside the exponent range of fp32 and bf16. The -scaled keys are stored in bf16, which has the exponent range of fp32, while the decayed keys and queries, scaled by factors no larger than one, go into the operand block in fp16. For GDN the decay is a scalar, so the kernel forms the raw Gram matrices and multiplies each entry by instead.
GDN has a second structural fact that we exploit: its grouped values mean two value heads share one query/key head, so , and would be identical up to the gates. The GDN prepare kernel therefore runs per query/key head and writes the raw , and once (a shared 12,288-byte head block), plus a 1,536-byte tail per value head with , and the gate scalars. The pass kernel then applies and to its accumulators rather than to the operands.
Pass: the state never leaves registers
The pass kernel runs the chain over a run of chunks of one sequence and head (a task). The state is held
transposed, (rows , columns ), in the fp32 accumulator registers of m16n8k16 tensor-core
instructions: each warp owns one or two 16-row slices of . The accumulator layout of one product is the
A-operand layout of the next, so the state feeds the next product after a conversion to 16-bit in registers, with
no shuffles and no trip through shared memory. Per chunk, ,
then and , and finally the state update:
// ---- state update: S^T <- S^T diag(gt) + U^T Kr
{
float gsc = 1.f;
if (SG) gsc = *reinterpret_cast<const float*>(blk + OFF_GT);
#pragma unroll
for (int nt = 0; nt < 16; ++nt) {
float2 gv = make_float2(gsc, gsc);
if (!SG) gv = *reinterpret_cast<const float2*>(blk + OFF_GT + (8 * nt + 2 * tig) * 4);
const uint2 bkr = *reinterpret_cast<const uint2*>(blk + OFF_KR + (nt * 32 + lane) * 8);
#pragma unroll
for (int mt = 0; mt < NM; ++mt) {
s[mt][nt][0] *= gv.x; s[mt][nt][1] *= gv.y; s[mt][nt][2] *= gv.x; s[mt][nt][3] *= gv.y;
mma_f16(s[mt][nt], uk[mt], bkr.x, bkr.y);
}
}
}The operand blocks arrive through a ring of four slots, by one bulk asynchronous copy per chunk (two for GDN, head
and tail); values and outputs
move through tiled asynchronous copies, and no strided global-memory instruction sits on the chain. A CTA serves
either 64 state rows with four state warps (NM = 1, two CTAs per head) or all 128 rows (NM = 2, one CTA per
head). In the NM = 1 variant a fifth warp issues every copy and waits for the stores, so the four state warps
contain no lane-dependent control flow at all.
Exact context parallelism
A long sequence would make one task the critical path. Because one chunk is an affine map of the state, for fixed and in the transposed orientation, a block of consecutive chunks is one too, and its map can be computed without knowing the state it starts from: run the same pass kernel from the identity with the values set to zero to obtain , and from zero with the real values to obtain . The task modes encode exactly this:
// ---- context-parallel record: one per (block >= 1 of a split sequence, head) ----
constexpr int REC_MT = 0; // M^T fp16, B-fragment major: 8 bytes ((kt*16+nt16)*32+lane), word w, half r&1
constexpr int REC_NT = 32768; // N^T fp32, D-fragment major: 16 bytes ((sl*16+nt16)*32+lane)
constexpr int REC_SB = 98304; // block start state, fp32, D-fragment major
constexpr int REC = 163840;
// pass task modes
constexpr int MODE_FIRST = 0; // from state_in, emits outputs; final -> state_out (slot < 0) or REC_SB[slot]
constexpr int MODE_M = 1; // identity init, v = 0, no outputs; final -> REC_MT[slot]
constexpr int MODE_N = 2; // zero init, no outputs; final -> REC_NT[slot]
constexpr int MODE_OUT = 3; // from REC_SB[slot], emits outputs, no final stateWhen any sequence of the batch is cut, three launches follow the prepare kernel. In the first pass kernel the first block runs normally from the true initial state while every later block computes in parallel. A short serial fix-up kernel composes
on tensor cores, with four CTAs per (sequence, head) and two warps per 16-row slice that exchange their halves of the 16-bit operand through shared memory; in fp32 is the accumulator's starting value. A second pass kernel then emits the outputs of all later blocks in parallel from their now-known start states. Nothing is approximated: the result equals the serial chain up to floating-point rounding ( is stored in fp16, and the start states in fp32).
#pragma unroll
for (int kt = 0; kt < 8; ++kt) {
const uint4 x = sm.xb[sl][kt >> 2][kt & 3][lane];
sa[kt][0] = x.x; sa[kt][1] = x.y; sa[kt][2] = x.z; sa[kt][3] = x.w;
}
#pragma unroll
for (int j = 0; j < 8; ++j) {
const float4 x = *reinterpret_cast<const float4*>(buf + 32768 + ((sl * 16 + 8 * half + j) * 32 + lane) * 16);
s[j][0] = x.x; s[j][1] = x.y; s[j][2] = x.z; s[j][3] = x.w;
}
#pragma unroll
for (int kt = 0; kt < 8; ++kt) {
#pragma unroll
for (int j = 0; j < 8; ++j) {
const uint2 bm = *reinterpret_cast<const uint2*>(buf + ((kt * 16 + 8 * half + j) * 32 + lane) * 8);
mma_f16(s[j], sa[kt], bm.x, bm.y);
}
}The planner: a makespan model over cuts
Cutting is not free. Every chunk of a later block is processed three times (the pass, the pass and the output pass), and each cut adds a serial fix-up step. Whether a cut pays off depends on the whole batch: how many tasks compete for the resident CTAs, how long the longest chain is, and whether the kernel is bound by memory traffic. The planner, written in Python and run once per batch layout, estimates the latency of the pass and fix-up kernels as the largest of three bounds: the longest task (chunks times a per-chunk latency ), the total work over the CTAs that can be resident at once, and the memory traffic:
Here is the number of CTAs per task over the resident CTA slots and the traffic cost of one chunk over all
heads.
The constants are measured latencies of our own kernels: or microseconds per chunk for
NM = 1 or 2, , , per block, and a
transition pass carries of an output pass's traffic.
def _makespan(nchs, P, H, nm):
"""Estimated latency of the pass / fix kernels for block counts P (one per sequence).
A pass kernel takes the largest of three bounds: its longest task (chunks * tau), its total CTA-chunks over the
CTAs that are resident at once (they queue otherwise), and its memory traffic (operand blocks, values and
outputs per chunk and head). Cutting a sequence into p blocks replaces its chain of nch chunks by two passes
over nch / p chunks (transition maps, then outputs) plus p - 1 serial fix-up steps, at the price of 2.3x the
work and traffic.
"""
tau = TAU[nm]
queue = H * (2 // nm) / SLOTS # CTAs per task over the resident CTAs
mem = H * MEM[nm]
crit_a = crit_c = fix = 0.0
work_a = work_c = traf_a = traf_c = 0.0
for nch, p in zip(nchs, P):
if p <= 1:
crit_a = max(crit_a, nch * tau)
work_a += nch * tau + T_TASK
traf_a += nch
else:
bc = -(-nch // p)
nb = -(-nch // bc)
crit_a = max(crit_a, bc * tau)
crit_c = max(crit_c, bc * tau)
work_a += (bc + 2 * (nch - bc)) * tau + (2 * nb - 1) * T_TASK
work_c += (nch - bc) * tau + (nb - 1) * T_TASK
traf_a += bc + 2 * MN_TRAFFIC * (nch - bc)
traf_c += nch - bc
fix = max(fix, (nb - 1) * T_FIX)
t = T_PASS + max(crit_a, work_a * queue, traf_a * mem)
if fix > 0.0:
t += fix + 1.0 + T_PASS + max(crit_c, work_c * queue, traf_c * mem)
return tThe search first tries a one-parameter family, a common block length (on a geometric grid with ratio
and at least 4 chunks) for every sequence of at least chunks, which finds the solutions in which several
long sequences must be cut together; it then runs coordinate descent on the three sequences with the longest
critical paths, and it does all of this for both values of NM.
best = None
top = max(nchs) if nchs else 0
lengths = sorted({max(MIN_BLOCK, int(round(MIN_BLOCK * 1.19 ** e))) for e in range(40)
if MIN_BLOCK * 1.19 ** e <= max(top, MIN_BLOCK)})
for nm in (1, 2):
tau = TAU[nm]
P = [1] * len(nchs)
cur = _makespan(nchs, P, H, nm)
for B in lengths:
cand = [(-(-nch // B) if nch >= B + MIN_BLOCK else 1) for nch in nchs]
t = _makespan(nchs, cand, H, nm)
if t < cur - 1e-9:
cur, P = t, candThe plan depends only on cu_seqlens and the head count, and is cached on that tensor, which the task's interface permits; the
operand-block and context-parallel scratch buffers are cached per batch layout, with the least recently used
layouts dropped beyond 32 GiB in total. The planner also sets how many chunks one prepare CTA streams: one per CTA
while all of them fit on the GPU at once, and up to 16 otherwise.
Results
| Method | ① | ② | ③ | ④ | ⑤ | ⑥ | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Correctness ↑ | Speed-up over starter ↑ | Correctness ↑ | Speed-up over starter ↑ | Correctness ↑ | Speed-up over starter ↑ | Correctness ↑ | Speed-up over starter ↑ | Correctness ↑ | Speed-up over starter ↑ | Correctness ↑ | Speed-up over starter ↑ | |
| Claude Fable 5.2 | 1.000 | 2.783 | 1.000 | 1.799 | 1.000 | 3.367 | 1.000 | 2.213 | 1.000 | 2.700 | 1.000 | 2.861 |
| FLA chunk kernels | 1.000 | 1.004 | 1.000 | 1.000 | 1.000 | 1.005 | 1.000 | 0.999 | 1.000 | 1.000 | 1.000 | 0.999 |
| FLA fused recurrent | 1.000 | 0.624 | 1.000 | 0.067 | 1.000 | 0.613 | 1.000 | 0.104 | 1.000 | 0.198 | 1.000 | 0.229 |
| Kachua | 1.000 | 3.172 | 0 | 1.059 | 1.000 | 1.001 | 1.000 | 0.999 | 1.000 | 1.000 | 1.000 | 1.000 |
| FlashInfer | 1.000 | 0.873 | 1.000 | 1.293 | 1.000 | 0.997 | 1.000 | 1.007 | 1.000 | 1.001 | 1.000 | 1.000 |
| FlashQLA | 1.000 | 1.146 | 1.000 | 1.142 | 1.000 | 1.001 | 1.000 | 1.010 | 1.000 | 1.000 | 1.000 | 0.999 |
| FlashKDA, single kernel | 1.000 | 1.003 | 1.000 | 0.999 | 1.000 | 1.320 | 1.000 | 0.882 | 1.000 | 1.713 | 1.000 | 1.937 |
| FlashKDA | 1.000 | 3.167 | 1.000 | 1.332 | 1.000 | 1.327 | 1.000 | 1.002 | 1.000 | 1.708 | 1.000 | 1.952 |
- ① Gated DeltaNet prefill (Qwen3-Next layer, TP4) · short batches, at most 512 tokens
- ② Gated DeltaNet prefill · long batches, 513 to 8K tokens
- ③ Kimi Delta Attention prefill · Kimi Linear layer, TP4, 8 heads · short batches
- ④ Kimi Delta Attention prefill · 8 heads · long batches
- ⑤ Kimi Delta Attention prefill · 64 heads · long batches
- ⑥ Kimi Delta Attention prefill · 96 heads · long batches
Our kernels are correct on every setting and faster than the starter's FLA chunk kernels on every setting, by a factor of 1.799 on GDN-long to 3.367 on KDA-short.
On five settings we are ahead of every published baseline. The margins are largest on KDA-short, where we reach 3.367 against 1.327 for the strongest baseline there (Per-batch dispatch), and on KDA-long, 2.213 against 1.010 (FlashQLA). On KDA-h64-long and KDA-h96-long we reach 2.700 and 2.861, against 1.713 (FlashKDA [2]) and 1.952 (Per-batch dispatch). GDN-long has the smallest lead and our lowest speedup: 1.799 against 1.332 (Per-batch dispatch).
GDN-short is the exception. There we reach 2.783, behind the contest-winning Kachua kernel at 3.172 and the per-batch dispatch baseline at 3.167, and ahead of every other baseline. The results do not tell us why. Our pipeline always launches at least two kernels per call and pays a start cost per task, and our own micro-benchmarks put a kernel launch at roughly a microsecond; those fixed costs weigh most where the reference itself is fast, but we did not isolate them on this setting.
How we got here
The design came from a first-principles analysis checked against a literature scan and a set of micro-benchmarks, and then from a sequence of measured versions, each kept only if it was correct and faster on our development shapes. All figures in this section are our development measurements, taken with our own harness during the run.
- The starting analysis. Before writing any kernel, our research log sets out the chunk form above and, among other structural facts, these three: the state-independent work is parallel over chunks, the value columns of the state are independent chains given the prepared matrices, and the chain is serial over chunks. Its design idea was already the one we kept: a warp per slice of , held as tensor-core accumulators whose layout is the next product's operand layout. A literature scan, which we delegated to a sub-agent, read the contest kernels, FlashInfer's and FlashQLA's GDN kernels and FlashKDA. From it came the exact form of context parallelism, together with the suggestion to decide per sequence rather than per batch, so that one long sequence in a ragged batch is cut while the short ones are not; and FlashKDA's reason for 16-token chunks, that stays in range at a lower bound of only up to about 17 tokens.
- Micro-benchmarks set the rules. We measured the GPU itself while profiling our first fused kernel, before designing the split pipeline's loop. A global-memory load or
store that missed the L1 cache blocked its warp for roughly 100 to 250 ns, one 16 KB bulk copy took 415 ns while 64
separate 256-byte rows took 1,180 ns,
ldmatrixwas slow (29 ns), and a dependent chain of tensor-core instructions cost 13.8 ns per instruction. Hence the rules the code follows: no global-memory instruction on the chain, a few large contiguous copies, and operands pre-laid out so that plain shared-memory loads suffice. - A fused kernel was abandoned. Our first version did prepare and recurrence in one CTA per (sequence, head). It was correct but took 3.9 microseconds per 16-token chunk. Splitting into prepare and pass kernels brought the chunk cost to 1.45 microseconds, of which 0.58 went to 16 separate output-row stores; tiled stores, one per chunk, replaced them. A second fused design, tried later, with eight prepare warps handing chunks to eight recurrence warps through shared memory, reached 2.4 to 3 microseconds per chunk but was limited by the latency of the prepare stage and by one resident CTA per SM, and it was slower than the split design in every regime.
- Context parallelism and the planner came next and made the split design the whole submission; before that, GDN batches of more than 512 tokens still fell back to the starter's kernels. With them our development mean speedup was 2.49.
- Bank conflicts and a code-generation hazard. Loading and storing the state in its natural layout had 8-way
shared-memory bank conflicts; rotating which of four neighbouring tiles each lane touches brought them to 2-way. The
same version exposed a class of bug: a block executed only by lane 0 (issuing a copy), followed without a convergent
barrier by
mbarrierwaits or inline tensor-core instructions, can be duplicated per branch by the compiler, so that lanes 1 to 31 run the wait or the product without lane 0, which gives garbage or a deadlock. The earlier version had worked by luck of code generation. Every such block is now followed by__syncwarp()(development mean 2.55). Earlier, while building context parallelism, an intermittent race, in which an output tile was refilled before its previous store had finished, had been fixed with an extra barrier. - Residency and a calibrated planner. Capping the prepare kernel's registers so that three CTAs are resident per SM cut its time on our largest KDA development configuration from 573 to 488 microseconds. The planner gained its measured constants, the common-block-length search (coordinate descent alone got stuck when several long sequences had to be cut together) and the memory-traffic term, added after we found that cutting a single long KDA sequence over many heads made it slower (development mean 2.82).
- Fix-up, shared heads and an I/O warp. A second fix-up kernel, with two warps per slice, took the serial step
from 2.0 to 1.25 microseconds per block. The GDN shared head block cut the prepare kernel's traffic by 47% and gave 8
to 10% on our multi-thousand-token GDN batches (development mean 2.85). The dedicated I/O warp in the
NM = 1pass kernel took the chain from 0.84 to about 0.75 microseconds per chunk (development mean 2.91). The submitted version differs from that one only in comments. - What did not help. Splitting each state slice between two warps by key columns left the chain speed unchanged: our ablation put pure compute at about 0.60 of the 0.84 microseconds per chunk and the I/O and synchronisation primitives at about 0.24, so halving each warp's instruction count could not help. Removing all asynchronous copies from the chain changed a 2,048-token shape only from 117 to 102 microseconds, so the copies were not the bottleneck either. Software-pipelining the operand loads in source order changed nothing, and a shuffle-based triangular solve was 4% slower than reading from shared memory.
- Planner changes we did not adopt. Late in the run we found that the model mis-ranks the two pass-kernel variants
on single sequences of 4k to 8k tokens: it picks a plan about 9% slower than the best we measured, because the
NM = 1kernel has a cliff once its output-pass CTAs exceed the resident slots. It also under-predicts queueing on ragged GDN batches with many sequences. Refitting the constants was a wash. A list-scheduling simulation of the task table in place of the average-work bound, tested with the common-block search alone (without the coordinate descent), improved the weakest development shape by 20% but regressed others by up to 8%, a net gain of 0.7%; we left it out for lack of time to validate it.
Limitations
- GDN-short trails two baselines. On GDN-short we are below Kachua's contest kernel and the per-batch dispatch baseline, and we have not established why.
- The planner's model is known to be wrong in places. By our development measurements it picks a plan about 9% slower than the best measured on single sequences of 4k to 8k tokens, and it under-predicts queueing on ragged GDN batches with many sequences, where our weakest development shapes were. The fix we identified (simulated queueing, a prepare term and a load-dependent together) is not in the submission.
- The constants are tied to one GPU. The latency constants were measured on the development GPU, its SM count is hard-coded, and the extension is compiled for a single GPU architecture. On another GPU the kernels may not run, and the planner's choices would be uncalibrated.
- The chunk size is tied to the gate bound. The KDA Gram matrices use -scaled keys, which stay in range only because the safe gate bounds each log-decay below by over 16 tokens. A weaker bound or a longer chunk would overflow; the block-anchored alternative noted in the literature scan was not tried.
- Reduced-precision operands. Every operand of the chain, including the state's copy for each product and the transition maps , is fp16, which is accurate enough for the task's tolerance but has a narrower range than bf16. Our edge tests (extreme gates and betas, states scaled thirtyfold, repeated keys) passed, but the range is a property of the format, not something the code guards.
- Large-head KDA remains traffic-bound. The operand blocks are a round trip through global memory, which we estimated at 57% of the traffic on large-head KDA batches; closing that needs a fused design with a deeply pipelined prepare, and our fused attempts failed. The scratch cache can also hold up to 32 GiB of device memory across batch layouts.
- Correctness depends on discipline, not structure. The barrier rule after lane-0 blocks guards against a code-generation hazard that we found by testing; it is enforced by convention throughout the kernels, not by any check.
References
- Songlin Yang, Jan Kautz, Ali Hatamizadeh (2025). Gated Delta Networks: Improving Mamba2 with Delta Rule. ICLR.
- Kimi Team, Yu Zhang, Zongyu Lin et al. (2025). Kimi Linear: An Expressive, Efficient Attention Architecture.
- Songlin Yang, Bailin Wang, Yu Zhang et al. (2024). Parallelizing Linear Transformers with the Delta Rule over Sequence Length. NeurIPS.
- Zihao Ye, Lequn Chen, Ruihang Lai et al. (2025). FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving.