Repository navigation
CUDA: keep four BF16 weight loads in flight in mul_mat_vec_f - #508
Open
danielhanchen wants to merge 1 commit into
Open
danielhanchen wants to merge 1 commit into
danielhanchen wants to merge 1 commit into
Conversation
The BF16 GEMV loop issues one 4 byte load per thread per iteration. On a B200 it reaches 2.90 TB/s and the rate is flat across a 485x size range, which points at memory-level parallelism rather than bandwidth or occupancy. Strip-mine the loop four ways so four loads are outstanding. Each thread keeps the same column set and accumulates into sumf[j] in the same order, so the result is bit-identical. A 128 bit vector load would give each thread a contiguous 4-pair chunk instead, changing the column partition and the summation order, so it is not used. Qwen3.6-35B-A3B BF16 on one B200, batch-1 decode: 196.95/194.63 -> 209.64/209.81 tok/s (+7.1%). BF16 mul_mat_vec_f kernel time 407.98 -> 363.06 ms.
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. |
This was referenced Dec 6, 2026
This was referenced Dec 6, 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.
Summary
The unslothai/llama.cpp prebuilt is an aged upstream
b####tag plus the pins listed inscripts/unsloth/pr-set.json, merged in order. This pin is one commit on top of upstream b12966 (9a811bab3c4) and needs no other pin. Once upstream has an equivalent change, the pin is dropped.The problem
The BF16 branch of
mul_mat_vec_f(one-column BF16 x F32 products: BF16 GGUFs at decode, and the BF16 tensors that UD quants keep) issues one 4 byte weight load per thread per loop iteration. On a B200 this reaches about 2.9 TB/s and the rate stays flat across a 485x range of matrix sizes, which points at too few loads in flight rather than at bandwidth or occupancy.The fix
mmvf.cu, BF16 (non-HIP) branch: the column loop is strip-mined four ways, so each thread has four weight loads (and four gate loads when the GLU fusion is active) outstanding. A remainder loop handles the last columns.sumf[j]in the same order as before, so the result is bit-identical. (A 128 bit vector load would hand each thread a contiguous chunk instead, which changes the column partition and the summation order, so it is not used.)Evidence
mul_mat_vec_fkernel time 407.98 -> 363.06 mstest-backend-ops -b CUDA0, b12966 + this pinmmvf.cufor sm_75 / 80 / 89 / 100 / 120llama_pinset.py sim, private copy, b13023, 12-06): master pr-set + open candidates #485-#503 (without #495) + #505 + #508-#513 + #516 at their current heads, 74 pinsmerge_checksclean;pin_contract: all pins intact once #491 is listed at its current heade6e34ffd3c2(the copy listed it at131d93897cd, whose comment-trimmed line arrives through #505 / #512, a listing artifact). CUDAmmvq.cu/mmvf.cu/mmid-gemm.cu/fusion.cucompile on the merged tree (sm_75 + sm_100a)Not proven
mul_mat_vec_fis reached, so there this pin only covers the cases CUDA: BF16 x F32 one-column mul_mat for sm_100 #503 declines. Its speedup is still to be measured with CUDA: BF16 x F32 one-column mul_mat for sm_100 #503 present on both sides (GGML_CUDA_DISABLE_MMV_BF16_F32=0/1).test-backend-opsreaches the new four-way loop through the long-K BF16MUL_MATcases (K=10240 / 2560). TheMUL_MAT_FUSIONcases use K=256 and only reach the remainder loop, so the gate loads are covered only by the greedy md5 runs.