Commit 48e985756 for llama.cpp
commit 48e985756788b4a6c50933a88e0af1aa8412b68d
Author: SecondSeed <38520721+SecondSeed@users.noreply.github.com>
Date: Tue Oct 13 03:57:26 2026 +0800
metal: fix metal tensor kernel_mul_mm error for large tensor (#28748)
* metal: fix metal tensor kernel_mul_mm error for large tensor
Assisted-by: Codex
* Update ggml/src/ggml-metal/kernels/mul_mm.metal
Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com>
---------
Co-authored-by: 向锡铭 <xiangximing@xiangximings-MacBook-Air.local>
Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com>
diff --git a/ggml/src/ggml-metal/kernels/mul_mm.metal b/ggml/src/ggml-metal/kernels/mul_mm.metal
index dee13d878..dfa5102c5 100644
--- a/ggml/src/ggml-metal/kernels/mul_mm.metal
+++ b/ggml/src/ggml-metal/kernels/mul_mm.metal
@@ -135,11 +135,15 @@ kernel void kernel_mul_mm(
}
// Store result tile to output matrix (with batch offset)
- // cT.store handles bounds checking via tD's extents (M, N)
- device float * dstBatch = (device float *)dst + im * N * M;
+ // a slice is not used because its byte offset is int32 and wraps at 2 GiB
+ // ref: https://github.com/ggml-org/llama.cpp/pull/28748
+ const int tileM = min(NRA, M - ra);
+ const int tileN = min(NRB, N - rb);
- auto tD = tensor(dstBatch, dextents<int32_t, 2>(M, N), array<int, 2>({1, M}));
- cT.store(tD.slice(ra, rb));
+ device float * dstTile = (device float *)dst + (uint64_t) im * N * M + (uint64_t) rb * M + ra;
+
+ auto tD = tensor(dstTile, dextents<int32_t, 2>(tileM, tileN), array<int, 2>({1, M}));
+ cT.store(tD);
}
#else