Skip to content

CUDA: gated_delta_net - share per-token k/q via shared memory for long prefills#54

Draft
roberteg16 wants to merge 1 commit into
gfx11from
rogarcia.gdn-shared-kq
Draft

CUDA: gated_delta_net - share per-token k/q via shared memory for long prefills#54
roberteg16 wants to merge 1 commit into
gfx11from
rogarcia.gdn-shared-kq

Conversation

@roberteg16

Copy link
Copy Markdown

Summary

The serial GATED_DELTA_NET kernel reloaded the per-token k/q from global memory once per warp, even though k/q are identical for every state column in a block. This stages them in shared memory once per token (a single block-wide load) when the kernel is memory-bound.

  • Gated at n_tokens >= 1536 (measured crossover on gfx1151, d=128). Short sequences stay latency-bound and are hidden by inter-warp overlap, which the extra __syncthreads would break, so they keep the direct global load.
  • Long sequences also stop degrading super-linearly (the direct-load path is ~2.7x per 2x tokens at large T; the shared-staged path is ~2.0x).

Measured (gfx1151, d=128, 32 heads, test-backend-ops perf, median of 3)

tokens direct load shared k/q speedup
<= 1024 (path off) (path off) 1.00x
1536 7495 us 7157 us 1.05x
2048 11272 us 9405 us 1.20x
4096 30183 us 18828 us 1.60x

Test plan

  • test-backend-ops -o GATED_DELTA_NET — 36/36 pass (CPU reference parity; scalar + KDA + K>1 + decode paths).
  • CI on gfx11.

RDNA3.5-only optimisation. The serial GATED_DELTA_NET kernel reloaded the
per-token k/q from global once per warp, even though k/q are identical for
every state column in a block. On RDNA3.5 (gfx115x) stage them in shared
once per token (one block-wide load) for long, memory-bound sequences.

Gated at compile time (#ifdef RDNA3_5) and at runtime
(GGML_CUDA_CC_IS_RDNA3_5(cc) && n_tokens >= 1536) so no other arch pays the
extra LDS or the barrier. Short sequences stay latency-bound (hidden by
inter-warp overlap) and use the direct global load.

Measured on gfx1151 (d=128, 32 heads, median of 3): ~1.05x at 1536, ~1.20x
at 2048, ~1.60x at 4096; neutral below the threshold. Also removes the
super-linear slowdown of the serial scan at long sequences.
@roberteg16
roberteg16 force-pushed the rogarcia.gdn-shared-kq branch from e332179 to 5bb1972 Compare July 16, 2026 13:51
@roberteg16

Copy link
Copy Markdown
Author

This seems to be a wash. I'll keep it open until it is 100% clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant