fix: don't call newBufferWithBytesNoCopy with NULL when ggml_metal_host_malloc returns NULL

This commit is contained in:
Gilad S 2024-05-05 01:56:36 +03:00 committed by GitHub
parent bfa4daea4e
commit a92efecb86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2944,14 +2944,16 @@ GGML_CALL static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buff
ctx->owned = true; ctx->owned = true;
ctx->n_buffers = 1; ctx->n_buffers = 1;
ctx->buffers[0].data = ctx->all_data; if (ctx->all_data != NULL) {
ctx->buffers[0].size = size; ctx->buffers[0].data = ctx->all_data;
ctx->buffers[0].metal = [device newBufferWithBytesNoCopy:ctx->all_data ctx->buffers[0].size = size;
length:size_aligned ctx->buffers[0].metal = [device newBufferWithBytesNoCopy:ctx->all_data
options:MTLResourceStorageModeShared length:size_aligned
deallocator:nil]; options:MTLResourceStorageModeShared
deallocator:nil];
}
if (ctx->buffers[0].metal == nil) { if (ctx->all_data == NULL || ctx->buffers[0].metal == nil) {
GGML_METAL_LOG_ERROR("%s: error: failed to allocate buffer, size = %8.2f MiB\n", __func__, size_aligned / 1024.0 / 1024.0); GGML_METAL_LOG_ERROR("%s: error: failed to allocate buffer, size = %8.2f MiB\n", __func__, size_aligned / 1024.0 / 1024.0);
free(ctx); free(ctx);
ggml_backend_metal_free_device(); ggml_backend_metal_free_device();