Commit 765002119 for llama.cpp
commit 76500211950d5337bc5750df4dd98e8584ed1384
Author: FlagZhao <FlagZhao@users.noreply.github.com>
Date: Wed Dec 2 02:05:59 2026 -0500
CUDA: fix grid-stride loop step in k_get_rows (#33140)
Each thread in k_get_rows processes 2 elements per iteration (i00 starts at 2*(blockIdx.y*blockDim.x + threadIdx.x)), so the loop stride must be 2*gridDim.y*blockDim.x instead of gridDim.y*blockDim.x to avoid redundant iterations and overlapping writes when ne00 > 256.
diff --git a/ggml/src/ggml-cuda/getrows.cu b/ggml/src/ggml-cuda/getrows.cu
index 09b7f02b8..fd6adacbe 100644
--- a/ggml/src/ggml-cuda/getrows.cu
+++ b/ggml/src/ggml-cuda/getrows.cu
@@ -13,7 +13,7 @@ static __global__ void k_get_rows(
ggml_cuda_pdl_sync();
for (int64_t z = blockIdx.z; z < ne11*(int64_t)ne12_fdv.z; z += gridDim.z) {
- for (int64_t i00 = 2*(blockIdx.y*blockDim.x + threadIdx.x); i00 < ne00; i00 += gridDim.y*blockDim.x) {
+ for (int64_t i00 = 2*(blockIdx.y*blockDim.x + threadIdx.x); i00 < ne00; i00 += 2*gridDim.y*blockDim.x) {
// The x and y dimensions of the grid are swapped because the maximum allowed grid size for x is higher.
const int i10 = blockIdx.x;
const uint2 dm = fast_div_modulo((uint32_t)z, ne12_fdv);