From c6a04cb5c38df58349c3d9b5f46dcb1b948d11a7 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 29 Apr 2026 14:57:48 +0300 Subject: [PATCH] ggml-metal: fix 2D async copy to use row-by-row transfers The MTLBlitCommandEncoder 2D copy method is not properly declared in the headers, causing compiler warnings. Use a loop with the simpler 1D copy method instead, which is already used elsewhere in the codebase. Assisted-by: llama.cpp:local pi --- ggml/src/ggml-metal/ggml-metal-context.m | 40 +++++++++--------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/ggml/src/ggml-metal/ggml-metal-context.m b/ggml/src/ggml-metal/ggml-metal-context.m index b5101ff718..5ae4dab029 100644 --- a/ggml/src/ggml-metal/ggml-metal-context.m +++ b/ggml/src/ggml-metal/ggml-metal-context.m @@ -415,19 +415,13 @@ void ggml_metal_set_tensor_2d_async(ggml_metal_t ctx, struct ggml_tensor * tenso id cmd_buf = [queue commandBuffer]; id encoder = [cmd_buf blitCommandEncoder]; - [encoder copyFromBuffer:buf_src - sourceOffset:0 - sourceBytesPerRow:stride_data - sourceBytesPerImage:0 - sourceHeight:n_copies - sourceDepth:1 - toBuffer:bid_dst.metal - destinationOffset:bid_dst.offs - destinationBytesPerRow:stride_tensor - destinationBytesPerImage:0 - destinationHeight:n_copies - destinationDepth:1 - size:MTLSizeMake(size, 1, 1)]; + for (size_t i = 0; i < n_copies; i++) { + [encoder copyFromBuffer:buf_src + sourceOffset:i * stride_data + toBuffer:bid_dst.metal + destinationOffset:bid_dst.offs + i * stride_tensor + size:size]; + } [encoder endEncoding]; [cmd_buf commit]; @@ -463,19 +457,13 @@ void ggml_metal_get_tensor_2d_async(ggml_metal_t ctx, const struct ggml_tensor * id cmd_buf = [queue commandBuffer]; id encoder = [cmd_buf blitCommandEncoder]; - [encoder copyFromBuffer:bid_src.metal - sourceOffset:bid_src.offs - sourceBytesPerRow:stride_tensor - sourceBytesPerImage:0 - sourceHeight:n_copies - sourceDepth:1 - toBuffer:buf_dst - destinationOffset:0 - destinationBytesPerRow:stride_data - destinationBytesPerImage:0 - destinationHeight:n_copies - destinationDepth:1 - size:MTLSizeMake(size, 1, 1)]; + for (size_t i = 0; i < n_copies; i++) { + [encoder copyFromBuffer:bid_src.metal + sourceOffset:bid_src.offs + i * stride_tensor + toBuffer:buf_dst + destinationOffset:i * stride_data + size:size]; + } [encoder endEncoding]; [cmd_buf commit];