Skip to content

Commit 25aee28

Browse files
authored
[SYCL] Add support for device UUID as a SYCL extension. (#3696)
This includes support for only level_zero. The llvm/sycl/docs/extensions/IntelGPU/IntelGPUDeviceInfo.md doc has been modified with a brief description of the extension. A new aspect is added to indicate if the support is available. Signed-off-by: rbegam <[email protected]>
1 parent ace4c73 commit 25aee28

File tree

15 files changed

+217
-6
lines changed

15 files changed

+217
-6
lines changed

sycl/doc/extensions/IntelGPU/IntelGPUDeviceInfo.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,50 @@ This proposal details what is required to provide this information as a SYCL ext
99

1010
## Feature Test Macro ##
1111

12-
The Feature Test Macro will be defined as:
12+
The Feature Test Macro SYCL\_EXT\_INTEL\_DEVICE\_INFO will be defined as one of the values defined in the table below. The existence of this macro can be tested to determine if the implementation supports this feature, or applications can test the macro's value to determine which of the extension's APIs the implementation supports.
13+
14+
| Value | Description |
15+
| ----- | ----------- |
16+
| 1 | Initial extension version\. Base features are supported |
17+
| 2 | Device UUID is supported |
18+
19+
20+
# Device UUID #
21+
22+
A new device descriptor will be added which will provide the device Universal Unique ID (UUID).
23+
24+
This new device descriptor is currently only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior would be to expose the UUIDs of all supported devices which enables detection of total number of unique devices.
25+
26+
27+
## Version ##
28+
29+
The extension supports this query in version 2 and later.
30+
31+
32+
## Device Information Descriptors ##
33+
34+
| Device Descriptors | Return Type | Description |
35+
| ------------------ | ----------- | ----------- |
36+
| info\:\:device\:\:ext\_intel\_device\_info\_uuid | unsigned char | Returns the device UUID|
37+
38+
39+
## Aspects ##
40+
41+
A new aspect, ext\_intel\_device\_info\_uuid, will be added.
42+
43+
## Error Condition ##
44+
45+
An invalid object runtime error will be thrown if the device does not support aspect\:\:ext\_intel\_device\_info\_uuid.
46+
47+
48+
## Example Usage ##
49+
50+
The UUID can be obtained using the standard get\_info() interface.
51+
52+
if (dev.has(aspect::ext_intel_device_info_uuid)) {
53+
auto UUID = dev.get_info<info::device::ext_intel_device_info_uuid>();
54+
}
1355

14-
#define SYCL_EXT_INTEL_DEVICE_INFO 1
1556

1657

1758
# PCI Address #
@@ -23,6 +64,11 @@ This new device descriptor is only available for devices in the Level Zero platf
2364
**Note:** The environment variable SYCL\_ENABLE\_PCI must be set to 1 to obtain the PCI address.
2465

2566

67+
## Version ##
68+
69+
All versions of the extension support this query.
70+
71+
2672
## Device Information Descriptors ##
2773

2874
| Device Descriptors | Return Type | Description |
@@ -56,6 +102,11 @@ A new device descriptor will be added which will provide the physical SIMD width
56102
This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform.
57103

58104

105+
## Version ##
106+
107+
All versions of the extension support this query.
108+
109+
59110
## Device Information Descriptors ##
60111

61112
| Device Descriptors | Return Type | Description |
@@ -91,6 +142,11 @@ This new device descriptor will provide the same information as "max\_compute\_u
91142
This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform.
92143

93144

145+
## Version ##
146+
147+
All versions of the extension support this query.
148+
149+
94150
## Device Information Descriptors ##
95151

96152
| Device Descriptors | Return Type | Description |
@@ -124,6 +180,11 @@ A new device descriptor will be added which will provide the number of slices on
124180
This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform.
125181

126182

183+
## Version ##
184+
185+
All versions of the extension support this query.
186+
187+
127188
## Device Information Descriptors ##
128189

129190
| Device Descriptors | Return Type | Description |
@@ -156,6 +217,11 @@ A new device descriptor will be added which will provide the number of subslices
156217
This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform.
157218

158219

220+
## Version ##
221+
222+
All versions of the extension support this query.
223+
224+
159225
## Device Information Descriptors ##
160226

161227
| Device Descriptors | Return Type | Description |
@@ -188,6 +254,11 @@ A new device descriptor will be added which will provide the number of EUs per s
188254
This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform.
189255

190256

257+
## Version ##
258+
259+
All versions of the extension support this query.
260+
261+
191262
## Device Information Descriptors ##
192263

193264
| Device Descriptors | Return Type | Description |
@@ -220,6 +291,11 @@ A new device descriptor will be added which will provide the maximum memory band
220291
This new device descriptor is only available for devices in the Level Zero platform, and the matching aspect is only true for those devices. The DPC++ default behavior is to expose GPU devices through the Level Zero platform.
221292

222293

294+
## Version ##
295+
296+
All versions of the extension support this query.
297+
298+
223299
## Device Information Descriptors ##
224300

225301
| Device Descriptors | Return Type | Description |

sycl/include/CL/sycl/aspects.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ enum class aspect {
4141
ext_intel_mem_channel = 25,
4242
usm_atomic_host_allocations = 26,
4343
usm_atomic_shared_allocations = 27,
44-
atomic64 = 28
44+
atomic64 = 28,
45+
ext_intel_device_info_uuid = 29,
4546
};
4647

4748
} // namespace sycl

sycl/include/CL/sycl/detail/pi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <CL/cl_ext.h>
5353
#include <CL/sycl/detail/cl.h>
5454
#include <CL/sycl/detail/export.hpp>
55+
5556
#include <cstdint>
5657

5758
#ifdef __cplusplus
@@ -278,6 +279,8 @@ typedef enum {
278279
CL_DEVICE_CROSS_DEVICE_SHARED_MEM_CAPABILITIES_INTEL,
279280
PI_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT =
280281
CL_DEVICE_SHARED_SYSTEM_MEM_CAPABILITIES_INTEL,
282+
// Intel UUID extension.
283+
PI_DEVICE_INFO_UUID = CL_DEVICE_UUID_KHR,
281284
// These are Intel-specific extensions.
282285
PI_DEVICE_INFO_PCI_ADDRESS = 0x10020,
283286
PI_DEVICE_INFO_GPU_EU_COUNT = 0x10021,

sycl/include/CL/sycl/detail/type_traits.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <CL/sycl/detail/stl_type_traits.hpp>
1414
#include <CL/sycl/detail/type_list.hpp>
1515

16+
#include <array>
1617
#include <type_traits>
1718

1819
__SYCL_INLINE_NAMESPACE(cl) {
@@ -51,6 +52,11 @@ __SYCL_INLINE_CONSTEXPR bool is_group_v =
5152
detail::is_group<T>::value || detail::is_sub_group<T>::value;
5253

5354
namespace detail {
55+
// Type for Intel device UUID extension.
56+
// For details about this extension, see
57+
// sycl/doc/extensions/IntelGPU/IntelGPUDeviceInfo.md
58+
using uuid_type = std::array<unsigned char, 16>;
59+
5460
template <typename T, typename R> struct copy_cv_qualifiers;
5561

5662
template <typename T, typename R>

sycl/include/CL/sycl/feature_test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace sycl {
1313
// Feature test macro definitions
1414

1515
// TODO: Move these feature-test macros to compiler driver.
16-
#define SYCL_EXT_INTEL_DEVICE_INFO 1
16+
#define SYCL_EXT_INTEL_DEVICE_INFO 2
1717
#define SYCL_EXT_ONEAPI_MATRIX 1
1818

1919
} // namespace sycl

sycl/include/CL/sycl/info/device_traits.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ __SYCL_PARAM_TRAITS_SPEC(device, ext_intel_gpu_subslices_per_slice, pi_uint32)
9494
__SYCL_PARAM_TRAITS_SPEC(device, ext_intel_gpu_eu_count_per_subslice, pi_uint32)
9595
__SYCL_PARAM_TRAITS_SPEC(device, ext_intel_max_mem_bandwidth, pi_uint64)
9696
__SYCL_PARAM_TRAITS_SPEC(device, ext_intel_mem_channel, bool)
97+
__SYCL_PARAM_TRAITS_SPEC(device, ext_intel_device_info_uuid, detail::uuid_type)

sycl/include/CL/sycl/info/info_desc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ enum class device : cl_device_info {
134134
usm_shared_allocations = PI_USM_SINGLE_SHARED_SUPPORT,
135135
usm_restricted_shared_allocations = PI_USM_CROSS_SHARED_SUPPORT,
136136
usm_system_allocator = PI_USM_SYSTEM_SHARED_SUPPORT,
137-
138137
// intel extensions
139138
ext_intel_pci_address = PI_DEVICE_INFO_PCI_ADDRESS,
140139
ext_intel_gpu_eu_count = PI_DEVICE_INFO_GPU_EU_COUNT,
@@ -145,6 +144,7 @@ enum class device : cl_device_info {
145144
PI_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE,
146145
ext_intel_max_mem_bandwidth = PI_DEVICE_INFO_MAX_MEM_BANDWIDTH,
147146
ext_intel_mem_channel = PI_MEM_PROPERTIES_CHANNEL,
147+
ext_intel_device_info_uuid = PI_DEVICE_INFO_UUID,
148148
atomic64 = PI_DEVICE_INFO_ATOMIC_64
149149
};
150150

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,10 @@ pi_result cuda_piDeviceGetInfo(pi_device device, pi_device_info param_name,
15511551
case PI_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE:
15521552
case PI_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE:
15531553
case PI_DEVICE_INFO_MAX_MEM_BANDWIDTH:
1554+
// TODO: Check if Intel device UUID extension is utilized for CUDA.
1555+
// For details about this extension, see
1556+
// sycl/doc/extensions/IntelGPU/IntelGPUDeviceInfo.md
1557+
case PI_DEVICE_INFO_UUID:
15541558
return PI_INVALID_VALUE;
15551559

15561560
default:

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,11 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
16551655
return ReturnValue(Device->Platform);
16561656
case PI_DEVICE_INFO_VENDOR_ID:
16571657
return ReturnValue(pi_uint32{Device->ZeDeviceProperties.vendorId});
1658+
case PI_DEVICE_INFO_UUID:
1659+
// Intel extension for device UUID. This returns the UUID as
1660+
// std::array<std::byte, 16>. For details about this extension,
1661+
// see sycl/doc/extensions/IntelGPU/IntelGPUDeviceInfo.md.
1662+
return ReturnValue(Device->ZeDeviceProperties.uuid.id);
16581663
case PI_DEVICE_INFO_EXTENSIONS: {
16591664
// Convention adopted from OpenCL:
16601665
// "Returns a space separated list of extension names (the extension

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,19 @@ pi_result piDeviceGetInfo(pi_device device, pi_device_info paramName,
169169
size_t paramValueSize, void *paramValue,
170170
size_t *paramValueSizeRet) {
171171
switch (paramName) {
172-
// Intel GPU EU device-specific information extensions.
173172
// TODO: Check regularly to see if support in enabled in OpenCL.
173+
// Intel GPU EU device-specific information extensions.
174174
case PI_DEVICE_INFO_PCI_ADDRESS:
175175
case PI_DEVICE_INFO_GPU_EU_COUNT:
176176
case PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH:
177177
case PI_DEVICE_INFO_GPU_SLICES:
178178
case PI_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE:
179179
case PI_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE:
180180
case PI_DEVICE_INFO_MAX_MEM_BANDWIDTH:
181+
// TODO: Check if device UUID extension is enabled in OpenCL.
182+
// For details about Intel UUID extension, see
183+
// sycl/doc/extensions/IntelGPU/IntelGPUDeviceInfo.md
184+
case PI_DEVICE_INFO_UUID:
181185
case PI_DEVICE_INFO_ATOMIC_64:
182186
return PI_INVALID_VALUE;
183187

sycl/source/detail/device_impl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ bool device_impl::has(aspect Aspect) const {
298298
MDevice, PI_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE,
299299
sizeof(pi_device_type), &device_type,
300300
&return_size) == PI_SUCCESS;
301+
case aspect::ext_intel_device_info_uuid: {
302+
auto Result = getPlugin().call_nocheck<detail::PiApiKind::piDeviceGetInfo>(
303+
MDevice, PI_DEVICE_INFO_UUID, 0, nullptr, &return_size);
304+
if (Result != PI_SUCCESS) {
305+
return false;
306+
}
307+
308+
assert(return_size <= 16);
309+
unsigned char UUID[16];
310+
311+
return getPlugin().call_nocheck<detail::PiApiKind::piDeviceGetInfo>(
312+
MDevice, PI_DEVICE_INFO_UUID, 16 * sizeof(unsigned char), UUID,
313+
nullptr) == PI_SUCCESS;
314+
}
301315
case aspect::ext_intel_max_mem_bandwidth:
302316
// currently not supported
303317
return false;

sycl/source/detail/device_info.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,14 @@ get_device_info_host<info::device::ext_intel_max_mem_bandwidth>() {
11011101
PI_INVALID_DEVICE);
11021102
}
11031103

1104+
template <>
1105+
inline detail::uuid_type
1106+
get_device_info_host<info::device::ext_intel_device_info_uuid>() {
1107+
throw runtime_error(
1108+
"Obtaining the device uuid is not supported on HOST device",
1109+
PI_INVALID_DEVICE);
1110+
}
1111+
11041112
} // namespace detail
11051113
} // namespace sycl
11061114
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,7 @@ _ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4168EEENS3_12param_traitsIS4_XT_E
41204120
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4169EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41214121
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4188EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41224122
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4189EEENS3_12param_traitsIS4_XT_EE11return_typeEv
4123+
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE4202EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41234124
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE65568EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41244125
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE65569EEENS3_12param_traitsIS4_XT_EE11return_typeEv
41254126
_ZNK2cl4sycl6device8get_infoILNS0_4info6deviceE65570EEENS3_12param_traitsIS4_XT_EE11return_typeEv
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_sycl_unittest(KernelAndProgramTests OBJECT
22
KernelRelease.cpp
33
KernelInfo.cpp
4+
DeviceInfo.cpp
45
PersistentDeviceCodeCache.cpp
56
)
67
add_subdirectory(device)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//==-------------- DeviceInfo.cpp --- device info unit test ----------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <CL/sycl.hpp>
10+
#include <detail/context_impl.hpp>
11+
#include <gtest/gtest.h>
12+
#include <helpers/PiMock.hpp>
13+
14+
using namespace sycl;
15+
16+
namespace {
17+
struct TestCtx {
18+
TestCtx(context &Ctx) : Ctx{Ctx} {}
19+
20+
context &Ctx;
21+
bool UUIDInfoCalled = false;
22+
};
23+
} // namespace
24+
25+
static std::unique_ptr<TestCtx> TestContext;
26+
27+
static pi_result redefinedDeviceGetInfo(pi_device device,
28+
pi_device_info param_name,
29+
size_t param_value_size,
30+
void *param_value,
31+
size_t *param_value_size_ret) {
32+
if (param_name == PI_DEVICE_INFO_UUID) {
33+
TestContext->UUIDInfoCalled = true;
34+
}
35+
36+
return PI_SUCCESS;
37+
}
38+
39+
class DeviceInfoTest : public ::testing::Test {
40+
public:
41+
DeviceInfoTest() : Plt{default_selector()} {}
42+
43+
protected:
44+
void SetUp() override {
45+
if (Plt.is_host()) {
46+
std::clog << "This test is only supported on non-host platforms.\n";
47+
std::clog << "Current platform is "
48+
<< Plt.get_info<info::platform::name>() << "\n";
49+
return;
50+
}
51+
52+
Mock = std::make_unique<unittest::PiMock>(Plt);
53+
54+
Mock->redefine<detail::PiApiKind::piDeviceGetInfo>(redefinedDeviceGetInfo);
55+
}
56+
57+
protected:
58+
platform Plt;
59+
std::unique_ptr<unittest::PiMock> Mock;
60+
};
61+
62+
TEST_F(DeviceInfoTest, GetDeviceUUID) {
63+
if (Plt.is_host()) {
64+
return;
65+
}
66+
67+
context Ctx{Plt};
68+
TestContext.reset(new TestCtx(Ctx));
69+
70+
device Dev = Ctx.get_devices()[0];
71+
72+
if (!Dev.has(aspect::ext_intel_device_info_uuid)) {
73+
std::clog
74+
<< "This test is only for the devices with UUID extension support.\n";
75+
return;
76+
}
77+
78+
auto UUID = Dev.get_info<info::device::ext_intel_device_info_uuid>();
79+
80+
EXPECT_EQ(TestContext->UUIDInfoCalled, true)
81+
<< "Expect piDeviceGetInfo to be "
82+
<< "called with PI_DEVICE_INFO_UUID";
83+
84+
EXPECT_EQ(sizeof(UUID), 16 * sizeof(unsigned char))
85+
<< "Expect device UUID to be "
86+
<< "of 16 bytes";
87+
}

0 commit comments

Comments
 (0)