From bf491bb833a59a8deda99947455ec385870f6cbd Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 11 Jan 2024 15:26:34 +0000 Subject: [PATCH 1/2] [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. --- include/ur_api.h | 2 +- include/ur_print.hpp | 13 +++++++++++-- scripts/core/device.yml | 2 +- scripts/templates/tools-info.hpp.mako | 4 ++++ tools/urinfo/urinfo.hpp | 2 +- tools/urinfo/utils.hpp | 15 +++++++++++++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/ur_api.h b/include/ur_api.h index 7f59e15f6e..d4ea8d3404 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -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 diff --git a/include/ur_print.hpp b/include/ur_print.hpp index 07df5a1874..d770cf2a45 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -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: { diff --git a/scripts/core/device.yml b/scripts/core/device.yml index 8acdfafed5..f1861731d3 100644 --- a/scripts/core/device.yml +++ b/scripts/core/device.yml @@ -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 diff --git a/scripts/templates/tools-info.hpp.mako b/scripts/templates/tools-info.hpp.mako index 44f328fbd4..ed9d67bb34 100644 --- a/scripts/templates/tools-info.hpp.mako +++ b/scripts/templates/tools-info.hpp.mako @@ -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 diff --git a/tools/urinfo/urinfo.hpp b/tools/urinfo/urinfo.hpp index 9745eed6cb..111726f6cc 100644 --- a/tools/urinfo/urinfo.hpp +++ b/tools/urinfo/urinfo.hpp @@ -258,7 +258,7 @@ inline void printDeviceInfos(ur_device_handle_t hDevice, printDeviceInfo( hDevice, UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT); std::cout << prefix; - printDeviceInfo(hDevice, UR_DEVICE_INFO_UUID); + printDeviceUUID(hDevice, UR_DEVICE_INFO_UUID); std::cout << prefix; printDeviceInfo(hDevice, UR_DEVICE_INFO_PCI_ADDRESS); std::cout << prefix; diff --git a/tools/urinfo/utils.hpp b/tools/urinfo/utils.hpp index a66b1de657..d7819b2947 100644 --- a/tools/urinfo/utils.hpp +++ b/tools/urinfo/utils.hpp @@ -244,4 +244,19 @@ inline void printDeviceInfo(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 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 From 6a60213407643c134aa0976ce0b4f08f51818fc4 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 23 Jan 2024 15:50:17 +0000 Subject: [PATCH 2/2] [CL] Implement UR_DEVICE_INFO_UUID query Check if the OpenCL device supports the `cl_khr_device_uuid` extension. If it is supported, use it to implement the `UR_DEVICE_INFO_UUID` query. Otherwise, continue to return `UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION`. --- source/adapters/opencl/device.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/source/adapters/opencl/device.cpp b/source/adapters/opencl/device.cpp index 229c2429a3..52671e6b01 100644 --- a/source/adapters/opencl/device.cpp +++ b/source/adapters/opencl/device.cpp @@ -10,6 +10,7 @@ #include "common.hpp" #include "platform.hpp" +#include #include ur_result_t cl_adapter::getDeviceVersion(cl_device_id Dev, @@ -941,6 +942,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } return ReturnValue(SupportedExtensions.c_str()); } + + case UR_DEVICE_INFO_UUID: { + // Use the cl_khr_device_uuid extension, if available. + bool isKhrDeviceUuidSupported = false; + if (cl_adapter::checkDeviceExtensions( + cl_adapter::cast(hDevice), {"cl_khr_device_uuid"}, + isKhrDeviceUuidSupported) != UR_RESULT_SUCCESS || + !isKhrDeviceUuidSupported) { + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; + } + static_assert(CL_UUID_SIZE_KHR == 16); + std::array UUID{}; + CL_RETURN_ON_FAILURE( + clGetDeviceInfo(cl_adapter::cast(hDevice), + CL_DEVICE_UUID_KHR, UUID.size(), UUID.data(), nullptr)); + return ReturnValue(UUID); + } + case UR_DEVICE_INFO_COMPONENT_DEVICES: case UR_DEVICE_INFO_COMPOSITE_DEVICE: // These two are exclusive of L0. @@ -957,10 +976,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE: case UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU: case UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH: - /* TODO: Check if device UUID extension is enabled in OpenCL. For details - * about Intel UUID extension, see - * sycl/doc/extensions/supported/sycl_ext_intel_device_info.md */ - case UR_DEVICE_INFO_UUID: /* This enums have no equivalent in OpenCL */ case UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP: case UR_DEVICE_INFO_GLOBAL_MEM_FREE: