Skip to content

Commit bc7f4bb

Browse files
committed
vulkan: Make Vulkan optional at runtime (#11493).
1 parent 66ee4f2 commit bc7f4bb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,8 +2765,6 @@ void ggml_vk_instance_init() {
27652765
}
27662766
VK_LOG_DEBUG("ggml_vk_instance_init()");
27672767

2768-
vk_instance_initialized = true;
2769-
27702768
uint32_t api_version = vk::enumerateInstanceVersion();
27712769

27722770
if (api_version < VK_API_VERSION_1_2) {
@@ -2817,6 +2815,7 @@ void ggml_vk_instance_init() {
28172815
GGML_LOG_DEBUG("ggml_vulkan: Validation layers enabled\n");
28182816
}
28192817
vk_instance.instance = vk::createInstance(instance_create_info);
2818+
vk_instance_initialized = true;
28202819

28212820
size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
28222821

@@ -2841,7 +2840,7 @@ void ggml_vk_instance_init() {
28412840
// Make sure at least one device exists
28422841
if (devices.empty()) {
28432842
std::cerr << "ggml_vulkan: Error: No devices found." << std::endl;
2844-
GGML_ABORT("fatal error");
2843+
return;
28452844
}
28462845

28472846
// Default to using all dedicated GPUs
@@ -8305,8 +8304,13 @@ ggml_backend_reg_t ggml_backend_vk_reg() {
83058304
/* .iface = */ ggml_backend_vk_reg_i,
83068305
/* .context = */ nullptr,
83078306
};
8308-
8309-
return &reg;
8307+
try {
8308+
ggml_vk_instance_init();
8309+
return &reg;
8310+
} catch (const vk::SystemError& e) {
8311+
VK_LOG_DEBUG("ggml_backend_vk_reg() -> Error: System error: " << e.what());
8312+
return nullptr;
8313+
}
83108314
}
83118315

83128316
// Extension availability

0 commit comments

Comments
 (0)