Repository navigation
ggml-cuda : convert contiguous tensors four elements at a time - #29155
Merged
Merged
Conversation
convert_unary handles the contiguous case through the general strided kernel,
one element per thread: each lane reads 4 bytes and writes 2. Converting the
activations for a bf16 matrix multiplication that way moves 126 MB in 1021 us
on gfx1151, about 65% of what the memory system can do.
Give the contiguous path its own kernel that takes four elements per thread
through a vector type, so a warp loads 512 bytes at a time instead of 128. It
is used only when the element count is a multiple of four and both pointers
carry the alignment the vector type needs, and falls back to the strided
kernel otherwise.
Model level, Qwen3.8-Next-Flash IQ3_XXS on gfx1151, llama-bench -ub 2048 -r 6,
mean of the last 3 reps, ABBA counterbalanced:
pp2048 688.0 680.0 -> 694.3 691.1 +1.26%
tg128 24.8 24.8 -> 24.8 24.8 +0.14%
Every conversion in a prefill takes the new kernel (kernel trace: 1146
convert_unary_cont_vec4, no convert_unary). Output is bit identical; MUL_MAT,
MUL_MAT_ID, CPY, CONT, GET_ROWS and SET_ROWS pass.
Assisted-by: Claude Opus 5
JohannesGaessler
approved these changes
Sep 19, 2026
IMbackK
approved these changes
Sep 20, 2026
IMbackK
left a comment
Contributor
There was a problem hiding this comment.
this complies down to global_load_dwordx4 on hip so nice.
tiny nit: the comment is wrong on cdna where we load 1K per warp.
Clarified comment on memory transfer size for different architectures.
Member
Author
|
Aight, corrected the comment, can I get a reapproval please? |
IMbackK
approved these changes
Sep 21, 2026
1 task done
iki007
added a commit
to iki007/llama.cpp
that referenced
this pull request
Sep 27, 2026
Port of CUDA ggml-org#29155: aligned contiguous conversions with a multiple of four elements take a kernel that moves four elements per work-item; the rest keep the strided kernel. Arc Pro B70 pp2048: Qwen3.8-27B UD-Q4_K_M +1.75%, Qwen3.6-35B-A3B Q4_K_M +0.69%. Assisted-by: Claude Opus 5.5
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 2, 2026
…org#29155) convert_unary handles the contiguous case through the general strided kernel, one element per thread: each lane reads 4 bytes and writes 2. Converting the activations for a bf16 matrix multiplication that way moves 126 MB in 1021 us on gfx1151, about 65% of what the memory system can do. Give the contiguous path its own kernel that takes four elements per thread through a vector type, so a warp loads 512 bytes at a time instead of 128. It is used only when the element count is a multiple of four and both pointers carry the alignment the vector type needs, and falls back to the strided kernel otherwise. Model level, Qwen3.8-Next-Flash IQ3_XXS on gfx1151, llama-bench -ub 2048 -r 6, mean of the last 3 reps, ABBA counterbalanced: pp2048 688.0 680.0 -> 694.3 691.1 +1.26% tg128 24.8 24.8 -> 24.8 24.8 +0.14% Every conversion in a prefill takes the new kernel (kernel trace: 1146 convert_unary_cont_vec4, no convert_unary). Output is bit identical; MUL_MAT, MUL_MAT_ID, CPY, CONT, GET_ROWS and SET_ROWS pass. Assisted-by: Claude Opus 5
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 4, 2026
…org#29155) convert_unary handles the contiguous case through the general strided kernel, one element per thread: each lane reads 4 bytes and writes 2. Converting the activations for a bf16 matrix multiplication that way moves 126 MB in 1021 us on gfx1151, about 65% of what the memory system can do. Give the contiguous path its own kernel that takes four elements per thread through a vector type, so a warp loads 512 bytes at a time instead of 128. It is used only when the element count is a multiple of four and both pointers carry the alignment the vector type needs, and falls back to the strided kernel otherwise. Model level, Qwen3.8-Next-Flash IQ3_XXS on gfx1151, llama-bench -ub 2048 -r 6, mean of the last 3 reps, ABBA counterbalanced: pp2048 688.0 680.0 -> 694.3 691.1 +1.26% tg128 24.8 24.8 -> 24.8 24.8 +0.14% Every conversion in a prefill takes the new kernel (kernel trace: 1146 convert_unary_cont_vec4, no convert_unary). Output is bit identical; MUL_MAT, MUL_MAT_ID, CPY, CONT, GET_ROWS and SET_ROWS pass. Assisted-by: Claude Opus 5 (cherry picked from commit f4e276a)
LadislavSopko
pushed a commit
to 0ics-srls/llama.cpp
that referenced
this pull request
Oct 5, 2026
…org#29155) convert_unary handles the contiguous case through the general strided kernel, one element per thread: each lane reads 4 bytes and writes 2. Converting the activations for a bf16 matrix multiplication that way moves 126 MB in 1021 us on gfx1151, about 65% of what the memory system can do. Give the contiguous path its own kernel that takes four elements per thread through a vector type, so a warp loads 512 bytes at a time instead of 128. It is used only when the element count is a multiple of four and both pointers carry the alignment the vector type needs, and falls back to the strided kernel otherwise. Model level, Qwen3.8-Next-Flash IQ3_XXS on gfx1151, llama-bench -ub 2048 -r 6, mean of the last 3 reps, ABBA counterbalanced: pp2048 688.0 680.0 -> 694.3 691.1 +1.26% tg128 24.8 24.8 -> 24.8 24.8 +0.14% Every conversion in a prefill takes the new kernel (kernel trace: 1146 convert_unary_cont_vec4, no convert_unary). Output is bit identical; MUL_MAT, MUL_MAT_ID, CPY, CONT, GET_ROWS and SET_ROWS pass. Assisted-by: Claude Opus 5
iki007
added a commit
to iki007/llama.cpp
that referenced
this pull request
Oct 21, 2026
Port of CUDA ggml-org#29155: aligned contiguous conversions with a multiple of four elements take a kernel that moves four elements per work-item; the rest keep the strided kernel. Arc Pro B70 pp2048: Qwen3.8-27B UD-Q4_K_M +1.75%, Qwen3.6-35B-A3B Q4_K_M +0.69%. Assisted-by: Claude Opus 5.5
iki007
added a commit
to iki007/llama.cpp
that referenced
this pull request
Oct 22, 2026
Port of CUDA ggml-org#29155: aligned contiguous conversions with a multiple of four elements take a kernel that moves four elements per work-item; the rest keep the strided kernel. Arc Pro B70 pp2048: Qwen3.8-27B UD-Q4_K_M +1.75%, Qwen3.6-35B-A3B Q4_K_M +0.69%. Assisted-by: Claude Opus 5.5
nicheng251
added a commit
to nicheng251/bonsai-turboquant-llama.cpp
that referenced
this pull request
Oct 23, 2026
Port five small upstream fixes that apply to code this fork ships: - fattn-vec: sync the warp at the end of the VKQ loop (ggml-org#30573). The next iteration's KQ write reused the shared buffer while other lanes were still reading it. - cpy: the transposed fast path requires a contiguous destination (ggml-org#27663). It wrote to a non-contiguous dst as if it were dense. - llama-kv-cache: only upload k_rot when the tensor has a buffer (ggml-org#27967). An unquantized K cache has no k_rot buffer and context shift crashed. - ggml_permute: keep dims and strides 64-bit (ggml-org#29227). The int temporaries truncated large tensors. - convert: run contiguous conversions four elements per thread (ggml-org#29155). Verified: FLASH_ATTN_EXT turbo 25/25, 27B Bonsai PTQ1_0 model smoke with q8_0 K + turbo3 V (prefill 547 tok/s, decode 31.2 tok/s at 2K; 30.0 at 17.4K). The stock q8_0/q8_0 long-sweep crash is not caused by the WAR hazard: it still aborts after 361 cases with this fix.
iki007
added a commit
to iki007/llama.cpp
that referenced
this pull request
Oct 29, 2026
Port of CUDA ggml-org#29155: aligned contiguous conversions with a multiple of four elements take a kernel that moves four elements per work-item; the rest keep the strided kernel. Arc Pro B70 pp2048: Qwen3.8-27B UD-Q4_K_M +1.75%, Qwen3.6-35B-A3B Q4_K_M +0.69%. Assisted-by: Claude Opus 5.5
iki007
added a commit
to iki007/llama.cpp
that referenced
this pull request
Nov 4, 2026
Port of CUDA ggml-org#29155: aligned contiguous conversions with a multiple of four elements take a kernel that moves four elements per work-item; the rest keep the strided kernel. Arc Pro B70 pp2048: Qwen3.8-27B UD-Q4_K_M +1.75%, Qwen3.6-35B-A3B Q4_K_M +0.69%. Assisted-by: Claude Opus 5.5
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.
As in topic. Helps BF16 prefill quite a bit.
Additional information
Columns are grouped by GPU:
Requirements