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
This commit is contained in:
Georgi Gerganov
2026-04-29 14:57:48 +03:00
parent f9e19a1f6e
commit c6a04cb5c3
+14 -26
View File
@@ -415,19 +415,13 @@ void ggml_metal_set_tensor_2d_async(ggml_metal_t ctx, struct ggml_tensor * tenso
id<MTLCommandBuffer> cmd_buf = [queue commandBuffer];
id<MTLBlitCommandEncoder> 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<MTLCommandBuffer> cmd_buf = [queue commandBuffer];
id<MTLBlitCommandEncoder> 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];