Repository navigation
CUDA: 4 rows per block for the MoE vector kernel on NVIDIA Turing to Ada and datacenter Blackwell - #417
Open
danielhanchen wants to merge 2 commits into
Open
CUDA: 4 rows per block for the MoE vector kernel on NVIDIA Turing to Ada and datacenter Blackwell#417danielhanchen wants to merge 2 commits into
danielhanchen wants to merge 2 commits into
Conversation
mul_mat_vec_q_moe (MUL_MAT_ID at 2-8 tokens) takes 4 rows per block on cc 10.x when the row count is a multiple of 4 (2 elsewhere, as before). That gives each warp more independent loads: -8% kernel time for NVFP4 experts at 4 and 8 tokens on B200 (37.6 -> 34.7 us, 71.7 -> 66.9 us). Each warp reduces each row in the same order, so the results are bit-identical. test-backend-ops: NVFP4 MUL_MAT_ID with 16 experts, 8 used, at 2/4/8 tokens, row counts divisible by 4 and not. Kill switch: GGML_CUDA_DISABLE_MOE_VEC_ROWS4=1.
Each row is still reduced exactly as with 2 rows per block, so the results are bit-identical. 4-sequence decode with 4 rows vs 2 (Inkling-2-Mini): T4 +7.4% (UD-IQ1_S), A100 +2.0 / +0.7 / +0.4% and L4 +1.8 / +0.8% (UD-IQ1_S / UD-Q4_K_XL / UD-Q8_K_XL). Batch-1 decode and prefill unchanged. Hopper (cc 9.x) is not measured and keeps 2 rows. Consumer Blackwell (cc 12.x, RTX PRO 6000) measured 0.2-0.5% slower at 4 sequences and keeps 2 rows. GGML_CUDA_DISABLE_MOE_VEC_ROWS4=1 keeps 2 rows per block everywhere.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
erokhins
pushed a commit
to JetBrains-Hardware/llama.cpp
that referenced
this pull request
Nov 24, 2026
This branch has not been deployed
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.
Pin for the prebuilt: upstream b12602 (418fe97) plus these two commits. Base branch base/upstream-418fe97b5.
What it changes
mul_mat_vec_q_moe (MUL_MAT_ID at 2-8 tokens: batched decode, speculative verify) takes 4 rows per block instead of 2 when the row count is a multiple of 4. That gives each warp more independent loads. Each warp still reduces each row in the same order, so the results are bit-identical.
GGML_CUDA_DISABLE_MOE_VEC_ROWS4=1 keeps 2 rows per block everywhere. test-backend-ops: NVFP4 MUL_MAT_ID with 16 experts, 8 used, at 2/4/8 tokens, row counts divisible by 4 and not.
Evidence
B200, one exclusive card, load-gated runs, with the other decode pins: 8-sequence decode UD-Q8_K_XL 357.9 -> 379.7 tok/s (+6%); 4 sequences and UD-Q4_K_XL tie; batch 1 unchanged.
Other NVIDIA GPUs (Colab, one card each, built from b12628 plus #399 plus the decode pins).
llama-batched-bench -c 4096 -npp 128 -ntg 64 -kvu, aggregate decode tok/s at 4 sequences, 3 rounds ABBA, median, 4 rows against 2 rows (the kill switch) in the same build; #399's spread over its 3 runs in brackets: