From 5acc9e50f5f47709207e844acdfffa488370b0d9 Mon Sep 17 00:00:00 2001 From: slaren Date: Sun, 24 Dec 2023 11:59:15 +0100 Subject: [PATCH] cuda : fallback to CPU on host buffer alloc fail --- ggml-cuda.cu | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ggml-cuda.cu b/ggml-cuda.cu index f61f06853..bdf7498ba 100644 --- a/ggml-cuda.cu +++ b/ggml-cuda.cu @@ -9797,8 +9797,10 @@ static void ggml_backend_cuda_host_buffer_free_buffer(ggml_backend_buffer_t buff static ggml_backend_buffer_t ggml_backend_cuda_host_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) { void * ptr = ggml_cuda_host_malloc(size); + if (ptr == nullptr) { - return nullptr; + // fallback to cpu buffer + return ggml_backend_buft_alloc_buffer(ggml_backend_cpu_buffer_type(), size); } // FIXME: this is a hack to avoid having to implement a new buffer type