Skip to content

Commit 51b86a0

Browse files
authored
[UR] Clarify spec around devices created from native handles. (#17910)
1 parent e620747 commit 51b86a0

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

unified-runtime/include/ur_api.h

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

unified-runtime/scripts/core/device.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ decl: static
835835
ordinal: "0"
836836
details:
837837
- "Creates runtime device handle from native driver device handle."
838+
- "Will always return the same handle in `phDevice` for a given `hNativeDevice`."
839+
- "If `hNativeDevice` is a root-level device, the handle returned in `phDevice` will be one of the handles that can be obtained by calling $xDeviceGet with the $X_DEVICE_TYPE_ALL device type."
838840
- "The application may call this function from simultaneous threads for the same context."
839841
- "The implementation of this function should be thread-safe."
840842
params:

unified-runtime/source/loader/ur_libapi.cpp

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

unified-runtime/source/ur_api.cpp

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

unified-runtime/test/conformance/device/urDeviceCreateWithNativeHandle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ TEST_P(urDeviceCreateWithNativeHandleTest, Success) {
2424
urDeviceCreateWithNativeHandle(native_handle, adapter, nullptr, &dev));
2525
ASSERT_NE(dev, nullptr);
2626

27+
// Based on the spec we can expect these to be equal.
28+
ASSERT_EQ(dev, device);
29+
2730
uint32_t dev_id = 0;
2831
ASSERT_SUCCESS(urDeviceGetInfo(dev, UR_DEVICE_INFO_TYPE, sizeof(uint32_t),
2932
&dev_id, nullptr));
@@ -41,6 +44,7 @@ TEST_P(urDeviceCreateWithNativeHandleTest,
4144
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
4245
urDeviceCreateWithNativeHandle(native_handle, adapter, &props, &dev));
4346
ASSERT_NE(dev, nullptr);
47+
ASSERT_EQ(dev, device);
4448
}
4549

4650
TEST_P(urDeviceCreateWithNativeHandleTest, InvalidNullHandlePlatform) {

unified-runtime/test/conformance/queue/urQueueGetInfo.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,7 @@ TEST_P(urQueueGetInfoTest, SuccessRoundtripNullDevice) {
121121
ASSERT_SUCCESS(urQueueGetInfo(from_native_queue, property_name, property_size,
122122
&property_value, nullptr));
123123

124-
// We can't assume that the two device handles are equal (since creating the
125-
// link to the UR structures has been severed by going through native handle,
126-
// so just check the underlying native pointers
127-
ur_native_handle_t original_device;
128-
ur_native_handle_t new_device;
129-
ASSERT_SUCCESS(urDeviceGetNativeHandle(device, &original_device));
130-
ASSERT_SUCCESS(urDeviceGetNativeHandle(property_value, &new_device));
131-
ASSERT_EQ(original_device, new_device);
124+
ASSERT_EQ(property_value, device);
132125
}
133126

134127
TEST_P(urQueueGetInfoTest, SuccessFlags) {

0 commit comments

Comments
 (0)