@@ -2759,14 +2759,12 @@ static void ggml_vk_print_gpu_info(size_t idx) {
27592759static bool ggml_vk_instance_validation_ext_available (const std::vector<vk::ExtensionProperties>& instance_extensions);
27602760static bool ggml_vk_instance_portability_enumeration_ext_available (const std::vector<vk::ExtensionProperties>& instance_extensions);
27612761
2762- void ggml_vk_instance_init () {
2762+ static void ggml_vk_instance_init () {
27632763 if (vk_instance_initialized) {
27642764 return ;
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 ®
8307+ try {
8308+ ggml_vk_instance_init ();
8309+ return ®
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