Skip to content

Commit 011854a

Browse files
authored
[SYCL][Bindless][E2E] Match UUID when searching for Vulkan device (#18562)
Currently the Vulkan interop tests create a Vulkan device based on the name of the SYCL device. This only works for very simple cases where the Vulkan driver and the SYCL backend driver report a similar enough name. With this patch, a Vulkan device is created from a SYCL one by matching the device UUID, which guarantees the same device.
1 parent 707093d commit 011854a

File tree

8 files changed

+25
-31
lines changed

8 files changed

+25
-31
lines changed

sycl/test-e2e/bindless_images/vulkan_interop/buffer_usm.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ int main() {
299299

300300
sycl::device syclDevice;
301301

302-
if (vkutil::setupDevice(syclDevice.get_info<sycl::info::device::name>()) !=
303-
VK_SUCCESS) {
302+
if (vkutil::setupDevice(syclDevice) != VK_SUCCESS) {
304303
std::cerr << "Device setup failed!\n";
305304
return EXIT_FAILURE;
306305
}

sycl/test-e2e/bindless_images/vulkan_interop/depth_format.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ int main() {
363363

364364
sycl::device syclDevice;
365365

366-
if (vkutil::setupDevice(syclDevice.get_info<sycl::info::device::name>()) !=
367-
VK_SUCCESS) {
366+
if (vkutil::setupDevice(syclDevice) != VK_SUCCESS) {
368367
std::cerr << "Device setup failed!\n";
369368
return EXIT_FAILURE;
370369
}

sycl/test-e2e/bindless_images/vulkan_interop/mipmaps.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@ int main() {
447447

448448
sycl::device dev;
449449

450-
if (vkutil::setupDevice(dev.get_info<sycl::info::device::name>()) !=
451-
VK_SUCCESS) {
450+
if (vkutil::setupDevice(dev) != VK_SUCCESS) {
452451
std::cerr << "Device setup failed!\n";
453452
return EXIT_FAILURE;
454453
}

sycl/test-e2e/bindless_images/vulkan_interop/sampled_images.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ int main() {
578578

579579
sycl::device dev;
580580

581-
if (vkutil::setupDevice(dev.get_info<sycl::info::device::name>()) !=
582-
VK_SUCCESS) {
581+
if (vkutil::setupDevice(dev) != VK_SUCCESS) {
583582
std::cerr << "Device setup failed!\n";
584583
return EXIT_FAILURE;
585584
}

sycl/test-e2e/bindless_images/vulkan_interop/sampled_images_USM.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ int main() {
328328

329329
sycl::device dev;
330330

331-
if (vkutil::setupDevice(dev.get_info<sycl::info::device::name>()) !=
332-
VK_SUCCESS) {
331+
if (vkutil::setupDevice(dev) != VK_SUCCESS) {
333332
std::cerr << "Device setup failed!\n";
334333
return EXIT_FAILURE;
335334
}

sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,7 @@ int main() {
677677

678678
sycl::device dev;
679679

680-
if (vkutil::setupDevice(dev.get_info<sycl::info::device::name>()) !=
681-
VK_SUCCESS) {
680+
if (vkutil::setupDevice(dev) != VK_SUCCESS) {
682681
std::cerr << "Device setup failed!\n";
683682
return EXIT_FAILURE;
684683
}

sycl/test-e2e/bindless_images/vulkan_interop/unsampled_images_timeline_semaphore.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ int main() {
480480

481481
sycl::device dev;
482482

483-
if (vkutil::setupDevice(dev.get_info<sycl::info::device::name>()) !=
484-
VK_SUCCESS) {
483+
if (vkutil::setupDevice(dev) != VK_SUCCESS) {
485484
std::cerr << "Device setup failed!\n";
486485
return EXIT_FAILURE;
487486
}

sycl/test-e2e/bindless_images/vulkan_interop/vulkan_common.hpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ getSupportedDeviceExtensions(std::vector<VkExtensionProperties> &extensions,
207207
return VK_SUCCESS;
208208
}
209209

210-
// Set up the Vulkan device.
211-
VkResult setupDevice(std::string device) {
210+
// Set up the Vulkan device from the SYCL one
211+
VkResult setupDevice(const sycl::device &dev) {
212212
uint32_t physicalDeviceCount = 0;
213213
// Get all physical devices.
214214
VK_CHECK_CALL_RET(
@@ -237,24 +237,25 @@ VkResult setupDevice(std::string device) {
237237
#endif
238238
};
239239

240-
// Make lowercase to fix inconsistent capitalization between SYCL and Vulkan
241-
// device naming.
242-
std::transform(device.begin(), device.end(), device.begin(),
243-
[](unsigned char c) { return std::tolower(c); });
240+
const auto UUID = dev.get_info<sycl::ext::intel::info::device::uuid>();
244241

245-
// From all physical devices, find the first one that supports all our
246-
// required device extensions.
242+
// From all physical devices, find the first one with a matching UUID
243+
// that also supports all our required device extensions
247244
for (int i = 0; i < physicalDeviceCount; i++) {
248245
vk_physical_device = physicalDevices[i];
249-
VkPhysicalDeviceProperties props;
250-
vkGetPhysicalDeviceProperties(vk_physical_device, &props);
251-
std::string name(props.deviceName);
252246

253-
// Make lowercase for comparision.
254-
std::transform(name.begin(), name.end(), name.begin(),
255-
[](unsigned char c) { return std::tolower(c); });
247+
VkPhysicalDeviceIDProperties devIDProps = {
248+
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES};
256249

257-
if (name.find(device) == std::string::npos) {
250+
VkPhysicalDeviceProperties2 devProps2 = {
251+
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
252+
.pNext = &devIDProps};
253+
254+
vkGetPhysicalDeviceProperties2(vk_physical_device, &devProps2);
255+
256+
if (!std::equal(std::begin(UUID), std::end(UUID),
257+
std::begin(devIDProps.deviceUUID),
258+
std::begin(devIDProps.deviceUUID) + VK_UUID_SIZE)) {
258259
continue;
259260
}
260261

@@ -275,8 +276,8 @@ VkResult setupDevice(std::string device) {
275276
}
276277

277278
foundDevice = true;
278-
std::cout << "Found suitable Vulkan device: " << props.deviceName
279-
<< std::endl;
279+
std::cout << "Found suitable Vulkan device: "
280+
<< devProps2.properties.deviceName << std::endl;
280281
break;
281282
}
282283

0 commit comments

Comments
 (0)