Skip to content

vulkan: chunked GATED_DELTA_NET implementation - #30207

Merged
ggerganov merged 22 commits into
masterfrom
0cc4m/vulkan-gdn-cm2
Nov 20, 2026
Merged

ggerganov merged 22 commits into
masterfrom
0cc4m/vulkan-gdn-cm2

Conversation

@0cc4m

@0cc4m 0cc4m commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Overview

This is a Vulkan port of the CUDA chunked kernel in #29353 to NV_coopmat2 and KHR_coopmat_maintenance1. The perf delta is much smaller than on CUDA, because I am missing some tuning options that CUDA has and because the Vulkan scan kernel is significantly better than CUDA's. This may not be worth the complexity, but I want to open it as draft to get some feedback from @jeffbolznv. It is a significant op-level speedup, but not on the model-level yet.

On the AMD side it requires radv built from upstream for maintenance1 support, since no released version supports it yet.

gdn_epyc_rtx3090 gdn_nv-spark_gb10 gdn_amd-arch_r9700 gdn_amd-395_8060s

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, ported and tuned by AI, validated and reviewed by me.

@github-actions github-actions Bot added testing Everything test related Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Oct 9, 2026
@jeffbolznv

Copy link
Copy Markdown
Contributor

I didn't have time to dig into the code today. I ran test-backend-ops and the perf is improved. codex suggested using V=32, and I get another almost 2x speedup from that.

@jeffbolznv

Copy link
Copy Markdown
Contributor

@0cc4m are you still pursuing this? If not, I'd be willing to take it over, I'd like to get it done one way or another.

@0cc4m
0cc4m force-pushed the 0cc4m/vulkan-gdn-cm2 branch from bfc0405 to 254ea47 Compare November 9, 2026 07:07
@0cc4m

0cc4m commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

We can finish this PR, sure. I'll look into your V=32 suggestion.

@0cc4m
0cc4m marked this pull request as ready for review November 10, 2026 13:32
@0cc4m
0cc4m requested review from a team and ggerganov as code owners November 10, 2026 13:32
@0cc4m

0cc4m commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

I saw a performance improvement from V=32 when larger sizes wouldn't fill the GPU, added that in a way similar to split-k with a decision based on core count. I also generalized the CMM1 shader further to theoretically allow other GPUs, please check.

@jeffbolznv

Copy link
Copy Markdown
Contributor

I ran into a couple issues. There are failures in the unit tests in the CM2 path. It's fixed by this change:

diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
index a6b3d73d4..7ae0d7f80 100644
--- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp
+++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
@@ -3781,13 +3781,13 @@ void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
         if (gdn_chunked && device->coopmat2 && device->coopmat2_bf16_support) {
             ggml_vk_create_pipeline(device, device->pipeline_gated_delta_net_cm,
                 "gated_delta_net_f32_cm2", gated_delta_net_f32_cm2_len, gated_delta_net_f32_cm2_data,
-                "main", 7, sizeof(vk_op_gated_delta_net_push_constants), {1, 1, 1}, {}, 1, true, true, 32);
+                "main", 7, sizeof(vk_op_gated_delta_net_push_constants), {1, 1, 1}, {16u * 32u}, 1, true, true, 32);
             ggml_vk_create_pipeline(device, device->pipeline_gated_delta_net_cm_v32,
                 "gated_delta_net_f32_cm2_v32", gated_delta_net_f32_cm2_v32_len, gated_delta_net_f32_cm2_v32_data,
-                "main", 7, sizeof(vk_op_gated_delta_net_push_constants), {1, 1, 1}, {}, 1, true, true, 32);
+                "main", 7, sizeof(vk_op_gated_delta_net_push_constants), {1, 1, 1}, {16u * 32u}, 1, true, true, 32);
             ggml_vk_create_pipeline(device, device->pipeline_gated_delta_net_cm_v128,
                 "gated_delta_net_f32_cm2_v128", gated_delta_net_f32_cm2_v128_len, gated_delta_net_f32_cm2_v128_data,
-                "main", 7, sizeof(vk_op_gated_delta_net_push_constants), {1, 1, 1}, {}, 1, true, true, 32);
+                "main", 7, sizeof(vk_op_gated_delta_net_push_constants), {1, 1, 1}, {16u * 32u}, 1, true, true, 32);
         }
 #endif
 #if defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) && defined(GGML_VULKAN_COOPMAT_MAINTENANCE1_GLSLC_SUPPORT) && defined(GGML_VULKAN_BFLOAT16_GLSLC_SUPPORT)

It also looks like some cases will use more than 48KB of shared memory, which is unsupported.

@0cc4m
0cc4m force-pushed the 0cc4m/vulkan-gdn-cm2 branch from 969cc73 to 2d06dd9 Compare November 18, 2026 09:23
@0cc4m

0cc4m commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

New benchmark data. Note Strix Halo 8060S scan kernel data is lower because I found that it is very latency-sensitive and the VRAM carveout performs significantly better here. Now data is run without the carveout to exclude this effect (which is also the configuration I use). Nvidia performance is increased from @jeffbolznv's kernel. I think the branch should be ready.

gdn_3090 gdn_gb10 gdn_r9700 gdn_8060s

@0cc4m 0cc4m added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 19, 2026
@ggerganov
ggerganov merged commit 16f80bd into master Nov 20, 2026
39 of 46 checks passed
@ggerganov

Copy link
Copy Markdown
Member

@0cc4m
0cc4m deleted the 0cc4m/vulkan-gdn-cm2 branch November 20, 2026 08:22
@am17an

am17an commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

The test-backend-ops changes look not required and actually quite hard to understand. I would suggest reverting them. The CUDA backend already has the chunked GDN kernel which already had coverage.

@0cc4m

0cc4m commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Maybe some of it isn't needed, but you should probably still fix supports_op to refuse cases which assert in your implementation.

@JohannesGaessler

Copy link
Copy Markdown
Contributor

Maybe some of it isn't needed, but you should probably still fix supports_op to refuse cases which assert in your implementation.

Yes, I don't know whether we formalized this somewhere but my opinion is that it is the responsibility of a backend to either return false for supports_op or to provide correct results.

@am17an

am17an commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Yes, but we shouldn't add tests which are not required. The rollback in the chunked kernel is not required, I guess the test cases are for those. It just adds extra CI time for which there is no actual use-case.

@JohannesGaessler

Copy link
Copy Markdown
Contributor

I'm completely fine with removing tests again, I am just of the opinion that from a ggml (rather than llama.cpp perspective) we should always make sure that supports_op exactly matches the corresponding backend.

@0cc4m

0cc4m commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@jeffbolznv built the tests, I'd wait for his opinion.

@ggerganov

Copy link
Copy Markdown
Member

I opened #32660 to heal the CI in the short term.

@jeffbolznv

Copy link
Copy Markdown
Contributor

Thanks for fixing. IMO if ggml.c allows something, it's fair game to have backend tests. Agents want to fill the test gaps they see, I think this is a good thing.

The kind of annoying thing is that test-backend-ops changes no longer trigger all builds in CI. It's a tradeoff, catching these things after submission is not perfect but seems to be working OK so far.

Kidplayer666 pushed a commit to Kidplayer666/llama.cpp that referenced this pull request Nov 20, 2026
* vulkan: add cm2 chunked GATED_DELTA_NET shader

* fix shmem bank conflict bottleneck

* optimize further

* add coopmat maintenance1 variant

* optimize for RDNA4

* add gmem version RDNA4

* optimize for Ampere

* fix nvidia shmem overuse

* fix cm2 validation errors

* improve cm2 perf

* improve cm1 perf

* clean up

* enable by default

* show cm maintenance1 marker in device info

* properly check for cm_m1 features

* add tests

* add v32 mode, improve chunked condition

* allow other subgroup sizes

* vulkan: specialize the GDN CM2 workgroup size

Assisted-by: Codex

* vulkan: coopmat2 GDN implementation

* work around Nvidia shader compiler crash

* remove shared shader cm2 code

---------

Co-authored-by: Jeff Bolz <[email protected]>
@jeffbolznv jeffbolznv mentioned this pull request Nov 21, 2026
6 of 8 tasks
x1250 added a commit to x1250/llama.cpp that referenced this pull request Nov 21, 2026
…d delta net prefill

Brings upstream's Inkling 2 Mini support (inkling2 and inkling2_loop, ggml-org#32694, ggml-org#32429,
and the inkling2v projector) and 70 other commits. One conflict: upstream's Vulkan
gated delta net gained a chunked coopmat prefill (ggml-org#30207) and packed state rows, and
the push constants gained s_off. The resolution keeps the fork's snapshot fusion on the
scan: one push-constant struct, upstream's fields first and the snapshot destination
after them, so the coopmat shaders read a prefix; the scan keeps its snapshot buffer
binding and takes upstream's row_index. The coopmat choice moves to
ggml_vk_gdn_use_cm, which the dispatch and the fusion share: the coopmat prefill
writes the state into its own output, so the fusion declines when it runs the op
(single state, ubatches of 4096 tokens or more on RDNA3).
Annieren pushed a commit to Annieren/llama.cpp-upstream that referenced this pull request Nov 23, 2026
* vulkan: add cm2 chunked GATED_DELTA_NET shader

* fix shmem bank conflict bottleneck

* optimize further

* add coopmat maintenance1 variant

* optimize for RDNA4

* add gmem version RDNA4

* optimize for Ampere

* fix nvidia shmem overuse

* fix cm2 validation errors

* improve cm2 perf

* improve cm1 perf

* clean up

* enable by default

* show cm maintenance1 marker in device info

* properly check for cm_m1 features

* add tests

* add v32 mode, improve chunked condition

* allow other subgroup sizes

* vulkan: specialize the GDN CM2 workgroup size

Assisted-by: Codex

* vulkan: coopmat2 GDN implementation

* work around Nvidia shader compiler crash

* remove shared shader cm2 code

---------

Co-authored-by: Jeff Bolz <[email protected]>
Nindaleth pushed a commit to Nindaleth/llama.cpp that referenced this pull request Nov 26, 2026
* vulkan: add cm2 chunked GATED_DELTA_NET shader

* fix shmem bank conflict bottleneck

* optimize further

* add coopmat maintenance1 variant

* optimize for RDNA4

* add gmem version RDNA4

* optimize for Ampere

* fix nvidia shmem overuse

* fix cm2 validation errors

* improve cm2 perf

* improve cm1 perf

* clean up

* enable by default

* show cm maintenance1 marker in device info

* properly check for cm_m1 features

* add tests

* add v32 mode, improve chunked condition

* allow other subgroup sizes

* vulkan: specialize the GDN CM2 workgroup size

Assisted-by: Codex

* vulkan: coopmat2 GDN implementation

* work around Nvidia shader compiler crash

* remove shared shader cm2 code

---------

Co-authored-by: Jeff Bolz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants