Skip to content

cuda: align snake fusion matcher with the other backends#25460

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
ServeurpersoCom:ggml/cuda-snake-fusion-parity
Jul 9, 2026
Merged

cuda: align snake fusion matcher with the other backends#25460
ggerganov merged 2 commits into
ggml-org:masterfrom
ServeurpersoCom:ggml/cuda-snake-fusion-parity

Conversation

@ServeurpersoCom

Copy link
Copy Markdown
Contributor

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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES Fable 5 / Rootless dev container with GPU

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.
@ServeurpersoCom ServeurpersoCom requested a review from a team as a code owner July 8, 2026 18:23
@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 8, 2026
@am17an am17an added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 9, 2026
@ggerganov ggerganov merged commit 2021515 into ggml-org:master Jul 9, 2026
21 of 22 checks passed
@ggerganov

Copy link
Copy Markdown
Member

Merging per the "merge ready" label.

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 merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants