Skip to content

Commit f80661e

Browse files
authored
[SYCL] Format UUID in sycl-ls (#18561)
This patch formats the UUID device info as a standard UUID string when displaying verbose output in `sycl-ls`. Currently the device UUID is printed as 16 numbers. This makes it difficult to compare the UUID across drivers, for example this is relevant for Vulkan interop.
1 parent efee051 commit f80661e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

sycl/tools/sycl-ls/sycl-ls.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include <sycl/sycl.hpp>
2020

2121
#include <cstdlib>
22+
#include <iomanip>
2223
#include <iostream>
2324
#include <map>
24-
#include <stdlib.h>
25+
#include <sstream>
2526
#include <string>
2627
#include <vector>
2728

@@ -126,6 +127,25 @@ std::array<int, 2> GetNumberOfSubAndSubSubDevices(const device &Device) {
126127
return {NumSubDevices, NumSubDevices * NumSubSubDevices};
127128
}
128129

130+
/// Standard formatting of UUID numbers into a string
131+
/// e.g. "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
132+
std::string formatUUID(detail::uuid_type UUID) {
133+
std::ostringstream oss;
134+
// Avoid locale issues with numbers
135+
oss.imbue(std::locale::classic());
136+
oss << std::hex << std::setfill('0');
137+
138+
assert((std::size(UUID) == 16) && "Invalid UUID length");
139+
for (int i = 0u; i < 16; ++i) {
140+
if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) {
141+
oss << "-";
142+
}
143+
oss << std::setw(2) << static_cast<int>(UUID[i]);
144+
}
145+
146+
return oss.str();
147+
}
148+
129149
static void printDeviceInfo(const device &Device, bool Verbose,
130150
const std::string &Prepend) {
131151
auto DeviceVersion = Device.get_info<info::device::version>();
@@ -146,11 +166,8 @@ static void printDeviceInfo(const device &Device, bool Verbose,
146166
// Get and print device UUID, if it is available.
147167
if (Device.has(aspect::ext_intel_device_info_uuid)) {
148168
auto UUID = Device.get_info<sycl::ext::intel::info::device::uuid>();
149-
std::cout << Prepend << "UUID : ";
150-
for (int i = 0; i < 16; i++) {
151-
std::cout << std::to_string(UUID[i]);
152-
}
153-
std::cout << std::endl;
169+
std::cout << Prepend << "UUID : " << formatUUID(UUID)
170+
<< std::endl;
154171
}
155172

156173
// Get and print device ID, if it is available.

0 commit comments

Comments
 (0)