Skip to content

Commit

Permalink
[urinfo] Fix printing of device UUID
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kbenzie committed Apr 22, 2024
1 parent 717791b commit bf491bb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ typedef enum ur_device_info_t {
///< shared memory access
UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT = 87, ///< [::ur_device_usm_access_capability_flags_t] support USM system wide
///< shared memory access
UR_DEVICE_INFO_UUID = 88, ///< [char[]] return device UUID
UR_DEVICE_INFO_UUID = 88, ///< [uint8_t[]] return device UUID
UR_DEVICE_INFO_PCI_ADDRESS = 89, ///< [char[]] return device PCI address
UR_DEVICE_INFO_GPU_EU_COUNT = 90, ///< [uint32_t] return Intel GPU EU count
UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH = 91, ///< [uint32_t] return Intel GPU EU SIMD width
Expand Down
13 changes: 11 additions & 2 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3596,8 +3596,17 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info
} break;
case UR_DEVICE_INFO_UUID: {

const char *tptr = (const char *)ptr;
printPtr(os, tptr);
const uint8_t *tptr = (const uint8_t *)ptr;
os << "{";
size_t nelems = size / sizeof(uint8_t);
for (size_t i = 0; i < nelems; ++i) {
if (i != 0) {
os << ", ";
}

os << tptr[i];
}
os << "}";
} break;
case UR_DEVICE_INFO_PCI_ADDRESS: {

Expand Down
2 changes: 1 addition & 1 deletion scripts/core/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ etors:
- name: USM_SYSTEM_SHARED_SUPPORT
desc: "[$x_device_usm_access_capability_flags_t] support USM system wide shared memory access"
- name: UUID
desc: "[char[]] return device UUID"
desc: "[uint8_t[]] return device UUID"
- name: PCI_ADDRESS
desc: "[char[]] return device PCI address"
- name: GPU_EU_COUNT
Expand Down
4 changes: 4 additions & 0 deletions scripts/templates/tools-info.hpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ inline void printPlatformInfos(${x}_platform_handle_t hPlatform, std::string_vie
inline void printDeviceInfos(${x}_device_handle_t hDevice, std::string_view prefix = " ") {
%for etor in obj['etors']:
std::cout << prefix;
%if etor['name'] == '$X_DEVICE_INFO_UUID':
printDeviceUUID(hDevice, ${etor['name'].replace('$X', X)});
%else:
printDeviceInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hDevice, ${etor['name'].replace('$X', X)});
%endif
%endfor
}
%endif
Expand Down
2 changes: 1 addition & 1 deletion tools/urinfo/urinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ inline void printDeviceInfos(ur_device_handle_t hDevice,
printDeviceInfo<ur_device_usm_access_capability_flags_t>(
hDevice, UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT);
std::cout << prefix;
printDeviceInfo<char[]>(hDevice, UR_DEVICE_INFO_UUID);
printDeviceUUID(hDevice, UR_DEVICE_INFO_UUID);
std::cout << prefix;
printDeviceInfo<char[]>(hDevice, UR_DEVICE_INFO_PCI_ADDRESS);
std::cout << prefix;
Expand Down
15 changes: 15 additions & 0 deletions tools/urinfo/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,19 @@ inline void printDeviceInfo<char[]>(ur_device_handle_t device,
str.pop_back(); // std::string does not need a terminating NULL, remove it here
std::cout << str << "\n";
}

inline void printDeviceUUID(ur_device_handle_t device, ur_device_info_t info) {
std::cout << getDeviceInfoName(info) << ": ";
size_t size;
UR_CHECK_WEAK(urDeviceGetInfo(device, info, 0, nullptr, &size));
std::vector<uint8_t> values(size / sizeof(uint8_t));
UR_CHECK_WEAK(urDeviceGetInfo(device, info, size, values.data(), nullptr));
for (size_t i = 0; i < values.size(); i++) {
if (i == 4 || i == 6 || i == 8 || i == 10) {
std::printf("-");
}
std::printf("%.2x", (uint32_t)values[i]);
}
std::printf("\n");
}
} // namespace urinfo

0 comments on commit bf491bb

Please sign in to comment.