Skip to content

Commit b0df1a9

Browse files
DBDuncankbenzie
authored andcommitted
Add support for getting device LUID on windows (#19349)
Adds a new aspect to get device LUID. This feature is only available on Windows and allows for device matching when performing SYCL/DirectX interop
1 parent 1b0d70e commit b0df1a9

File tree

10 files changed

+187
-0
lines changed

10 files changed

+187
-0
lines changed

include/ur_api.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/ur_print.hpp

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/core/device.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ etors:
464464
desc: "[$x_bool_t] support for native bfloat16 conversions"
465465
- name: KERNEL_LAUNCH_CAPABILITIES
466466
desc: "[$x_kernel_launch_properties_flags_t] Bitfield of supported kernel launch properties."
467+
- name: LUID
468+
desc: "[uint8_t[]][optional-query] return device Windows LUID"
469+
- name: NODE_MASK
470+
desc: "[uint32_t][optional-query] return device Windows node mask"
467471
--- #--------------------------------------------------------------------------
468472
type: function
469473
desc: "Retrieves various information about device"

source/adapters/cuda/device.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,44 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11861186

11871187
return ReturnValue(0);
11881188
}
1189+
case UR_DEVICE_INFO_LUID: {
1190+
// LUID is only available on Windows.
1191+
// Intel extension for device LUID. This returns the LUID as
1192+
// std::array<std::byte, 8>. For details about this extension,
1193+
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1194+
std::array<char, 8> LUID{};
1195+
cuDeviceGetLuid(LUID.data(), nullptr, hDevice->get());
1196+
1197+
bool isAllZeros = true;
1198+
for (char num : LUID) {
1199+
if (num != 0) {
1200+
isAllZeros = false;
1201+
}
1202+
}
1203+
1204+
if (isAllZeros) {
1205+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1206+
}
1207+
1208+
std::array<unsigned char, 8> Name{};
1209+
std::copy(LUID.begin(), LUID.end(), Name.begin());
1210+
return ReturnValue(Name.data(), 8);
1211+
}
1212+
case UR_DEVICE_INFO_NODE_MASK: {
1213+
// Device node mask is only available on Windows.
1214+
// Intel extension for device node mask. This returns the node mask as
1215+
// uint32_t. For details about this extension,
1216+
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1217+
uint32_t nodeMask = 0;
1218+
cuDeviceGetLuid(nullptr, &nodeMask, hDevice->get());
1219+
1220+
// If nodeMask has not changed, return unsupported.
1221+
if (nodeMask == 0) {
1222+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1223+
}
1224+
1225+
return ReturnValue(nodeMask);
1226+
}
11891227
default:
11901228
break;
11911229
}

source/adapters/level_zero/device.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,48 @@ ur_result_t urDeviceGetInfo(
13811381
}
13821382
case UR_DEVICE_INFO_KERNEL_LAUNCH_CAPABILITIES:
13831383
return ReturnValue(UR_KERNEL_LAUNCH_PROPERTIES_FLAG_COOPERATIVE);
1384+
case UR_DEVICE_INFO_LUID: {
1385+
// LUID is only available on Windows.
1386+
// Intel extension for device LUID. This returns the LUID as
1387+
// std::array<std::byte, 8>. For details about this extension,
1388+
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1389+
if (Device->Platform->ZeLUIDSupported) {
1390+
ze_device_properties_t DeviceProp = {};
1391+
DeviceProp.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
1392+
ze_device_luid_ext_properties_t LuidDesc = {};
1393+
LuidDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
1394+
DeviceProp.pNext = (void *)&LuidDesc;
1395+
1396+
ZE2UR_CALL(zeDeviceGetProperties, (ZeDevice, &DeviceProp));
1397+
1398+
const auto &LUID = LuidDesc.luid.id;
1399+
return ReturnValue(LUID, sizeof(LUID));
1400+
} else {
1401+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1402+
}
1403+
}
1404+
case UR_DEVICE_INFO_NODE_MASK: {
1405+
// Device node mask is only available on Windows.
1406+
// Intel extension for device node mask. This returns the node mask as
1407+
// uint32_t. For details about this extension,
1408+
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1409+
1410+
// Node mask is provided through the L0 LUID extension so support for this
1411+
// extension must be checked.
1412+
if (Device->Platform->ZeLUIDSupported) {
1413+
ze_device_properties_t DeviceProp = {};
1414+
DeviceProp.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
1415+
ze_device_luid_ext_properties_t LuidDesc = {};
1416+
LuidDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
1417+
DeviceProp.pNext = (void *)&LuidDesc;
1418+
1419+
ZE2UR_CALL(zeDeviceGetProperties, (ZeDevice, &DeviceProp));
1420+
1421+
return ReturnValue(LuidDesc.nodeMask);
1422+
} else {
1423+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1424+
}
1425+
}
13841426
default:
13851427
UR_LOG(ERR, "Unsupported ParamName in urGetDeviceInfo");
13861428
UR_LOG(ERR, "ParamNameParamName={}(0x{})", ParamName,

source/adapters/level_zero/platform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ ur_result_t ur_platform_handle_t_::initialize() {
295295
ZeBindlessImagesExtensionSupported = true;
296296
}
297297
}
298+
if (strncmp(extension.name, ZE_DEVICE_LUID_EXT_NAME,
299+
strlen(ZE_DEVICE_LUID_EXT_NAME) + 1) == 0) {
300+
if (extension.version == ZE_DEVICE_LUID_EXT_VERSION_1_0) {
301+
ZeLUIDSupported = true;
302+
}
303+
}
298304
zeDriverExtensionMap[extension.name] = extension.version;
299305
}
300306

source/adapters/level_zero/platform.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct ur_platform_handle_t_ : ur::handle_base<ur::level_zero::ddi_getter>,
6969
bool ZeDriverEuCountExtensionFound{false};
7070
bool ZeCopyOffloadExtensionSupported{false};
7171
bool ZeBindlessImagesExtensionSupported{false};
72+
bool ZeLUIDSupported{false};
7273

7374
// Cache UR devices for reuse
7475
std::vector<std::unique_ptr<ur_device_handle_t_>> URDevicesCache;

source/adapters/opencl/device.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,59 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
14181418
return ReturnValue(true);
14191419
case UR_DEVICE_INFO_KERNEL_LAUNCH_CAPABILITIES:
14201420
return ReturnValue(0);
1421+
case UR_DEVICE_INFO_LUID: {
1422+
// LUID is only available on Windows.
1423+
// Intel extension for device LUID. This returns the LUID as
1424+
// std::array<std::byte, 8>. For details about this extension,
1425+
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1426+
1427+
// Use the cl_khr_device_uuid extension, if available.
1428+
bool isKhrDeviceLuidSupported = false;
1429+
if (hDevice->checkDeviceExtensions({"cl_khr_device_uuid"},
1430+
isKhrDeviceLuidSupported) !=
1431+
UR_RESULT_SUCCESS ||
1432+
!isKhrDeviceLuidSupported) {
1433+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
1434+
}
1435+
1436+
cl_bool isLuidValid;
1437+
CL_RETURN_ON_FAILURE(
1438+
clGetDeviceInfo(hDevice->CLDevice, CL_DEVICE_LUID_VALID_KHR,
1439+
sizeof(cl_bool), &isLuidValid, nullptr));
1440+
1441+
if (!isLuidValid) {
1442+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
1443+
}
1444+
1445+
static_assert(CL_LUID_SIZE_KHR == 8);
1446+
std::array<unsigned char, CL_LUID_SIZE_KHR> UUID{};
1447+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(hDevice->CLDevice, CL_DEVICE_LUID_KHR,
1448+
UUID.size(), UUID.data(), nullptr));
1449+
return ReturnValue(UUID);
1450+
}
1451+
case UR_DEVICE_INFO_NODE_MASK: {
1452+
// Device node mask is only available on Windows.
1453+
// Intel extension for device node mask. This returns the node mask as
1454+
// uint32_t. For details about this extension,
1455+
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1456+
1457+
// Use the cl_khr_device_uuid extension, if available.
1458+
bool isKhrDeviceLuidSupported = false;
1459+
if (hDevice->checkDeviceExtensions({"cl_khr_device_uuid"},
1460+
isKhrDeviceLuidSupported) !=
1461+
UR_RESULT_SUCCESS ||
1462+
!isKhrDeviceLuidSupported) {
1463+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
1464+
}
1465+
1466+
cl_int nodeMask = 0;
1467+
1468+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(hDevice->CLDevice,
1469+
CL_DEVICE_NODE_MASK_KHR,
1470+
sizeof(cl_int), &nodeMask, nullptr));
1471+
1472+
return ReturnValue(nodeMask);
1473+
}
14211474
// TODO: We can't query to check if these are supported, they will need to be
14221475
// manually updated if support is ever implemented.
14231476
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:

test/conformance/testing/include/uur/optional_queries.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/urinfo/urinfo.hpp

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)