Skip to content

Commit 3a1a3e4

Browse files
committed
Update cts tests.
1 parent dc7597c commit 3a1a3e4

File tree

8 files changed

+124
-23
lines changed

8 files changed

+124
-23
lines changed

source/adapters/level_zero/context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ ur_result_t urContextCreateWithNativeHandle(
159159
const ur_context_native_properties_t *Properties,
160160
/// [out] pointer to the handle of the context object created.
161161
ur_context_handle_t *Context) {
162-
bool OwnNativeHandle = Properties->isNativeHandleOwned;
162+
bool OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false;
163163
try {
164164
ze_context_handle_t ZeContext =
165165
reinterpret_cast<ze_context_handle_t>(NativeContext);

source/adapters/level_zero/memory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,9 @@ ur_result_t urMemImageCreateWithNativeHandle(
16391639
return Res;
16401640
}
16411641

1642-
UR_CALL(createUrMemFromZeImage(
1643-
Context, ZeHImage, Properties->isNativeHandleOwned, ZeImageDesc, Mem));
1642+
auto OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false;
1643+
UR_CALL(createUrMemFromZeImage(Context, ZeHImage, OwnNativeHandle,
1644+
ZeImageDesc, Mem));
16441645

16451646
return UR_RESULT_SUCCESS;
16461647
}

test/conformance/event/urEventCreateWithNativeHandle.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,26 @@ TEST_P(urEventCreateWithNativeHandleTest, Success) {
3333
sizeof(ur_execution_info_t), &exec_info,
3434
nullptr));
3535
}
36+
37+
TEST_P(urEventCreateWithNativeHandleTest, SuccessWithProperties) {
38+
ur_native_handle_t native_event = 0;
39+
{
40+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
41+
urEventGetNativeHandle(event, &native_event));
42+
}
43+
44+
uur::raii::Event evt = nullptr;
45+
// We can't pass isNativeHandleOwned = true in the generic tests since
46+
// we always get the native handle from a UR object, and transferring
47+
// ownership from one UR object to another isn't allowed.
48+
ur_event_native_properties_t props = {
49+
UR_STRUCTURE_TYPE_EVENT_NATIVE_PROPERTIES, nullptr, false};
50+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
51+
urEventCreateWithNativeHandle(native_event, context, &props, evt.ptr()));
52+
ASSERT_NE(evt, nullptr);
53+
54+
ur_execution_info_t exec_info;
55+
ASSERT_SUCCESS(urEventGetInfo(evt, UR_EVENT_INFO_COMMAND_EXECUTION_STATUS,
56+
sizeof(ur_execution_info_t), &exec_info,
57+
nullptr));
58+
}

test/conformance/kernel/urKernelCreateWithNativeHandle.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ struct urKernelCreateWithNativeHandleTest : uur::urKernelTest {
1414
urKernelGetNativeHandle(kernel, &native_kernel_handle));
1515
}
1616

17-
void TearDown() override {
18-
if (native_kernel) {
19-
EXPECT_SUCCESS(urKernelRelease(native_kernel));
20-
}
21-
UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::TearDown());
22-
}
23-
2417
ur_native_handle_t native_kernel_handle = 0;
2518
ur_kernel_handle_t native_kernel = nullptr;
19+
// We can't pass isNativeHandleOwned = true in the generic tests since
20+
// we always get the native handle from a UR object, and transferring
21+
// ownership from one UR object to another isn't allowed.
2622
ur_kernel_native_properties_t properties = {
2723
UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES, /*sType*/
2824
nullptr, /*pNext*/
@@ -32,6 +28,17 @@ struct urKernelCreateWithNativeHandleTest : uur::urKernelTest {
3228
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urKernelCreateWithNativeHandleTest);
3329

3430
TEST_P(urKernelCreateWithNativeHandleTest, Success) {
31+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urKernelCreateWithNativeHandle(
32+
native_kernel_handle, context, program, nullptr, &native_kernel));
33+
34+
uint32_t ref_count = 0;
35+
ASSERT_SUCCESS(urKernelGetInfo(native_kernel, UR_KERNEL_INFO_REFERENCE_COUNT,
36+
sizeof(ref_count), &ref_count, nullptr));
37+
38+
ASSERT_NE(ref_count, 0);
39+
}
40+
41+
TEST_P(urKernelCreateWithNativeHandleTest, SuccessWithProperties) {
3542
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urKernelCreateWithNativeHandle(
3643
native_kernel_handle, context, program, &properties, &native_kernel));
3744

test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,29 @@ TEST_P(urMemBufferCreateWithNativeHandleTest, Success) {
3232
ASSERT_SUCCESS(urMemRelease(mem));
3333
}
3434

35-
TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
36-
ur_native_handle_t native_handle = 0;
35+
TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithProperties) {
36+
ur_native_handle_t hNativeMem = 0;
3737
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
38-
urMemGetNativeHandle(buffer, device, &native_handle));
38+
urMemGetNativeHandle(buffer, device, &hNativeMem));
3939

4040
ur_mem_handle_t mem = nullptr;
41+
// We can't pass isNativeHandleOwned = true in the generic tests since
42+
// we always get the native handle from a UR object, and transferring
43+
// ownership from one UR object to another isn't allowed.
4144
ur_mem_native_properties_t props = {
4245
/*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
4346
/*.pNext =*/nullptr,
44-
/*.isNativeHandleOwned =*/true,
47+
/*.isNativeHandleOwned =*/false,
4548
};
46-
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
47-
urMemBufferCreateWithNativeHandle(native_handle, context, &props, &mem));
48-
ASSERT_NE(nullptr, mem);
49+
ASSERT_SUCCESS(
50+
urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, &mem));
51+
ASSERT_NE(mem, nullptr);
4952

50-
ur_context_handle_t mem_context = nullptr;
51-
ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_CONTEXT,
52-
sizeof(ur_context_handle_t), &mem_context,
53-
nullptr));
54-
ASSERT_EQ(context, mem_context);
53+
size_t alloc_size = 0;
54+
ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_SIZE, sizeof(size_t),
55+
&alloc_size, nullptr));
56+
57+
ASSERT_SUCCESS(urMemRelease(mem));
5558
}
5659

5760
TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {

test/conformance/memory/urMemImageCreateWithNativeHandle.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ struct urMemImageCreateWithNativeHandleTest : uur::urMemImageTest {
1616
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemImageCreateWithNativeHandleTest);
1717

1818
TEST_P(urMemImageCreateWithNativeHandleTest, Success) {
19+
<<<<<<< HEAD
1920
UUR_KNOWN_FAILURE_ON(uur::HIP{}, uur::LevelZero{});
21+
=======
22+
ur_native_handle_t native_handle = 0;
23+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
24+
urMemGetNativeHandle(image, device, &native_handle));
25+
>>>>>>> a2dab68a (Update cts tests.)
2026

2127
ur_native_handle_t native_handle = 0;
2228
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
@@ -34,6 +40,28 @@ TEST_P(urMemImageCreateWithNativeHandleTest, Success) {
3440
ASSERT_EQ(context, mem_context);
3541
}
3642

43+
TEST_P(urMemImageCreateWithNativeHandleTest, SuccessWithProperties) {
44+
ur_native_handle_t native_handle = 0;
45+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
46+
urMemGetNativeHandle(image, device, &native_handle));
47+
48+
ur_mem_handle_t mem = nullptr;
49+
ur_mem_native_properties_t props = {UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
50+
nullptr, false};
51+
// We can't pass isNativeHandleOwned = true in the generic tests since
52+
// we always get the native handle from a UR object, and transferring
53+
// ownership from one UR object to another isn't allowed.
54+
ASSERT_SUCCESS(urMemImageCreateWithNativeHandle(
55+
native_handle, context, &image_format, &image_desc, &props, &mem));
56+
ASSERT_NE(nullptr, mem);
57+
58+
ur_context_handle_t mem_context = nullptr;
59+
ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_CONTEXT,
60+
sizeof(ur_context_handle_t), &mem_context,
61+
nullptr));
62+
ASSERT_EQ(context, mem_context);
63+
}
64+
3765
TEST_P(urMemImageCreateWithNativeHandleTest, InvalidNullHandle) {
3866
ur_native_handle_t native_handle = 0;
3967
ASSERT_SUCCESS(urMemGetNativeHandle(image, device, &native_handle));

test/conformance/program/urProgramCreateWithNativeHandle.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ TEST_P(urProgramCreateWithNativeHandleTest, Success) {
4747
ASSERT_NE(ref_count, 0);
4848
}
4949

50+
TEST_P(urProgramCreateWithNativeHandleTest, SuccessWithProperties) {
51+
// We can't pass isNativeHandleOwned = true in the generic tests since
52+
// we always get the native handle from a UR object, and transferring
53+
// ownership from one UR object to another isn't allowed.
54+
ur_program_native_properties_t props = {
55+
UR_STRUCTURE_TYPE_PROGRAM_NATIVE_PROPERTIES, nullptr, false};
56+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urProgramCreateWithNativeHandle(
57+
native_program_handle, context, &props, &native_program));
58+
59+
uint32_t ref_count = 0;
60+
61+
ASSERT_SUCCESS(urProgramGetInfo(native_program,
62+
UR_PROGRAM_INFO_REFERENCE_COUNT,
63+
sizeof(ref_count), &ref_count, nullptr));
64+
65+
ASSERT_NE(ref_count, 0);
66+
}
67+
5068
TEST_P(urProgramCreateWithNativeHandleTest, InvalidNullHandleContext) {
5169
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
5270
urProgramCreateWithNativeHandle(native_program_handle,

test/conformance/queue/urQueueCreateWithNativeHandle.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,34 @@ TEST_P(urQueueCreateWithNativeHandleTest, Success) {
1313

1414
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
1515
urQueueGetNativeHandle(queue, nullptr, &native_handle));
16+
// We cannot assume anything about a native_handle, not even if it's
17+
// `nullptr` since this could be a valid representation within a backend.
18+
// We can however convert the native_handle back into a unified-runtime handle
19+
// and perform some query on it to verify that it works.
20+
ur_queue_handle_t q = nullptr;
21+
ASSERT_SUCCESS(urQueueCreateWithNativeHandle(native_handle, context, device,
22+
nullptr, &q));
23+
ASSERT_NE(q, nullptr);
24+
25+
ur_context_handle_t q_context = nullptr;
26+
ASSERT_SUCCESS(urQueueGetInfo(q, UR_QUEUE_INFO_CONTEXT, sizeof(q_context),
27+
&q_context, nullptr));
28+
ASSERT_EQ(q_context, context);
29+
ASSERT_SUCCESS(urQueueRelease(q));
30+
}
1631

32+
TEST_P(urQueueCreateWithNativeHandleTest, SuccessWithProperties) {
33+
ur_native_handle_t native_handle = 0;
34+
35+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
36+
urQueueGetNativeHandle(queue, nullptr, &native_handle));
1737
// We cannot assume anything about a native_handle, not even if it's
1838
// `nullptr` since this could be a valid representation within a backend.
1939
// We can however convert the native_handle back into a unified-runtime handle
2040
// and perform some query on it to verify that it works.
2141
ur_queue_handle_t q = nullptr;
22-
ur_queue_native_properties_t properties{};
42+
ur_queue_native_properties_t properties = {
43+
UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES, nullptr, false};
2344
ASSERT_SUCCESS(urQueueCreateWithNativeHandle(native_handle, context, device,
2445
&properties, &q));
2546
ASSERT_NE(q, nullptr);

0 commit comments

Comments
 (0)