Skip to content

CUDA: add GGML_OP_LIGHTNING_INDEXER kernel (F16/F32 K)#25632

Closed
Dorijan10 wants to merge 1 commit into
ggml-org:masterfrom
Dorijan10:lightning-indexer-cuda
Closed

CUDA: add GGML_OP_LIGHTNING_INDEXER kernel (F16/F32 K)#25632
Dorijan10 wants to merge 1 commit into
ggml-org:masterfrom
Dorijan10:lightning-indexer-cuda

Conversation

@Dorijan10

Copy link
Copy Markdown

What

Adds the CUDA backend for GGML_OP_LIGHTNING_INDEXER, introduced in #24231
with a CPU implementation only. On GPU-resident DeepSeek-V3.2 / GLM-5.2 models
the fused lightning-indexer path currently has no CUDA kernel.

Implementation

Naive one-thread-per-KV-position kernel: each thread computes
sum_h relu(dot(q_h, k)) * w_h + mask over the indexer heads, matching the
CPU reference in ggml_compute_forward_lightning_indexer. Supports F16 and
F32 K; quantized K (Q8_0 etc.) to follow in a subsequent change.

Validation

Passes the existing test-backend-ops LIGHTNING_INDEXER case at the test's
1e-6 NMSE tolerance across all tested shapes (varying heads, KV, batch,
streams, mask broadcast), on an RTX 5090 (sm_120):

test-backend-ops test -o LIGHTNING_INDEXER -b CUDA0
... all f16/f32 cases: OK

Quantized K types report not supported via supports_op and are skipped.

Notes

This is a correctness-first implementation; optimization (shared-memory
q/w staging, coalesced K reads) can follow. Happy to iterate.

Implements the CUDA backend for the lightning indexer op (added in ggml-org#24231,
CPU-only). Naive one-thread-per-KV kernel; validated against the CPU
reference via test-backend-ops at all tested shapes on sm_120 (RTX 5090).
Supports F16/F32 K; quantized K to follow.
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Jul 13, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Hi @Dorijan10, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@abc-nix

abc-nix commented Jul 13, 2026

Copy link
Copy Markdown

You know that #25545 exists, right?

@Dorijan10

Copy link
Copy Markdown
Author

@abc-nix

Thanks I noticed it now, I knew about #25407 and #24231 (hence I got the idea from), but not this one.

I see it is more thorough. I have 8 RTX 5090 (sm_120), let me know if you guys want me to do any validation on these as well.

@am17an am17an closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants