Skip to content

Commit

Permalink
vulkan: Make Vulkan optional at runtime (#11493).
Browse files Browse the repository at this point in the history
  • Loading branch information
daym committed Jan 29, 2025
1 parent 66ee4f2 commit bc7f4bb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ggml/src/ggml-vulkan/ggml-vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2765,8 +2765,6 @@ void ggml_vk_instance_init() {
}
VK_LOG_DEBUG("ggml_vk_instance_init()");

vk_instance_initialized = true;

uint32_t api_version = vk::enumerateInstanceVersion();

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

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

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

// Default to using all dedicated GPUs
Expand Down Expand Up @@ -8305,8 +8304,13 @@ ggml_backend_reg_t ggml_backend_vk_reg() {
/* .iface = */ ggml_backend_vk_reg_i,
/* .context = */ nullptr,
};

return &reg;
try {
ggml_vk_instance_init();
return &reg;
} catch (const vk::SystemError& e) {
VK_LOG_DEBUG("ggml_backend_vk_reg() -> Error: System error: " << e.what());
return nullptr;
}
}

// Extension availability
Expand Down

0 comments on commit bc7f4bb

Please sign in to comment.