mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-10-28 08:31:25 +00:00
metal : report OOM errors (#16274)
This commit is contained in:
@@ -222,7 +222,28 @@ void ggml_metal_synchronize(ggml_metal_t ctx) {
|
|||||||
ctx->cmd_buf_last = nil;
|
ctx->cmd_buf_last = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// release any completed command buffers
|
// check status of all command buffers
|
||||||
|
{
|
||||||
|
const int n_cb = ctx->n_cb;
|
||||||
|
|
||||||
|
for (int cb_idx = 0; cb_idx <= n_cb; ++cb_idx) {
|
||||||
|
id<MTLCommandBuffer> cmd_buf = ctx->cmd_bufs[cb_idx].obj;
|
||||||
|
if (!cmd_buf) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MTLCommandBufferStatus status = [cmd_buf status];
|
||||||
|
if (status != MTLCommandBufferStatusCompleted) {
|
||||||
|
GGML_LOG_ERROR("%s: error: command buffer %d failed with status %d\n", __func__, cb_idx, (int) status);
|
||||||
|
if (status == MTLCommandBufferStatusError) {
|
||||||
|
GGML_LOG_ERROR("error: %s\n", [[cmd_buf error].localizedDescription UTF8String]);
|
||||||
|
}
|
||||||
|
GGML_ABORT("fatal error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// release any completed extra command buffers
|
||||||
if (ctx->cmd_bufs_ext.count > 0) {
|
if (ctx->cmd_bufs_ext.count > 0) {
|
||||||
for (size_t i = 0; i < ctx->cmd_bufs_ext.count; ++i) {
|
for (size_t i = 0; i < ctx->cmd_bufs_ext.count; ++i) {
|
||||||
id<MTLCommandBuffer> cmd_buf = ctx->cmd_bufs_ext[i];
|
id<MTLCommandBuffer> cmd_buf = ctx->cmd_bufs_ext[i];
|
||||||
@@ -260,6 +281,8 @@ void ggml_metal_set_tensor_async(ggml_metal_t ctx, struct ggml_tensor * tensor,
|
|||||||
length:size
|
length:size
|
||||||
options:MTLResourceStorageModeShared];
|
options:MTLResourceStorageModeShared];
|
||||||
|
|
||||||
|
GGML_ASSERT(buf_src);
|
||||||
|
|
||||||
struct ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(tensor);
|
struct ggml_metal_buffer_id bid_dst = ggml_metal_get_buffer_id(tensor);
|
||||||
if (bid_dst.metal == nil) {
|
if (bid_dst.metal == nil) {
|
||||||
GGML_ABORT("%s: failed to find buffer for tensor '%s'\n", __func__, tensor->name);
|
GGML_ABORT("%s: failed to find buffer for tensor '%s'\n", __func__, tensor->name);
|
||||||
@@ -299,6 +322,8 @@ void ggml_metal_get_tensor_async(ggml_metal_t ctx, const struct ggml_tensor * te
|
|||||||
options:MTLResourceStorageModeShared
|
options:MTLResourceStorageModeShared
|
||||||
deallocator:nil];
|
deallocator:nil];
|
||||||
|
|
||||||
|
GGML_ASSERT(buf_dst);
|
||||||
|
|
||||||
struct ggml_metal_buffer_id bid_src = ggml_metal_get_buffer_id(tensor);
|
struct ggml_metal_buffer_id bid_src = ggml_metal_get_buffer_id(tensor);
|
||||||
if (bid_src.metal == nil) {
|
if (bid_src.metal == nil) {
|
||||||
GGML_ABORT("%s: failed to find buffer for tensor '%s'\n", __func__, tensor->name);
|
GGML_ABORT("%s: failed to find buffer for tensor '%s'\n", __func__, tensor->name);
|
||||||
|
|||||||
@@ -1176,6 +1176,8 @@ void ggml_metal_buffer_set_tensor(ggml_metal_buffer_t buf, struct ggml_tensor *
|
|||||||
options:MTLResourceStorageModeShared
|
options:MTLResourceStorageModeShared
|
||||||
deallocator:nil];
|
deallocator:nil];
|
||||||
|
|
||||||
|
GGML_ASSERT(buf_src);
|
||||||
|
|
||||||
// dst
|
// dst
|
||||||
struct ggml_metal_buffer_id bid_dst = ggml_metal_buffer_get_id(buf, tensor);
|
struct ggml_metal_buffer_id bid_dst = ggml_metal_buffer_get_id(buf, tensor);
|
||||||
bid_dst.offs += offset;
|
bid_dst.offs += offset;
|
||||||
@@ -1232,6 +1234,8 @@ void ggml_metal_buffer_get_tensor(ggml_metal_buffer_t buf, const struct ggml_ten
|
|||||||
options:MTLResourceStorageModeShared
|
options:MTLResourceStorageModeShared
|
||||||
deallocator:nil];
|
deallocator:nil];
|
||||||
|
|
||||||
|
GGML_ASSERT(buf_dst);
|
||||||
|
|
||||||
id<MTLCommandQueue> queue = buf->queue;
|
id<MTLCommandQueue> queue = buf->queue;
|
||||||
id<MTLCommandBuffer> cmd_buf = [queue commandBufferWithUnretainedReferences];
|
id<MTLCommandBuffer> cmd_buf = [queue commandBufferWithUnretainedReferences];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user