From: SRHMorris Date: Sun, 6 Oct 2024 07:34:20 +0000 (+0100) Subject: vulkan : retry allocation with fallback flags (whisper/2451) X-Git-Tag: upstream/0.0.1642~300 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=1210a0a1bd03e0e9f3631e991c5db2001655318b;p=pkg%2Fggml%2Fsources%2Fggml vulkan : retry allocation with fallback flags (whisper/2451) Co-authored-by: Samuel Morris --- diff --git a/src/ggml-vulkan.cpp b/src/ggml-vulkan.cpp index 12ad9d81..30bd376d 100644 --- a/src/ggml-vulkan.cpp +++ b/src/ggml-vulkan.cpp @@ -1070,10 +1070,25 @@ static vk_buffer ggml_vk_create_buffer(vk_device& device, size_t size, vk::Memor try { buf->device_memory = device->device.allocateMemory({ mem_req.size, memory_type_index }); } catch (const vk::SystemError& e) { - // Out of Host/Device memory, clean up buffer - device->device.destroyBuffer(buf->buffer); - buf->size = 0; - throw e; + if (buf->memory_property_flags != fallback_flags) { + // Try again with fallback flags + memory_type_index = find_properties(&mem_props, &mem_req, fallback_flags); + buf->memory_property_flags = fallback_flags; + + try { + buf->device_memory = device->device.allocateMemory({ mem_req.size, memory_type_index }); + } + catch (const vk::SystemError& e) { + device->device.destroyBuffer(buf->buffer); + buf->size = 0; + throw e; + } + } else { + // Out of Host/Device memory, clean up buffer + device->device.destroyBuffer(buf->buffer); + buf->size = 0; + throw e; + } } buf->ptr = nullptr;