LLM inference in C/C++
C++ ggml
metal : null-check buffer alloc to fix OOM crash (#25371)
Yuri Khrustalev3737e41370da
diff --git a/ggml/src/ggml-metal/ggml-metal.cpp b/ggml/src/ggml-metal/ggml-metal.cppindex e5b2ee8a55..9756d47050 100644--- a/ggml/src/ggml-metal/ggml-metal.cpp+++ b/ggml/src/ggml-metal/ggml-metal.cpp@@ -204,6 +204,11 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_baggml_metal_device_t ctx_dev = (ggml_metal_device_t)buft->device->context;ggml_metal_buffer_t res = ggml_metal_buffer_init(ctx_dev, size, shared);+ if (res == NULL) {+ GGML_LOG_ERROR("%s: failed to allocate Metal buffer of %zu bytes (out of memory)\n", __func__, size);+ return NULL;+ }+ggml_backend_buffer_i buf_i = ggml_metal_buffer_is_shared(res)? ggml_backend_metal_buffer_shared_i: ggml_backend_metal_buffer_private_i;