Spaces:
Sleeping
Sleeping
vulkan : retry allocation with fallback flags (#2451)
Browse filesCo-authored-by: Samuel Morris <[email protected]>
- ggml/src/ggml-vulkan.cpp +19 -4
ggml/src/ggml-vulkan.cpp
CHANGED
|
@@ -1070,10 +1070,25 @@ static vk_buffer ggml_vk_create_buffer(vk_device& device, size_t size, vk::Memor
|
|
| 1070 |
try {
|
| 1071 |
buf->device_memory = device->device.allocateMemory({ mem_req.size, memory_type_index });
|
| 1072 |
} catch (const vk::SystemError& e) {
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1077 |
}
|
| 1078 |
buf->ptr = nullptr;
|
| 1079 |
|
|
|
|
| 1070 |
try {
|
| 1071 |
buf->device_memory = device->device.allocateMemory({ mem_req.size, memory_type_index });
|
| 1072 |
} catch (const vk::SystemError& e) {
|
| 1073 |
+
if (buf->memory_property_flags != fallback_flags) {
|
| 1074 |
+
// Try again with fallback flags
|
| 1075 |
+
memory_type_index = find_properties(&mem_props, &mem_req, fallback_flags);
|
| 1076 |
+
buf->memory_property_flags = fallback_flags;
|
| 1077 |
+
|
| 1078 |
+
try {
|
| 1079 |
+
buf->device_memory = device->device.allocateMemory({ mem_req.size, memory_type_index });
|
| 1080 |
+
}
|
| 1081 |
+
catch (const vk::SystemError& e) {
|
| 1082 |
+
device->device.destroyBuffer(buf->buffer);
|
| 1083 |
+
buf->size = 0;
|
| 1084 |
+
throw e;
|
| 1085 |
+
}
|
| 1086 |
+
} else {
|
| 1087 |
+
// Out of Host/Device memory, clean up buffer
|
| 1088 |
+
device->device.destroyBuffer(buf->buffer);
|
| 1089 |
+
buf->size = 0;
|
| 1090 |
+
throw e;
|
| 1091 |
+
}
|
| 1092 |
}
|
| 1093 |
buf->ptr = nullptr;
|
| 1094 |
|