Commit f351f415d for llama.cpp

commit f351f415d6a193b26dd41e80c140a141d758bc2d
Author: Georgi Gerganov <ggerganov@gmail.com>
Date:   Fri Nov 27 11:10:50 2026 +0200

    metal : check all fused nodes for concurrency (#33175)

    * metal : check all fused nodes for concurrency

    The concurrency check for a fused group only examined the last node, so
    intermediate outputs (e.g. the TOPK_MOE ids/weights) and the group's
    sources (e.g. the router logits) were ignored. This allowed the fused
    top-k kernel to run concurrently with the router matmul that writes its
    input, producing nondeterministic expert routing.

    Check every node of the fused group instead.

    Assisted-by: dsh:llama.cpp/ggml-org/DeepSeek-V4.1-Flash-1017-GGUF (Mac Studio, M5 Ultra, 256GB)

    * tests : update the Metal fusion baseline for bailingmoe3

    PR #33081 enables the SSM_CONV + SILU fusion in bailingmoe3. Record the
    new SSM_CONV+UNARY count in the Metal baseline.

    Assisted-by: dsh:llama.cpp/ggml-org/DeepSeek-V4.1-Flash-1017-GGUF (Mac Studio, M5 Ultra, 256GB)

diff --git a/ggml/src/ggml-metal/ggml-metal-ops.cpp b/ggml/src/ggml-metal/ggml-metal-ops.cpp
index c4c4f94dd..f2439bdb2 100644
--- a/ggml/src/ggml-metal/ggml-metal-ops.cpp
+++ b/ggml/src/ggml-metal/ggml-metal-ops.cpp
@@ -236,8 +236,13 @@ static int ggml_metal_op_encode_impl(ggml_metal_op_t ctx, int idx) {
             int n_fuse = 1;
             const ggml_metal_fusion * fusion = ctx->can_fuse(idx, GGML_METAL_FUSION_FULL, &n_fuse);
             if (fusion) {
-                // fused kernels write to the last node of the group, not necessarily to the first node's dst
-                is_concurrent = ggml_mem_ranges_check(ctx->mem_ranges, ctx->node(idx + n_fuse - 1));
+                // every node of the group contributes sources and destinations, check all of them
+                for (int j = 0; j < n_fuse; ++j) {
+                    if (!ggml_mem_ranges_check(ctx->mem_ranges, ctx->node(idx + j))) {
+                        is_concurrent = false;
+                        break;
+                    }
+                }
             }
         }

diff --git a/tests/fusion/MTL.csv b/tests/fusion/MTL.csv
index 65dbfde15..defaa0743 100644
--- a/tests/fusion/MTL.csv
+++ b/tests/fusion/MTL.csv
@@ -22,6 +22,7 @@ bailingmoe3         ,1   ,any     ,GATED_DELTA_NET+CPY         ,      1
 bailingmoe3         ,1   ,any     ,MUL+ADD                     ,      2
 bailingmoe3         ,1   ,any     ,RMS_NORM+MUL                ,      8
 bailingmoe3         ,1   ,any     ,RMS_NORM+SCALE              ,      2
+bailingmoe3         ,1   ,any     ,SSM_CONV+UNARY              ,      3
 bailingmoe3         ,1   ,any     ,UNARY+ADD+ARGSORT+GET_ROWS  ,      1
 beam                ,1   ,any     ,MUL+ADD                     ,      6
 beam                ,1   ,any     ,RMS_NORM+MUL                ,     25