Skip to content

Commit a9e8dc4

Browse files
committed
vulkan: detect multiple devices by deviceUUID instead of deviceID
1 parent a785474 commit a9e8dc4

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

ggml-vulkan.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,39 +1745,45 @@ void ggml_vk_instance_init() {
17451745

17461746
// Default to using all dedicated GPUs
17471747
for (size_t i = 0; i < devices.size(); i++) {
1748-
vk::PhysicalDeviceProperties props = devices[i].getProperties();
1749-
1750-
if (props.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
1748+
vk::PhysicalDeviceProperties new_props_1 = devices[i].getProperties();
1749+
vk::PhysicalDeviceProperties2 new_props_2;
1750+
vk::PhysicalDeviceDriverProperties new_driver;
1751+
vk::PhysicalDeviceIDProperties new_id;
1752+
new_props_2.pNext = &new_driver;
1753+
new_driver.pNext = &new_id;
1754+
devices[i].getProperties2(&new_props_2);
1755+
1756+
if (new_props_1.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
17511757
// Check if there are two physical devices corresponding to the same GPU
17521758
auto old_device = std::find_if(
17531759
vk_instance.device_indices.begin(),
17541760
vk_instance.device_indices.end(),
1755-
[&devices, &props](const size_t k){ return devices[k].getProperties().deviceID == props.deviceID; }
1761+
[&devices, &new_id](const size_t k){
1762+
vk::PhysicalDeviceProperties2 old_props_2;
1763+
vk::PhysicalDeviceIDProperties old_id;
1764+
devices[k].getProperties2(&old_props_2);
1765+
return std::equal(std::begin(old_id.deviceUUID), std::end(old_id.deviceUUID), std::begin(new_id.deviceUUID));
1766+
}
17561767
);
17571768
if (old_device == vk_instance.device_indices.end()) {
17581769
vk_instance.device_indices.push_back(i);
17591770
} else {
17601771
// There can be two physical devices corresponding to the same GPU if there are 2 different drivers
17611772
// This can cause error when splitting layers aross the devices, need to keep only 1
1762-
VK_LOG_DEBUG("Device " << i << " and device " << *old_device << " have the same device id");
1773+
VK_LOG_DEBUG("Device " << i << " and device " << *old_device << " have the same deviceUUID");
17631774

1764-
vk::PhysicalDeviceProperties2 old_prop;
1775+
vk::PhysicalDeviceProperties2 old_props_2;
17651776
vk::PhysicalDeviceDriverProperties old_driver;
1766-
old_prop.pNext = &old_driver;
1767-
devices[*old_device].getProperties2(&old_prop);
1768-
1769-
vk::PhysicalDeviceProperties2 new_prop;
1770-
vk::PhysicalDeviceDriverProperties new_driver;
1771-
new_prop.pNext = &new_driver;
1772-
devices[i].getProperties2(&new_prop);
1777+
old_props_2.pNext = &old_driver;
1778+
devices[*old_device].getProperties2(&old_props_2);
17731779

17741780
std::map<vk::DriverId, int> driver_priorities {};
17751781
int old_priority = std::numeric_limits<int>::max();
17761782
int new_priority = std::numeric_limits<int>::max();
17771783

17781784
// Check https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDriverId.html for the list of driver id
17791785
// Smaller number -> higher priority
1780-
switch (old_prop.properties.vendorID) {
1786+
switch (old_props_2.properties.vendorID) {
17811787
case VK_VENDOR_ID_AMD:
17821788
driver_priorities[vk::DriverId::eMesaRadv] = 1;
17831789
driver_priorities[vk::DriverId::eAmdOpenSource] = 2;

0 commit comments

Comments
 (0)