Skip to content

Commit 3e46d20

Browse files
authored
[UR] Added "roundtrip" GetInfo comformance tests (#17738)
This tests that converting a UR handle to a native handle, then back into a UR handle preserves/recreates any handles contained within it. The event test is a special case; since urEventCreateWithNativeHandle doesn't accept a queue paramater. For this, we tollerate a different queue being created, as long as they both have the same underlying native handle.
1 parent 3d70752 commit 3e46d20

File tree

7 files changed

+296
-0
lines changed

7 files changed

+296
-0
lines changed

unified-runtime/test/conformance/context/urContextGetInfo.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ TEST_P(urContextGetInfoTest, SuccessDevices) {
4242
ASSERT_EQ(property_value, device);
4343
}
4444

45+
TEST_P(urContextGetInfoTest, SuccessRoundtripDevices) {
46+
const ur_context_info_t property_name = UR_CONTEXT_INFO_DEVICES;
47+
size_t property_size = sizeof(ur_device_handle_t);
48+
49+
ur_native_handle_t native_context;
50+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
51+
urContextGetNativeHandle(context, &native_context));
52+
53+
ur_context_handle_t from_native_context;
54+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urContextCreateWithNativeHandle(
55+
native_context, adapter, 1, &device, nullptr, &from_native_context));
56+
57+
ur_device_handle_t property_value = nullptr;
58+
ASSERT_SUCCESS(urContextGetInfo(from_native_context, property_name,
59+
property_size, &property_value, nullptr));
60+
61+
size_t devices_count = property_size / sizeof(ur_device_handle_t);
62+
ASSERT_EQ(devices_count, 1);
63+
ASSERT_EQ(property_value, device);
64+
}
65+
4566
TEST_P(urContextGetInfoTest, SuccessUSMMemCpy2DSupport) {
4667
const ur_context_info_t property_name = UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT;
4768
size_t property_size = 0;

unified-runtime/test/conformance/event/urEventGetInfo.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,58 @@ TEST_P(urEventGetInfoTest, SuccessCommandQueue) {
2525
ASSERT_EQ(queue, property_value);
2626
}
2727

28+
TEST_P(urEventGetInfoTest, SuccessRoundtripContext) {
29+
// Segfaults
30+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
31+
32+
const ur_event_info_t property_name = UR_EVENT_INFO_CONTEXT;
33+
size_t property_size = sizeof(ur_context_handle_t);
34+
35+
ur_native_handle_t native_event;
36+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
37+
urEventGetNativeHandle(event, &native_event));
38+
39+
ur_event_handle_t from_native_event;
40+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEventCreateWithNativeHandle(
41+
native_event, context, nullptr, &from_native_event));
42+
43+
ur_context_handle_t property_value = nullptr;
44+
ASSERT_SUCCESS(urEventGetInfo(from_native_event, property_name, property_size,
45+
&property_value, nullptr));
46+
47+
ASSERT_EQ(property_value, context);
48+
}
49+
50+
TEST_P(urEventGetInfoTest, SuccessRoundtripCommandQueue) {
51+
UUR_KNOWN_FAILURE_ON(uur::HIP{}, uur::CUDA{});
52+
// Segfaults
53+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
54+
55+
const ur_event_info_t property_name = UR_EVENT_INFO_COMMAND_QUEUE;
56+
size_t property_size = sizeof(ur_queue_handle_t);
57+
58+
ur_native_handle_t native_event;
59+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
60+
urEventGetNativeHandle(event, &native_event));
61+
62+
ur_event_handle_t from_native_event;
63+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEventCreateWithNativeHandle(
64+
native_event, context, nullptr, &from_native_event));
65+
66+
ur_queue_handle_t property_value = nullptr;
67+
ASSERT_SUCCESS(urEventGetInfo(from_native_event, property_name, property_size,
68+
&property_value, nullptr));
69+
70+
// We can't assume that the two queue handles are equal (since creating the
71+
// link to the UR structures has been severed by going through native handle,
72+
// so just check the underlying native pointers
73+
ur_native_handle_t original_queue;
74+
ur_native_handle_t new_queue;
75+
ASSERT_SUCCESS(urQueueGetNativeHandle(queue, nullptr, &original_queue));
76+
ASSERT_SUCCESS(urQueueGetNativeHandle(property_value, nullptr, &new_queue));
77+
ASSERT_EQ(original_queue, new_queue);
78+
}
79+
2880
TEST_P(urEventGetInfoTest, SuccessContext) {
2981
const ur_event_info_t property_name = UR_EVENT_INFO_CONTEXT;
3082
size_t property_size = 0;

unified-runtime/test/conformance/kernel/urKernelGetInfo.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ TEST_P(urKernelGetInfoTest, SuccessContext) {
7777
ASSERT_EQ(context, property_value);
7878
}
7979

80+
TEST_P(urKernelGetInfoTest, SuccessRoundtripContext) {
81+
const ur_kernel_info_t property_name = UR_KERNEL_INFO_CONTEXT;
82+
size_t property_size = 0;
83+
84+
ur_native_handle_t native_kernel;
85+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
86+
urKernelGetNativeHandle(kernel, &native_kernel));
87+
88+
ur_kernel_handle_t from_native_kernel;
89+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urKernelCreateWithNativeHandle(
90+
native_kernel, context, program, nullptr, &from_native_kernel));
91+
92+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(urKernelGetInfo(from_native_kernel,
93+
property_name, 0, nullptr,
94+
&property_size),
95+
property_name);
96+
ASSERT_EQ(property_size, sizeof(ur_context_handle_t));
97+
98+
ur_context_handle_t property_value = nullptr;
99+
ASSERT_SUCCESS(urKernelGetInfo(from_native_kernel, property_name,
100+
property_size, &property_value, nullptr));
101+
102+
ASSERT_EQ(property_value, context);
103+
}
104+
80105
TEST_P(urKernelGetInfoTest, SuccessProgram) {
81106
const ur_kernel_info_t property_name = UR_KERNEL_INFO_PROGRAM;
82107
size_t property_size = 0;
@@ -93,6 +118,55 @@ TEST_P(urKernelGetInfoTest, SuccessProgram) {
93118
ASSERT_EQ(program, property_value);
94119
}
95120

121+
TEST_P(urKernelGetInfoTest, SuccessRoundtripProgram) {
122+
const ur_kernel_info_t property_name = UR_KERNEL_INFO_PROGRAM;
123+
size_t property_size = sizeof(ur_program_handle_t);
124+
125+
ur_native_handle_t native_kernel;
126+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
127+
urKernelGetNativeHandle(kernel, &native_kernel));
128+
129+
ur_kernel_handle_t from_native_kernel;
130+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urKernelCreateWithNativeHandle(
131+
native_kernel, context, program, nullptr, &from_native_kernel));
132+
133+
ur_program_handle_t property_value = nullptr;
134+
ASSERT_SUCCESS(urKernelGetInfo(from_native_kernel, property_name,
135+
property_size, &property_value, nullptr));
136+
137+
ASSERT_EQ(property_value, program);
138+
}
139+
140+
TEST_P(urKernelGetInfoTest, SuccessRoundtripNullProgram) {
141+
const ur_kernel_info_t property_name = UR_KERNEL_INFO_PROGRAM;
142+
size_t property_size = sizeof(ur_program_handle_t);
143+
144+
ur_native_handle_t native_kernel;
145+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
146+
urKernelGetNativeHandle(kernel, &native_kernel));
147+
148+
ur_kernel_handle_t from_native_kernel;
149+
auto result = urKernelCreateWithNativeHandle(native_kernel, context, nullptr,
150+
nullptr, &from_native_kernel);
151+
if (result == UR_RESULT_ERROR_INVALID_NULL_HANDLE) {
152+
GTEST_SKIP() << "Implementation requires a valid program";
153+
}
154+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(result);
155+
156+
ur_program_handle_t property_value = nullptr;
157+
ASSERT_SUCCESS(urKernelGetInfo(from_native_kernel, property_name,
158+
property_size, &property_value, nullptr));
159+
160+
// We can't assume that the two program handles are equal (since creating the
161+
// link to the UR structures has been severed by going through native handle,
162+
// so just check the underlying native pointers
163+
ur_native_handle_t original_program;
164+
ur_native_handle_t new_program;
165+
ASSERT_SUCCESS(urProgramGetNativeHandle(program, &original_program));
166+
ASSERT_SUCCESS(urProgramGetNativeHandle(property_value, &new_program));
167+
ASSERT_EQ(original_program, new_program);
168+
}
169+
96170
TEST_P(urKernelGetInfoTest, SuccessAttributes) {
97171
const ur_kernel_info_t property_name = UR_KERNEL_INFO_ATTRIBUTES;
98172
size_t property_size = 0;

unified-runtime/test/conformance/platform/urPlatformGetInfo.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ TEST_P(urPlatformGetInfoTest, SuccessAdapter) {
128128
ASSERT_NE(adapter_found, uur::AdapterEnvironment::instance->adapters.end());
129129
}
130130

131+
TEST_P(urPlatformGetInfoTest, SuccessRoundtripAdapter) {
132+
const ur_platform_info_t property_name = UR_PLATFORM_INFO_ADAPTER;
133+
size_t property_size = sizeof(ur_adapter_handle_t);
134+
135+
ur_adapter_handle_t adapter = nullptr;
136+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
137+
urPlatformGetInfo(platform, UR_PLATFORM_INFO_ADAPTER,
138+
sizeof(ur_adapter_handle_t), &adapter, nullptr),
139+
UR_PLATFORM_INFO_ADAPTER);
140+
141+
ur_native_handle_t native_platform;
142+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
143+
urPlatformGetNativeHandle(platform, &native_platform));
144+
145+
ur_platform_handle_t from_native_platform;
146+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urPlatformCreateWithNativeHandle(
147+
native_platform, adapter, nullptr, &from_native_platform));
148+
149+
ur_adapter_handle_t property_value = nullptr;
150+
ASSERT_SUCCESS(urPlatformGetInfo(from_native_platform, property_name,
151+
property_size, &property_value, nullptr));
152+
153+
ASSERT_EQ(adapter, property_value);
154+
}
155+
131156
TEST_P(urPlatformGetInfoTest, InvalidNullHandlePlatform) {
132157
size_t property_size = 0;
133158
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,

unified-runtime/test/conformance/program/urProgramGetInfo.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ TEST_P(urProgramGetInfoTest, SuccessContext) {
5151
ASSERT_EQ(property_value, context);
5252
}
5353

54+
TEST_P(urProgramGetInfoTest, SuccessRoundtripContext) {
55+
const ur_program_info_t property_name = UR_PROGRAM_INFO_CONTEXT;
56+
size_t property_size = sizeof(ur_context_handle_t);
57+
58+
ur_native_handle_t native_program;
59+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
60+
urProgramGetNativeHandle(program, &native_program));
61+
62+
ur_program_handle_t from_native_program;
63+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urProgramCreateWithNativeHandle(
64+
native_program, context, nullptr, &from_native_program));
65+
66+
ur_context_handle_t property_value = nullptr;
67+
ASSERT_SUCCESS(urProgramGetInfo(from_native_program, property_name,
68+
property_size, &property_value, nullptr));
69+
70+
ASSERT_EQ(property_value, context);
71+
}
72+
5473
TEST_P(urProgramGetInfoTest, SuccessNumDevices) {
5574
size_t property_size = 0;
5675
const ur_program_info_t property_name = UR_PROGRAM_INFO_NUM_DEVICES;

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ TEST_P(urQueueGetInfoTest, SuccessContext) {
2727
ASSERT_EQ(context, property_value);
2828
}
2929

30+
TEST_P(urQueueGetInfoTest, SuccessRoundtripContext) {
31+
const ur_queue_info_t property_name = UR_QUEUE_INFO_CONTEXT;
32+
size_t property_size = sizeof(ur_context_handle_t);
33+
34+
ur_native_handle_t native_queue;
35+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
36+
urQueueGetNativeHandle(queue, nullptr, &native_queue));
37+
38+
ur_queue_handle_t from_native_queue;
39+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueCreateWithNativeHandle(
40+
native_queue, context, device, nullptr, &from_native_queue));
41+
42+
ur_context_handle_t property_value = nullptr;
43+
ASSERT_SUCCESS(urQueueGetInfo(from_native_queue, property_name, property_size,
44+
&property_value, nullptr));
45+
46+
ASSERT_EQ(property_value, context);
47+
}
48+
3049
TEST_P(urQueueGetInfoTest, SuccessDevice) {
3150
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
3251

@@ -45,6 +64,73 @@ TEST_P(urQueueGetInfoTest, SuccessDevice) {
4564
ASSERT_EQ(device, property_value);
4665
}
4766

67+
TEST_P(urQueueGetInfoTest, SuccessRoundtripDevice) {
68+
// Segfaults
69+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
70+
71+
const ur_queue_info_t property_name = UR_QUEUE_INFO_DEVICE;
72+
size_t property_size = 0;
73+
74+
ur_native_handle_t native_queue;
75+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
76+
urQueueGetNativeHandle(queue, nullptr, &native_queue));
77+
78+
ur_queue_handle_t from_native_queue;
79+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueCreateWithNativeHandle(
80+
native_queue, context, device, nullptr, &from_native_queue));
81+
82+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(urQueueGetInfo(from_native_queue,
83+
property_name, 0, nullptr,
84+
&property_size),
85+
property_name);
86+
ASSERT_EQ(property_size, sizeof(ur_device_handle_t));
87+
88+
ur_device_handle_t property_value = nullptr;
89+
ASSERT_SUCCESS(urQueueGetInfo(from_native_queue, property_name, property_size,
90+
&property_value, nullptr));
91+
92+
ASSERT_EQ(property_value, device);
93+
}
94+
95+
TEST_P(urQueueGetInfoTest, SuccessRoundtripNullDevice) {
96+
// Segfaults
97+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
98+
99+
const ur_queue_info_t property_name = UR_QUEUE_INFO_DEVICE;
100+
size_t property_size = 0;
101+
102+
ur_native_handle_t native_queue;
103+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
104+
urQueueGetNativeHandle(queue, nullptr, &native_queue));
105+
106+
ur_queue_handle_t from_native_queue;
107+
auto result = urQueueCreateWithNativeHandle(native_queue, context, nullptr,
108+
nullptr, &from_native_queue);
109+
if (result == UR_RESULT_ERROR_INVALID_NULL_HANDLE) {
110+
GTEST_SKIP() << "Implementation requires a valid device";
111+
}
112+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(result);
113+
114+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(urQueueGetInfo(from_native_queue,
115+
property_name, 0, nullptr,
116+
&property_size),
117+
property_name);
118+
ASSERT_EQ(property_size, sizeof(ur_device_handle_t));
119+
120+
ur_device_handle_t property_value = nullptr;
121+
ASSERT_SUCCESS(urQueueGetInfo(from_native_queue, property_name, property_size,
122+
&property_value, nullptr));
123+
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);
132+
}
133+
48134
TEST_P(urQueueGetInfoTest, SuccessFlags) {
49135
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
50136

unified-runtime/test/conformance/sampler/urSamplerGetInfo.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ TEST_P(urSamplerGetInfoTest, SuccessContext) {
4848
ASSERT_EQ(property_value, context);
4949
}
5050

51+
TEST_P(urSamplerGetInfoTest, SuccessRoundtripContext) {
52+
const ur_sampler_info_t property_name = UR_SAMPLER_INFO_CONTEXT;
53+
size_t property_size = sizeof(ur_context_handle_t);
54+
55+
ur_native_handle_t native_sampler;
56+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
57+
urSamplerGetNativeHandle(sampler, &native_sampler));
58+
59+
ur_sampler_handle_t from_native_sampler;
60+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urSamplerCreateWithNativeHandle(
61+
native_sampler, context, nullptr, &from_native_sampler));
62+
63+
ur_context_handle_t property_value = nullptr;
64+
ASSERT_SUCCESS(urSamplerGetInfo(from_native_sampler, property_name,
65+
property_size, &property_value, nullptr));
66+
67+
ASSERT_EQ(property_value, context);
68+
}
69+
5170
TEST_P(urSamplerGetInfoTest, SuccessNormalizedCoords) {
5271
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
5372

0 commit comments

Comments
 (0)