]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
vulkan : retry allocation with fallback flags (whisper/2451)
authorSRHMorris <redacted>
Sun, 6 Oct 2024 07:34:20 +0000 (08:34 +0100)
committerGeorgi Gerganov <redacted>
Sun, 6 Oct 2024 09:52:11 +0000 (12:52 +0300)
Co-authored-by: Samuel Morris <redacted>
ggml/src/ggml-vulkan.cpp

index 12ad9d810327f258447ba81575e2f61db0aa5493..30bd376da61882aca8361f98a4333ae4933c3961 100644 (file)
@@ -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;