@@ -3595,11 +3595,11 @@ static void ggml_vk_instance_init() {
35953595
35963596 vk_perf_logger_enabled = getenv("GGML_VK_PERF_LOGGER") != nullptr;
35973597
3598- size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
3599-
36003598 // Emulate behavior of CUDA_VISIBLE_DEVICES for Vulkan
36013599 char * devices_env = getenv("GGML_VK_VISIBLE_DEVICES");
36023600 if (devices_env != nullptr) {
3601+ size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
3602+
36033603 std::string devices(devices_env);
36043604 std::replace(devices.begin(), devices.end(), ',', ' ');
36053605
@@ -3615,9 +3615,9 @@ static void ggml_vk_instance_init() {
36153615 } else {
36163616 std::vector<vk::PhysicalDevice> devices = vk_instance.instance.enumeratePhysicalDevices();
36173617
3618- // Make sure at least one device exists
3618+ // If no vulkan devices are found, return early
36193619 if (devices.empty()) {
3620- std::cerr << "ggml_vulkan: Error: No devices found." << std::endl ;
3620+ GGML_LOG_INFO( "ggml_vulkan: No devices found.\n") ;
36213621 return;
36223622 }
36233623
@@ -3700,9 +3700,20 @@ static void ggml_vk_instance_init() {
37003700 }
37013701 }
37023702
3703- // If no dedicated GPUs found, fall back to GPU 0
3703+ // If no dedicated GPUs found, fall back to the first non-CPU device.
3704+ // If only CPU devices are available, return without devices.
3705+ if (vk_instance.device_indices.empty()) {
3706+ for (size_t i = 0; i < devices.size(); i++) {
3707+ if (devices[i].getProperties().deviceType != vk::PhysicalDeviceType::eCpu) {
3708+ vk_instance.device_indices.push_back(i);
3709+ break;
3710+ }
3711+ }
3712+ }
3713+
37043714 if (vk_instance.device_indices.empty()) {
3705- vk_instance.device_indices.push_back(0);
3715+ GGML_LOG_INFO("ggml_vulkan: No devices found.\n");
3716+ return;
37063717 }
37073718 }
37083719 GGML_LOG_DEBUG("ggml_vulkan: Found %zu Vulkan devices:\n", vk_instance.device_indices.size());
0 commit comments