Skip to content

Commit bf491bb

Browse files
committed
[urinfo] Fix printing of device UUID
* Change the type returned by the `UR_DEVICE_INFO_UUID` query to `uint8_t` to match the type returned from Level Zero, CUDA, & HIP. * Modify template to emit call to `printDeviceUUID()` instead of generic info printer to special case output formatting. * Add `printDeviceUUID()` to print the device UUID in a human friendly format.
1 parent 717791b commit bf491bb

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ typedef enum ur_device_info_t {
15461546
///< shared memory access
15471547
UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT = 87, ///< [::ur_device_usm_access_capability_flags_t] support USM system wide
15481548
///< shared memory access
1549-
UR_DEVICE_INFO_UUID = 88, ///< [char[]] return device UUID
1549+
UR_DEVICE_INFO_UUID = 88, ///< [uint8_t[]] return device UUID
15501550
UR_DEVICE_INFO_PCI_ADDRESS = 89, ///< [char[]] return device PCI address
15511551
UR_DEVICE_INFO_GPU_EU_COUNT = 90, ///< [uint32_t] return Intel GPU EU count
15521552
UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH = 91, ///< [uint32_t] return Intel GPU EU SIMD width

include/ur_print.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,8 +3596,17 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info
35963596
} break;
35973597
case UR_DEVICE_INFO_UUID: {
35983598

3599-
const char *tptr = (const char *)ptr;
3600-
printPtr(os, tptr);
3599+
const uint8_t *tptr = (const uint8_t *)ptr;
3600+
os << "{";
3601+
size_t nelems = size / sizeof(uint8_t);
3602+
for (size_t i = 0; i < nelems; ++i) {
3603+
if (i != 0) {
3604+
os << ", ";
3605+
}
3606+
3607+
os << tptr[i];
3608+
}
3609+
os << "}";
36013610
} break;
36023611
case UR_DEVICE_INFO_PCI_ADDRESS: {
36033612

scripts/core/device.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ etors:
377377
- name: USM_SYSTEM_SHARED_SUPPORT
378378
desc: "[$x_device_usm_access_capability_flags_t] support USM system wide shared memory access"
379379
- name: UUID
380-
desc: "[char[]] return device UUID"
380+
desc: "[uint8_t[]] return device UUID"
381381
- name: PCI_ADDRESS
382382
desc: "[char[]] return device PCI address"
383383
- name: GPU_EU_COUNT

scripts/templates/tools-info.hpp.mako

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ inline void printPlatformInfos(${x}_platform_handle_t hPlatform, std::string_vie
6262
inline void printDeviceInfos(${x}_device_handle_t hDevice, std::string_view prefix = " ") {
6363
%for etor in obj['etors']:
6464
std::cout << prefix;
65+
%if etor['name'] == '$X_DEVICE_INFO_UUID':
66+
printDeviceUUID(hDevice, ${etor['name'].replace('$X', X)});
67+
%else:
6568
printDeviceInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hDevice, ${etor['name'].replace('$X', X)});
69+
%endif
6670
%endfor
6771
}
6872
%endif

tools/urinfo/urinfo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ inline void printDeviceInfos(ur_device_handle_t hDevice,
258258
printDeviceInfo<ur_device_usm_access_capability_flags_t>(
259259
hDevice, UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT);
260260
std::cout << prefix;
261-
printDeviceInfo<char[]>(hDevice, UR_DEVICE_INFO_UUID);
261+
printDeviceUUID(hDevice, UR_DEVICE_INFO_UUID);
262262
std::cout << prefix;
263263
printDeviceInfo<char[]>(hDevice, UR_DEVICE_INFO_PCI_ADDRESS);
264264
std::cout << prefix;

tools/urinfo/utils.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,19 @@ inline void printDeviceInfo<char[]>(ur_device_handle_t device,
244244
str.pop_back(); // std::string does not need a terminating NULL, remove it here
245245
std::cout << str << "\n";
246246
}
247+
248+
inline void printDeviceUUID(ur_device_handle_t device, ur_device_info_t info) {
249+
std::cout << getDeviceInfoName(info) << ": ";
250+
size_t size;
251+
UR_CHECK_WEAK(urDeviceGetInfo(device, info, 0, nullptr, &size));
252+
std::vector<uint8_t> values(size / sizeof(uint8_t));
253+
UR_CHECK_WEAK(urDeviceGetInfo(device, info, size, values.data(), nullptr));
254+
for (size_t i = 0; i < values.size(); i++) {
255+
if (i == 4 || i == 6 || i == 8 || i == 10) {
256+
std::printf("-");
257+
}
258+
std::printf("%.2x", (uint32_t)values[i]);
259+
}
260+
std::printf("\n");
261+
}
247262
} // namespace urinfo

0 commit comments

Comments
 (0)