From e4569679e8fa59b236bce798cce2515bbce4b162 Mon Sep 17 00:00:00 2001 From: Aaron Greig Date: Fri, 11 Oct 2024 16:48:20 +0100 Subject: [PATCH] Update cts tests. --- source/adapters/level_zero/context.cpp | 2 +- source/adapters/level_zero/memory.cpp | 7 ++-- .../urContextCreateWithNativeHandle.cpp | 6 ++-- .../device/urDeviceCreateWithNativeHandle.cpp | 6 ++-- .../event/urEventCreateWithNativeHandle.cpp | 23 +++++++++++++ .../kernel/urKernelCreateWithNativeHandle.cpp | 15 +++++++++ .../urMemBufferCreateWithNativeHandle.cpp | 22 +++++++++++++ .../urMemImageCreateWithNativeHandle.cpp | 33 +++++++++++++++---- .../urPlatformCreateWithNativeHandle.cpp | 10 +++--- .../urProgramCreateWithNativeHandle.cpp | 18 ++++++++++ .../queue/urQueueCreateWithNativeHandle.cpp | 25 +++++++++++++- 11 files changed, 145 insertions(+), 22 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 296e3e98d5..d160c2c795 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -152,7 +152,7 @@ ur_result_t urContextCreateWithNativeHandle( ur_context_handle_t *Context ///< [out] pointer to the handle of the context object created. ) { - bool OwnNativeHandle = Properties->isNativeHandleOwned; + bool OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false; try { ze_context_handle_t ZeContext = reinterpret_cast(NativeContext); diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index bc915517e7..f3640da63a 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -1589,8 +1589,9 @@ ur_result_t urMemImageCreateWithNativeHandle( return Res; } - UR_CALL(createUrMemFromZeImage( - Context, ZeHImage, Properties->isNativeHandleOwned, ZeImageDesc, Mem)); + auto OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false; + UR_CALL(createUrMemFromZeImage(Context, ZeHImage, OwnNativeHandle, + ZeImageDesc, Mem)); return UR_RESULT_SUCCESS; } @@ -1764,7 +1765,7 @@ ur_result_t urMemBufferCreateWithNativeHandle( ur_mem_handle_t *Mem ///< [out] pointer to handle of buffer memory object created. ) { - bool OwnNativeHandle = Properties->isNativeHandleOwned; + bool OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false; std::shared_lock Lock(Context->Mutex); diff --git a/test/conformance/context/urContextCreateWithNativeHandle.cpp b/test/conformance/context/urContextCreateWithNativeHandle.cpp index 198cdf7e74..b7fa7bb4b7 100644 --- a/test/conformance/context/urContextCreateWithNativeHandle.cpp +++ b/test/conformance/context/urContextCreateWithNativeHandle.cpp @@ -32,8 +32,7 @@ TEST_P(urContextCreateWithNativeHandleTest, Success) { ASSERT_SUCCESS(urContextRelease(ctx)); } -TEST_P(urContextCreateWithNativeHandleTest, - SuccessExplicitUnOwnedNativeHandle) { +TEST_P(urContextCreateWithNativeHandleTest, SuccessWithProperties) { ur_native_handle_t native_context = 0; { UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( @@ -41,6 +40,9 @@ TEST_P(urContextCreateWithNativeHandleTest, } ur_context_handle_t ctx = nullptr; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. ur_context_native_properties_t props{ UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES, nullptr, false}; UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urContextCreateWithNativeHandle( diff --git a/test/conformance/device/urDeviceCreateWithNativeHandle.cpp b/test/conformance/device/urDeviceCreateWithNativeHandle.cpp index 4c306619e1..ba1a0f57e7 100644 --- a/test/conformance/device/urDeviceCreateWithNativeHandle.cpp +++ b/test/conformance/device/urDeviceCreateWithNativeHandle.cpp @@ -29,8 +29,7 @@ TEST_F(urDeviceCreateWithNativeHandleTest, Success) { } } -TEST_F(urDeviceCreateWithNativeHandleTest, - SuccessWithExplicitUnOwnedNativeHandle) { +TEST_F(urDeviceCreateWithNativeHandleTest, SuccessWithProperties) { for (auto device : devices) { ur_native_handle_t native_handle = 0; { @@ -39,6 +38,9 @@ TEST_F(urDeviceCreateWithNativeHandleTest, } ur_device_handle_t dev = nullptr; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. ur_device_native_properties_t props{ UR_STRUCTURE_TYPE_DEVICE_NATIVE_PROPERTIES, nullptr, false}; UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urDeviceCreateWithNativeHandle( diff --git a/test/conformance/event/urEventCreateWithNativeHandle.cpp b/test/conformance/event/urEventCreateWithNativeHandle.cpp index 36ff0b44dc..935597d6c3 100644 --- a/test/conformance/event/urEventCreateWithNativeHandle.cpp +++ b/test/conformance/event/urEventCreateWithNativeHandle.cpp @@ -30,3 +30,26 @@ TEST_P(urEventCreateWithNativeHandleTest, Success) { sizeof(ur_execution_info_t), &exec_info, nullptr)); } + +TEST_P(urEventCreateWithNativeHandleTest, SuccessWithProperties) { + ur_native_handle_t native_event = 0; + { + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( + urEventGetNativeHandle(event, &native_event)); + } + + uur::raii::Event evt = nullptr; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. + ur_event_native_properties_t props = { + UR_STRUCTURE_TYPE_EVENT_NATIVE_PROPERTIES, nullptr, false}; + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEventCreateWithNativeHandle( + native_event, context, &props, evt.ptr())); + ASSERT_NE(evt, nullptr); + + ur_execution_info_t exec_info; + ASSERT_SUCCESS(urEventGetInfo(evt, UR_EVENT_INFO_COMMAND_EXECUTION_STATUS, + sizeof(ur_execution_info_t), &exec_info, + nullptr)); +} diff --git a/test/conformance/kernel/urKernelCreateWithNativeHandle.cpp b/test/conformance/kernel/urKernelCreateWithNativeHandle.cpp index 8640463334..6b90d5f005 100644 --- a/test/conformance/kernel/urKernelCreateWithNativeHandle.cpp +++ b/test/conformance/kernel/urKernelCreateWithNativeHandle.cpp @@ -23,6 +23,9 @@ struct urKernelCreateWithNativeHandleTest : uur::urKernelTest { ur_native_handle_t native_kernel_handle = 0; ur_kernel_handle_t native_kernel = nullptr; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. ur_kernel_native_properties_t properties = { UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES, /*sType*/ nullptr, /*pNext*/ @@ -32,6 +35,18 @@ struct urKernelCreateWithNativeHandleTest : uur::urKernelTest { UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urKernelCreateWithNativeHandleTest); TEST_P(urKernelCreateWithNativeHandleTest, Success) { + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urKernelCreateWithNativeHandle( + native_kernel_handle, context, program, nullptr, &native_kernel)); + + uint32_t ref_count = 0; + ASSERT_SUCCESS(urKernelGetInfo(native_kernel, + UR_KERNEL_INFO_REFERENCE_COUNT, + sizeof(ref_count), &ref_count, nullptr)); + + ASSERT_NE(ref_count, 0); +} + +TEST_P(urKernelCreateWithNativeHandleTest, SuccessWithProperties) { UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urKernelCreateWithNativeHandle( native_kernel_handle, context, program, &properties, &native_kernel)); diff --git a/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp b/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp index 80afbd5f7c..56a4089cba 100644 --- a/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp +++ b/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp @@ -20,6 +20,28 @@ TEST_P(urMemBufferCreateWithNativeHandleTest, Success) { // We can however convert the native_handle back into a unified-runtime handle // and perform some query on it to verify that it works. ur_mem_handle_t mem = nullptr; + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( + urMemBufferCreateWithNativeHandle(hNativeMem, context, nullptr, &mem)); + ASSERT_NE(mem, nullptr); + + size_t alloc_size = 0; + ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_SIZE, sizeof(size_t), + &alloc_size, nullptr)); + + ASSERT_SUCCESS(urMemRelease(mem)); +} + +TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithProperties) { + ur_native_handle_t hNativeMem = 0; + { + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( + urMemGetNativeHandle(buffer, device, &hNativeMem)); + } + + ur_mem_handle_t mem = nullptr; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. ur_mem_native_properties_t props = { /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, /*.pNext =*/nullptr, diff --git a/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp b/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp index 3404b4203f..95fc4a2bd5 100644 --- a/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp +++ b/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp @@ -10,15 +10,34 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemImageCreateWithNativeHandleTest); TEST_P(urMemImageCreateWithNativeHandleTest, Success) { ur_native_handle_t native_handle = 0; - if (urMemGetNativeHandle(image, device, &native_handle)) { - GTEST_SKIP(); - } + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( + urMemGetNativeHandle(image, device, &native_handle)); ur_mem_handle_t mem = nullptr; - ASSERT_EQ_RESULT( - UR_RESULT_ERROR_INVALID_NULL_HANDLE, - urMemImageCreateWithNativeHandle(native_handle, context, &image_format, - &image_desc, nullptr, &mem)); + ASSERT_SUCCESS(urMemImageCreateWithNativeHandle( + native_handle, context, &image_format, &image_desc, nullptr, &mem)); + ASSERT_NE(nullptr, mem); + + ur_context_handle_t mem_context = nullptr; + ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_CONTEXT, + sizeof(ur_context_handle_t), &mem_context, + nullptr)); + ASSERT_EQ(context, mem_context); +} + +TEST_P(urMemImageCreateWithNativeHandleTest, SuccessWithProperties) { + ur_native_handle_t native_handle = 0; + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( + urMemGetNativeHandle(image, device, &native_handle)); + + ur_mem_handle_t mem = nullptr; + ur_mem_native_properties_t props = {UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, + nullptr, false}; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. + ASSERT_SUCCESS(urMemImageCreateWithNativeHandle( + native_handle, context, &image_format, &image_desc, &props, &mem)); ASSERT_NE(nullptr, mem); ur_context_handle_t mem_context = nullptr; diff --git a/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp b/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp index 1b7980ff04..61d9775394 100644 --- a/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp +++ b/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp @@ -30,8 +30,7 @@ TEST_F(urPlatformCreateWithNativeHandleTest, Success) { } } -TEST_F(urPlatformCreateWithNativeHandleTest, - SuccessWithExplicitUnOwnedNativeHandle) { +TEST_F(urPlatformCreateWithNativeHandleTest, SuccessWithProperties) { for (auto platform : platforms) { ur_native_handle_t native_handle = 0; { @@ -39,10 +38,9 @@ TEST_F(urPlatformCreateWithNativeHandleTest, urPlatformGetNativeHandle(platform, &native_handle)); } - // We cannot assume anything about a native_handle, not even if it's - // `nullptr` since this could be a valid representation within a backend. - // We can however convert the native_handle back into a unified-runtime - // handle and perform some query on it to verify that it works. + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. ur_platform_native_properties_t props = { UR_STRUCTURE_TYPE_PLATFORM_NATIVE_PROPERTIES, nullptr, false}; ur_platform_handle_t plat = nullptr; diff --git a/test/conformance/program/urProgramCreateWithNativeHandle.cpp b/test/conformance/program/urProgramCreateWithNativeHandle.cpp index ddf3767e43..ddecb2822b 100644 --- a/test/conformance/program/urProgramCreateWithNativeHandle.cpp +++ b/test/conformance/program/urProgramCreateWithNativeHandle.cpp @@ -38,6 +38,24 @@ TEST_P(urProgramCreateWithNativeHandleTest, Success) { ASSERT_NE(ref_count, 0); } +TEST_P(urProgramCreateWithNativeHandleTest, SuccessWithProperties) { + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. + ur_program_native_properties_t props = { + UR_STRUCTURE_TYPE_PROGRAM_NATIVE_PROPERTIES, nullptr, false}; + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urProgramCreateWithNativeHandle( + native_program_handle, context, &props, &native_program)); + + uint32_t ref_count = 0; + + ASSERT_SUCCESS(urProgramGetInfo(native_program, + UR_PROGRAM_INFO_REFERENCE_COUNT, + sizeof(ref_count), &ref_count, nullptr)); + + ASSERT_NE(ref_count, 0); +} + TEST_P(urProgramCreateWithNativeHandleTest, InvalidNullHandleContext) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, urProgramCreateWithNativeHandle(native_program_handle, diff --git a/test/conformance/queue/urQueueCreateWithNativeHandle.cpp b/test/conformance/queue/urQueueCreateWithNativeHandle.cpp index f2fa83ec8e..d22f18a8b5 100644 --- a/test/conformance/queue/urQueueCreateWithNativeHandle.cpp +++ b/test/conformance/queue/urQueueCreateWithNativeHandle.cpp @@ -19,7 +19,30 @@ TEST_P(urQueueCreateWithNativeHandleTest, Success) { // We can however convert the native_handle back into a unified-runtime handle // and perform some query on it to verify that it works. ur_queue_handle_t q = nullptr; - ur_queue_native_properties_t properties{}; + ASSERT_SUCCESS(urQueueCreateWithNativeHandle(native_handle, context, device, + nullptr, &q)); + ASSERT_NE(q, nullptr); + + ur_context_handle_t q_context = nullptr; + ASSERT_SUCCESS(urQueueGetInfo(q, UR_QUEUE_INFO_CONTEXT, sizeof(q_context), + &q_context, nullptr)); + ASSERT_EQ(q_context, context); + ASSERT_SUCCESS(urQueueRelease(q)); +} + +TEST_P(urQueueCreateWithNativeHandleTest, SuccessWithProperties) { + ur_native_handle_t native_handle = 0; + { + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( + urQueueGetNativeHandle(queue, nullptr, &native_handle)); + } + + ur_queue_handle_t q = nullptr; + // We can't pass isNativeHandleOwned = true in the generic tests since + // we always get the native handle from a UR object, and transferring + // ownership from one UR object to another isn't allowed. + ur_queue_native_properties_t properties = { + UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES, nullptr, false}; ASSERT_SUCCESS(urQueueCreateWithNativeHandle(native_handle, context, device, &properties, &q)); ASSERT_NE(q, nullptr);