@@ -2793,14 +2793,12 @@ static void ggml_vk_print_gpu_info(size_t idx) {
27932793static bool ggml_vk_instance_validation_ext_available (const std::vector<vk::ExtensionProperties>& instance_extensions);
27942794static bool ggml_vk_instance_portability_enumeration_ext_available (const std::vector<vk::ExtensionProperties>& instance_extensions);
27952795
2796- void ggml_vk_instance_init () {
2796+ static void ggml_vk_instance_init () {
27972797 if (vk_instance_initialized) {
27982798 return ;
27992799 }
28002800 VK_LOG_DEBUG (" ggml_vk_instance_init()" );
28012801
2802- vk_instance_initialized = true ;
2803-
28042802 uint32_t api_version = vk::enumerateInstanceVersion ();
28052803
28062804 if (api_version < VK_API_VERSION_1_2) {
@@ -2851,6 +2849,7 @@ void ggml_vk_instance_init() {
28512849 GGML_LOG_DEBUG (" ggml_vulkan: Validation layers enabled\n " );
28522850 }
28532851 vk_instance.instance = vk::createInstance (instance_create_info);
2852+ vk_instance_initialized = true ;
28542853
28552854 size_t num_available_devices = vk_instance.instance .enumeratePhysicalDevices ().size ();
28562855
@@ -2875,7 +2874,7 @@ void ggml_vk_instance_init() {
28752874 // Make sure at least one device exists
28762875 if (devices.empty ()) {
28772876 std::cerr << " ggml_vulkan: Error: No devices found." << std::endl;
2878- GGML_ABORT ( " fatal error " ) ;
2877+ return ;
28792878 }
28802879
28812880 // Default to using all dedicated GPUs
@@ -8350,8 +8349,13 @@ ggml_backend_reg_t ggml_backend_vk_reg() {
83508349 /* .iface = */ ggml_backend_vk_reg_i,
83518350 /* .context = */ nullptr ,
83528351 };
8353-
8354- return ®
8352+ try {
8353+ ggml_vk_instance_init ();
8354+ return ®
8355+ } catch (const vk::SystemError& e) {
8356+ VK_LOG_DEBUG (" ggml_backend_vk_reg() -> Error: System error: " << e.what ());
8357+ return nullptr ;
8358+ }
83558359}
83568360
83578361// Extension availability
0 commit comments