Skip to content

Commit 3d4f15b

Browse files
committed
Add support for luid and node mask in opencl backend and tests
1 parent 88a4dd3 commit 3d4f15b

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// REQUIRES: aspect-ext_intel_device_info_luid
2+
// REQUIRES: gpu, opencl, windows
3+
4+
// RUN: %{build} -o %t.out %opencl_lib
5+
// RUN: %{run} %t.out
6+
7+
// Test that the LUID is read correctly from OpenCL.
8+
9+
#include <iomanip>
10+
#include <iostream>
11+
#include <sstream>
12+
#include <sycl/backend.hpp>
13+
#include <sycl/detail/core.hpp>
14+
15+
int main() {
16+
sycl::device dev;
17+
auto luid = dev.get_info<sycl::ext::intel::info::device::luid>();
18+
19+
std::stringstream luidSYCLHex;
20+
for (int i = 0; i < luid.size(); ++i) {
21+
luidSYCLHex << std::hex << std::setw(2) << std::setfill('0')
22+
<< int(luid[i]);
23+
}
24+
std::cout << "SYCL: " << luidSYCLHex.str() << std::endl;
25+
26+
auto openclDevice = sycl::get_native<sycl::backend::opencl>(dev);
27+
28+
char *luidOpencl = nullptr;
29+
30+
clGetDeviceInfo(openclDevice, CL_DEVICE_LUID_KHR,
31+
sizeof(char) * CL_LUID_SIZE_KHR, luidOpencl, nullptr);
32+
33+
std::stringstream luidOpenclHex;
34+
for (int i = 0; i < 8; ++i)
35+
luidOpenclHex << std::hex << std::setw(2) << std::setfill('0')
36+
<< int(luidOpencl[i]);
37+
std::cout << "OpenCL : " << luidOpenclHex.str() << std::endl;
38+
39+
if (luidSYCLHex.str() != luidOpenclHex.str()) {
40+
std::cout << "FAILED" << std::endl;
41+
return -1;
42+
}
43+
44+
std::cout << "PASSED" << std::endl;
45+
return 0;
46+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// REQUIRES: aspect-ext_intel_device_info_node_mask
2+
// REQUIRES: gpu, opencl, windows
3+
4+
// RUN: %{build} -o %t.out %opencl_lib
5+
// RUN: %{run} %t.out
6+
7+
// Test that the node mask is read correctly from OpenCL.
8+
9+
#include <iomanip>
10+
#include <iostream>
11+
#include <sstream>
12+
#include <sycl/backend.hpp>
13+
#include <sycl/detail/core.hpp>
14+
15+
int main() {
16+
sycl::device dev;
17+
auto nodeMaskSYCL = dev.get_info<sycl::ext::intel::info::device::node_mask>();
18+
19+
std::cout << "SYCL: " << nodeMaskSYCL << std::endl;
20+
21+
auto openclDevice = sycl::get_native<sycl::backend::opencl>(dev);
22+
23+
uint32_t *nodeMaskOpencl = nullptr;
24+
25+
clGetDeviceInfo(openclDevice, CL_DEVICE_NODE_MASK_KHR,
26+
sizeof(uint32_t), nodeMaskOpencl, nullptr);
27+
28+
std::cout << "OpenCL : " << *nodeMaskOpencl << std::endl;
29+
30+
if (nodeMaskSYCL != *nodeMaskOpencl) {
31+
std::cout << "FAILED" << std::endl;
32+
return -1;
33+
}
34+
35+
std::cout << "PASSED" << std::endl;
36+
return 0;
37+
}

unified-runtime/source/adapters/opencl/device.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,63 @@ 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_FEATURE;
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 = nullptr;
1467+
1468+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(hDevice->CLDevice,
1469+
CL_DEVICE_NODE_MASK_KHR,
1470+
sizeof(cl_int), nodeMask, nullptr));
1471+
1472+
if (nodeMask == nullptr) {
1473+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1474+
}
1475+
1476+
return ReturnValue(*nodeMask);
1477+
}
14211478
// TODO: We can't query to check if these are supported, they will need to be
14221479
// manually updated if support is ever implemented.
14231480
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS:

0 commit comments

Comments
 (0)