Skip to content

Commit ed316c6

Browse files
AdriankhlNeoZhangJianyu
authored andcommitted
vulkan: detect multiple devices by deviceUUID instead of deviceID (ggml-org#8022)
* vulkan: detect multiple devices by deviceUUID instead of deviceID * vulkan: remove unneeded variables * vulkan: fix id query
1 parent 8a9ff8f commit ed316c6

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

ggml-vulkan.cpp

+20-14
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::PhysicalDeviceProperties2 new_props;
1749+
vk::PhysicalDeviceDriverProperties new_driver;
1750+
vk::PhysicalDeviceIDProperties new_id;
1751+
new_props.pNext = &new_driver;
1752+
new_driver.pNext = &new_id;
1753+
devices[i].getProperties2(&new_props);
1754+
1755+
if (new_props.properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
17511756
// Check if there are two physical devices corresponding to the same GPU
17521757
auto old_device = std::find_if(
17531758
vk_instance.device_indices.begin(),
17541759
vk_instance.device_indices.end(),
1755-
[&devices, &props](const size_t k){ return devices[k].getProperties().deviceID == props.deviceID; }
1760+
[&devices, &new_id](const size_t k){
1761+
vk::PhysicalDeviceProperties2 old_props;
1762+
vk::PhysicalDeviceIDProperties old_id;
1763+
old_props.pNext = &old_id;
1764+
devices[k].getProperties2(&old_props);
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;
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.pNext = &old_driver;
1778+
devices[*old_device].getProperties2(&old_props);
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.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)