Skip to content

ggml-cuda: Allow transpose-free gemmv computation - #26171

Merged
am17an merged 1 commit into
ggml-org:masterfrom
AMD-Ecosystem:rogarcia.cuda-mmvf-single-col-swap-pr
Jul 30, 2026
Merged

am17an merged 1 commit into
ggml-org:masterfrom
AMD-Ecosystem:rogarcia.cuda-mmvf-single-col-swap-pr

Conversation

@roberteg16

Copy link
Copy Markdown
Contributor

Overview

A mul_mat of a single-column f32 weight (ne01 == 1) against a wide activation (ne11 > MMVF_MAX_BATCH_SIZE) currently misses the in-house mmvf vector kernel and falls back to an f32 cuBLAS/rocBLAS GEMM.

This opportunity was found in model Qwen3.6-35B-A3B (also applicable to Qwen3.5, since they share same arch) with quantization scheme Q4_K_M. It can be found in the shared-expert gate of the model.

Measured improvement on GFX1151 (Qwen3.6-35B-A3B, prefill pp128)

shared-expert gate (weight f32[2048,1], ×40 layers) before after
kernel rocBLAS Cijk_…MT32x32x8 Sgemm mul_mat_vec_f (mmvf)
per instance ~78.4 µs ~3.8 µs
total (40 instances) ~3135 µs ~156 µs

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, location of opportunity in code, understanding and iteration on final code.

@roberteg16
roberteg16 requested review from a team and ggerganov as code owners July 27, 2026 11:06
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Jul 27, 2026
@am17an

am17an commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Plus post end to end results for a particular model using llama-bench

@roberteg16

roberteg16 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Plus post end to end results for a particular model using llama-bench

This is a fairly small optimization. Qwen3.6-35B-A3B contains blk.N.ffn_gate_inp_shexp.weight which is a 1D weight of 2048xf32. The good side is that this PR opens to the highly optimized mmvf path for the future. These are the results for Qwen3.6-35B-A3B:Q4_K_M:

test Commit OFF (t/s) Commit ON (t/s) Δ abs (t/s) Δ rel (%)
pp16 321.96 ± 11.76 346.52 ± 8.58 +24.56 +7.6%
pp32 460.75 ± 7.18 475.60 ± 49.71 +14.85 +3.2%
pp64 575.57 ± 15.80 597.08 ± 14.63 +21.51 +3.7%
pp128 567.05 ± 12.75 577.95 ± 13.43 +10.90 +1.9%
pp512 1095.11 ± 41.76 1108.06 ± 25.40 +12.95 +1.2%

Run command:
llama-bench -hf unsloth/Qwen3.5-35B-A3B-GGUF:Q4_K_M -ngl 999 -d 0 -n 0 -p 16,32,64,128,512 -n 0 -r 50

Comment thread tests/test-backend-ops.cpp Resolved
@roberteg16
roberteg16 force-pushed the rogarcia.cuda-mmvf-single-col-swap-pr branch from bf7b90e to 3a14277 Compare July 30, 2026 12:44
@roberteg16
roberteg16 requested review from IMbackK and am17an July 30, 2026 12:45
@roberteg16

Copy link
Copy Markdown
Contributor Author

Sorry for reasking for review, I added a commit updating a comment @IMbackK @am17an

Comment thread ggml/src/ggml-cuda/ggml-cuda.cu Resolved
Comment thread ggml/src/ggml-cuda/ggml-cuda.cu Resolved
Comment thread ggml/src/ggml-cuda/ggml-cuda.cu Resolved
@roberteg16
roberteg16 force-pushed the rogarcia.cuda-mmvf-single-col-swap-pr branch from 3a14277 to a3dbdde Compare July 30, 2026 13:13
@roberteg16
roberteg16 requested a review from am17an July 30, 2026 13:14
Comment thread ggml/src/ggml-cuda/ggml-cuda.cu Resolved
When matrix's weights are shaped 1xK is leverage a transpose-free
computation to use mat_mul_vec_f.
@roberteg16
roberteg16 force-pushed the rogarcia.cuda-mmvf-single-col-swap-pr branch from a3dbdde to dcc71fd Compare July 30, 2026 13:25
@roberteg16
roberteg16 requested a review from am17an July 30, 2026 13:39
@am17an
am17an merged commit e1a1abb into ggml-org:master Jul 30, 2026
1 check passed
huaxel pushed a commit to huaxel/strix-llama.cpp that referenced this pull request Aug 2, 2026
When matrix's weights are shaped 1xK is leverage a transpose-free
computation to use mat_mul_vec_f.
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
When matrix's weights are shaped 1xK is leverage a transpose-free
computation to use mat_mul_vec_f.
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
When matrix's weights are shaped 1xK is leverage a transpose-free
computation to use mat_mul_vec_f.
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
When matrix's weights are shaped 1xK is leverage a transpose-free
computation to use mat_mul_vec_f.
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 testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants