Commit 8d0323c85 for llama.cpp

commit 8d0323c8562a01918574af3e78bc79432ba7b45c
Author: Jeff Bolz <jbolz@nvidia.com>
Date:   Mon Nov 30 08:40:16 2026 -0600

    vulkan: handle ADD_ID with more tokens than maxComputeWorkGroupCount[1] (#33232)

    Clamp the workgroup count and loop in the shader. The failing test was
    added in #33162.

diff --git a/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h b/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h
index 026ad8935..a92d20eb6 100644
--- a/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h
+++ b/ggml/src/ggml-vulkan/ggml-vulkan-push-constants.h
@@ -541,6 +541,7 @@ struct vk_op_topk_moe_push_constants {
 struct vk_op_add_id_push_constants {
     uint32_t ne0;
     uint32_t ne1;
+    uint32_t ne2;
     uint32_t s01;
     uint32_t s02;
     uint32_t s11;
diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
index 50bc27148..0a5956eb0 100644
--- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp
+++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
@@ -11182,7 +11182,8 @@ static void ggml_vk_op_f32(ggml_backend_vk_context * ctx, vk_context& subctx, co
         } break;
     case GGML_OP_ADD_ID:
         {
-            elements = { (uint32_t)ne01, (uint32_t)ne02, 1 };
+            // the shader loops over the tokens when there are more than the workgroups in y
+            elements = { (uint32_t)ne01, std::min((uint32_t)ne02, ctx->device->properties.limits.maxComputeWorkGroupCount[1]), 1 };
         } break;
     case GGML_OP_SET_ROWS:
         {
@@ -11646,6 +11647,7 @@ void ggml_vk_add_id(ggml_backend_vk_context * ctx, vk_context& subctx, const ggm
     ggml_vk_op_f32<vk_op_add_id_push_constants>(ctx, subctx, src0, src1, src2, nullptr, dst, GGML_OP_ADD_ID, {
         (uint32_t)dst->ne[0],
         (uint32_t)dst->ne[1],
+        (uint32_t)dst->ne[2],
         (uint32_t)src0->nb[1] / src0_type_size,
         (uint32_t)src0->nb[2] / src0_type_size,
         (uint32_t)src1->nb[1] / src1_type_size,
diff --git a/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp b/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp
index bf6206704..de559b246 100644
--- a/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp
+++ b/ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp
@@ -8,6 +8,7 @@ layout (push_constant) uniform parameter
 {
     uint ne0;
     uint ne1;
+    uint ne2;
     uint s01;
     uint s02;
     uint s11;
@@ -25,26 +26,28 @@ layout (binding = 3) writeonly buffer D {D_TYPE data_d[];};

 void main() {
     const uint i1 = gl_WorkGroupID.x;
-    const uint i2 = gl_WorkGroupID.y;
-
-    const int i11 = data_c[i1 + i2 * p.s21];

     const uint s1 = p.ne0;
     const uint s2 = p.ne0 * p.ne1;

-    const uint d0 = i1 * s1 + i2 * s2;
-    const uint a0 = i1 * p.s01 + i2 * p.s02;
+    // the tokens, gl_NumWorkGroups.y apart (more tokens than maxComputeWorkGroupCount[1] loop)
+    for (uint i2 = gl_WorkGroupID.y; i2 < p.ne2; i2 += gl_NumWorkGroups.y) {
+        const int i11 = data_c[i1 + i2 * p.s21];

-    if (i11 == -1) { // skipped slot, add nothing
-        for (uint i0 = gl_LocalInvocationID.x; i0 < p.ne0; i0 += BLOCK_SIZE) {
-            data_d[d0 + i0] = data_a[a0 + i0];
+        const uint d0 = i1 * s1 + i2 * s2;
+        const uint a0 = i1 * p.s01 + i2 * p.s02;
+
+        if (i11 == -1) { // skipped slot, add nothing
+            for (uint i0 = gl_LocalInvocationID.x; i0 < p.ne0; i0 += BLOCK_SIZE) {
+                data_d[d0 + i0] = data_a[a0 + i0];
+            }
+            continue;
         }
-        return;
-    }

-    const uint b0 = uint(i11) * p.s11;
+        const uint b0 = uint(i11) * p.s11;

-    for (uint i0 = gl_LocalInvocationID.x; i0 < p.ne0; i0 += BLOCK_SIZE) {
-        data_d[d0 + i0] = data_a[a0 + i0] + data_b[b0 + i0];
+        for (uint i0 = gl_LocalInvocationID.x; i0 < p.ne0; i0 += BLOCK_SIZE) {
+            data_d[d0 + i0] = data_a[a0 + i0] + data_b[b0 + i0];
+        }
     }
 }