cuda: align snake fusion matcher with the other backends#25460
Merged
ggerganov merged 2 commits intoJul 9, 2026
Conversation
The matcher required a->type == x->type while launch_snake reads both as const float *, matching the CPU and Metal contract where a and inv_b stay F32. F16/BF16 chains never fused and fell back to the naive path, and a hypothetical all F16 chain would have read F16 bits as float. Aligns the predicate and the comment with ggml-cpu.c
The kernel reads x[idx] and a[c] / inv_b[c] linearly, so a non-contiguous view passing the matcher would silently read wrong data. Mirror the contiguity guard already present in the CPU, Vulkan and Metal matchers.
am17an
approved these changes
Jul 9, 2026
Member
|
Merging per the "merge ready" label. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
The CUDA snake matcher was the first one written and missed the review experience accumulated on the later backends: the Vulkan reviews raised the F32 contract on a / inv_b and the stride checks, and CPU and Metal were written with both baked in. This PR brings CUDA back in line.
Two fixes:
The matcher required a->type == x->type while launch_snake reads a and inv_b as const float *. F16/BF16 chains never fused and silently fell back to the naive path, and a hypothetical all F16 chain would have read F16 bits as float. The predicate now requires F32, matching the kernel and the other three backends.
The kernel reads x[idx] and a[c] / inv_b[c] linearly, but nothing rejected non-contiguous operands. Added the same contiguity guard as CPU, Vulkan and Metal.
Additional information
Validation:
SNAKE_FUSE 16/16 on RTX PRO 6000 Blackwell. The F16 cases now actually exercise the fused kernel: the test builds a / inv_b in F32, so under the old predicate they always fell back to the naive chain and passed without covering the fused path.
Requirements