Skip to content

Commit b49a6c6

Browse files
committed
[SYCL] Add support for getting device LUID on windows
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 8aee753 commit b49a6c6

File tree

19 files changed

+176
-2
lines changed

19 files changed

+176
-2
lines changed

llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def AspectExt_intel_current_clock_throttle_reasons : Aspect<"ext_intel_current_c
9292
def AspectExt_intel_fan_speed : Aspect<"ext_intel_fan_speed">;
9393
def AspectExt_intel_power_limits : Aspect<"ext_intel_power_limits">;
9494
def AspectExt_oneapi_async_memory_alloc : Aspect<"ext_oneapi_async_memory_alloc">;
95+
def AspectExt_intel_device_info_luid : Aspect<"ext_intel_device_info_luid">;
9596

9697
// Deprecated aspects
9798
def AspectInt64_base_atomics : Aspect<"int64_base_atomics">;
@@ -163,7 +164,8 @@ def : TargetInfo<"__TestAspectList",
163164
AspectExt_intel_current_clock_throttle_reasons,
164165
AspectExt_intel_fan_speed,
165166
AspectExt_intel_power_limits,
166-
AspectExt_oneapi_async_memory_alloc],
167+
AspectExt_oneapi_async_memory_alloc,
168+
AspectExt_intel_device_info_luid],
167169
[]>;
168170
// This definition serves the only purpose of testing whether the deprecated aspect list defined in here and in SYCL RT
169171
// match.

sycl/doc/extensions/supported/sycl_ext_intel_device_info.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The Feature Test Macro SYCL\_EXT\_INTEL\_DEVICE\_INFO will be defined as one of
2020
| 5 | Device ID is supported |
2121
| 6 | Memory clock rate and bus width queries are supported |
2222
| 7 | Throttle reasons, fan speed and power limits queries are supported |
23+
| 8 | Device LUID is supported |
2324

2425

2526

@@ -626,7 +627,35 @@ Then the power limits can be obtained using the standard `get_info()` interface.
626627
```
627628

628629

630+
# Device LUID #
629631

632+
A new device descriptor is added which will provide the device Locally Unique ID (LUID).
633+
634+
## Version ##
635+
636+
The extension supports this query in version 8 and later.
637+
638+
| Device Descriptors | Return Type | Description |
639+
| ------------------ | ----------- | ----------- |
640+
|`ext::intel::info::device::luid` |`std::array<unsigned char, 8>` | Returns the device LUID. |
641+
642+
## Aspects ##
643+
644+
A new aspect, `ext_intel_device_info_luid`, is added.
645+
646+
## Error Condition ##
647+
648+
Throws a synchronous `exception` with the `errc::feature_not_supported` error code if the device does not have `aspect::ext_intel_device_info_luid`.
649+
650+
## Example Usage ##
651+
652+
The LUID can be obtained using the standard `get_info()` interface.
653+
654+
```
655+
if (dev.has(aspect::ext_intel_device_info_luid)) {
656+
auto LUID = dev.get_info<ext::intel::info::device::luid>();
657+
}
658+
```
630659

631660
# Deprecated queries #
632661

sycl/include/sycl/detail/type_traits.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ inline constexpr bool is_group_helper_v =
110110
} // namespace ext::oneapi::experimental
111111

112112
namespace detail {
113-
// Type for Intel device UUID extension.
113+
// Types for Intel's device UUID and device LUID extension.
114114
// For details about this extension, see
115115
// sycl/doc/extensions/supported/sycl_ext_intel_device_info.md
116116
using uuid_type = std::array<unsigned char, 16>;
117+
using luid_type = std::array<unsigned char, 8>;
117118

118119
template <typename T, typename R> struct copy_cv_qualifiers;
119120

sycl/include/sycl/info/aspects.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ __SYCL_ASPECT(ext_intel_current_clock_throttle_reasons, 84)
7878
__SYCL_ASPECT(ext_intel_fan_speed, 85)
7979
__SYCL_ASPECT(ext_intel_power_limits, 86)
8080
__SYCL_ASPECT(ext_oneapi_async_memory_alloc, 87)
81+
__SYCL_ASPECT(ext_intel_device_info_luid, 88)
8182

sycl/include/sycl/info/device_traits.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ __SYCL_PARAM_TRAITS_SPEC(device, ext_oneapi_max_work_groups_3d, id<3>,
237237
__SYCL_PARAM_TRAITS_SPEC(device, ext_oneapi_max_global_work_groups, size_t, __SYCL_TRAIT_HANDLED_IN_RT)
238238
__SYCL_PARAM_TRAITS_SPEC(device, ext_oneapi_cuda_cluster_group, bool, __SYCL_TRAIT_HANDLED_IN_RT)
239239

240+
__SYCL_PARAM_TRAITS_SPEC(device, ext_intel_device_info_luid, detail::luid_type,
241+
UR_DEVICE_INFO_LUID)
242+
240243
#ifdef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF
241244
#undef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC
242245
#undef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF

sycl/include/sycl/info/ext_intel_device_traits.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ __SYCL_PARAM_TRAITS_SPEC(ext::intel, device, current_clock_throttle_reasons, std
2121
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, fan_speed, int32_t, UR_DEVICE_INFO_FAN_SPEED)
2222
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, min_power_limit, int32_t, UR_DEVICE_INFO_MIN_POWER_LIMIT)
2323
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, max_power_limit, int32_t, UR_DEVICE_INFO_MAX_POWER_LIMIT)
24+
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, luid, detail::luid_type, UR_DEVICE_INFO_LUID)
2425
#ifdef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF
2526
#undef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC
2627
#undef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF

sycl/source/detail/device_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ EXPORT_GET_INFO(ext::intel::info::device::current_clock_throttle_reasons)
510510
EXPORT_GET_INFO(ext::intel::info::device::fan_speed)
511511
EXPORT_GET_INFO(ext::intel::info::device::min_power_limit)
512512
EXPORT_GET_INFO(ext::intel::info::device::max_power_limit)
513+
EXPORT_GET_INFO(ext::intel::info::device::luid)
513514

514515
EXPORT_GET_INFO(ext::codeplay::experimental::info::device::supports_fusion)
515516
EXPORT_GET_INFO(ext::codeplay::experimental::info::device::max_registers_per_work_group)

sycl/source/detail/device_impl.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,15 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
11951195
"The device does not have the ext_intel_power_limits aspect");
11961196
return get_info_impl<UR_DEVICE_INFO_MIN_POWER_LIMIT>();
11971197
}
1198+
CASE(ext::intel::info::device::luid) {
1199+
if (!has(aspect::ext_intel_device_info_luid))
1200+
throw exception(
1201+
make_error_code(errc::feature_not_supported),
1202+
"The device does not have the ext_intel_device_info_luid aspect");
1203+
// TODO: we're essentially memcpy'ing here...
1204+
static_assert(std::is_same_v<luid_type, std::array<unsigned char, 8>>);
1205+
return get_info_impl<UR_DEVICE_INFO_LUID>();
1206+
}
11981207
else {
11991208
constexpr auto Desc = UrInfoCode<Param>::value;
12001209
return static_cast<typename Param::return_type>(get_info_impl<Desc>());
@@ -1305,6 +1314,9 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
13051314
CASE(ext_intel_device_info_uuid) {
13061315
return has_info_desc(UR_DEVICE_INFO_UUID);
13071316
}
1317+
CASE(ext_intel_device_info_luid) {
1318+
return has_info_desc(UR_DEVICE_INFO_LUID);
1319+
}
13081320
CASE(ext_intel_max_mem_bandwidth) {
13091321
// currently not supported
13101322
return false;
@@ -2313,6 +2325,7 @@ EXPORT_GET_INFO(ext::intel::info::device::current_clock_throttle_reasons)
23132325
EXPORT_GET_INFO(ext::intel::info::device::fan_speed)
23142326
EXPORT_GET_INFO(ext::intel::info::device::min_power_limit)
23152327
EXPORT_GET_INFO(ext::intel::info::device::max_power_limit)
2328+
EXPORT_GET_INFO(ext::intel::info::device::luid)
23162329

23172330
EXPORT_GET_INFO(ext::codeplay::experimental::info::device::supports_fusion)
23182331
EXPORT_GET_INFO(ext::codeplay::experimental::info::device::max_registers_per_work_group)

sycl/source/detail/ur_device_info_ret_types.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ MAP(UR_DEVICE_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES, ur_memory_order_capability_
129129
MAP(UR_DEVICE_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES, ur_memory_scope_capability_flags_t)
130130
MAP(UR_DEVICE_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES, ur_memory_order_capability_flags_t)
131131
MAP(UR_DEVICE_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES, ur_memory_scope_capability_flags_t)
132+
MAP(UR_DEVICE_INFO_LUID, std::array<uint8_t, 8>)
132133
// Deprecated, we're not using it, so comment out to avoid warnings:
133134
// MAP(UR_DEVICE_INFO_BFLOAT16, ur_bool_t)
134135
MAP(UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES, uint32_t)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// REQUIRES: aspect-ext_intel_device_info_luid
2+
// REQUIRES: gpu, level_zero, level_zero_dev_kit, windows
3+
4+
// RUN: %{build} %level_zero_options -o %t.out
5+
// RUN: %{run} %t.out 2>&1 | FileCheck %s
6+
7+
// Test that the LUID is read correctly from Level Zero.
8+
9+
// CHECK: PASSED
10+
#include <iomanip>
11+
#include <iostream>
12+
#include <level_zero/ze_api.h>
13+
#include <sstream>
14+
#include <sycl/backend.hpp>
15+
#include <sycl/detail/core.hpp>
16+
17+
int main() {
18+
sycl::device dev;
19+
auto luid = dev.get_info<sycl::ext::intel::info::device::luid>();
20+
21+
std::stringstream luid_sycl;
22+
for (int i = 0; i < luid.size(); ++i) {
23+
luid_sycl << std::hex << std::setw(2) << std::setfill('0') << int(luid[i]);
24+
}
25+
std::cout << "SYCL: " << luid_sycl.str() << std::endl;
26+
27+
auto zedev = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(dev);
28+
ze_device_properties_t device_properties{};
29+
device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
30+
31+
ze_device_luid_ext_properties_t luid_device_properties{};
32+
luid_device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
33+
34+
device_properties.pNext = &luid_device_properties;
35+
36+
zeDeviceGetProperties(zedev, &device_properties);
37+
38+
ze_device_luid_ext_properties_t *luid_dev_prop =
39+
static_cast<ze_device_luid_ext_properties_t *>(device_properties.pNext);
40+
41+
std::stringstream luid_l0;
42+
for (int i = 0; i < ZE_MAX_DEVICE_LUID_SIZE_EXT; ++i)
43+
luid_l0 << std::hex << std::setw(2) << std::setfill('0')
44+
<< int(luid_dev_prop->luid.id[i]);
45+
std::cout << "L0 : " << luid_l0.str() << std::endl;
46+
47+
if (luid_sycl.str() != luid_l0.str()) {
48+
std::cout << "FAILED" << std::endl;
49+
return -1;
50+
}
51+
52+
std::cout << "PASSED" << std::endl;
53+
return 0;
54+
}

0 commit comments

Comments
 (0)