@@ -3595,11 +3595,11 @@ static void ggml_vk_instance_init() {
3595
3595
3596
3596
vk_perf_logger_enabled = getenv("GGML_VK_PERF_LOGGER") != nullptr;
3597
3597
3598
- size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
3599
-
3600
3598
// Emulate behavior of CUDA_VISIBLE_DEVICES for Vulkan
3601
3599
char * devices_env = getenv("GGML_VK_VISIBLE_DEVICES");
3602
3600
if (devices_env != nullptr) {
3601
+ size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
3602
+
3603
3603
std::string devices(devices_env);
3604
3604
std::replace(devices.begin(), devices.end(), ',', ' ');
3605
3605
@@ -3615,9 +3615,9 @@ static void ggml_vk_instance_init() {
3615
3615
} else {
3616
3616
std::vector<vk::PhysicalDevice> devices = vk_instance.instance.enumeratePhysicalDevices();
3617
3617
3618
- // Make sure at least one device exists
3618
+ // If no vulkan devices are found, return early
3619
3619
if (devices.empty()) {
3620
- std::cerr << "ggml_vulkan: Error: No devices found." << std::endl ;
3620
+ GGML_LOG_INFO( "ggml_vulkan: No devices found.\n") ;
3621
3621
return;
3622
3622
}
3623
3623
@@ -3700,9 +3700,20 @@ static void ggml_vk_instance_init() {
3700
3700
}
3701
3701
}
3702
3702
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
+
3704
3714
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;
3706
3717
}
3707
3718
}
3708
3719
GGML_LOG_DEBUG("ggml_vulkan: Found %zu Vulkan devices:\n", vk_instance.device_indices.size());
0 commit comments