Skip to content

Commit

Permalink
vulkan : retry allocation with fallback flags (whisper/2451)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Morris <[email protected]>
  • Loading branch information
2 people authored and ggerganov committed Oct 6, 2024
1 parent 8c475b9 commit b0915d5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions ggml/src/ggml-vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b0915d5

Please sign in to comment.