Skip to content

Commit

Permalink
Update cts tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongreig committed Oct 14, 2024
1 parent 6f0c6f3 commit e456967
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 22 deletions.
2 changes: 1 addition & 1 deletion source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ze_context_handle_t>(NativeContext);
Expand Down
7 changes: 4 additions & 3 deletions source/adapters/level_zero/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<ur_shared_mutex> Lock(Context->Mutex);

Expand Down
6 changes: 4 additions & 2 deletions test/conformance/context/urContextCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ 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(
urContextGetNativeHandle(context, &native_context));
}

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(
Expand Down
6 changes: 4 additions & 2 deletions test/conformance/device/urDeviceCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
{
Expand All @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions test/conformance/event/urEventCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
15 changes: 15 additions & 0 deletions test/conformance/kernel/urKernelCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand All @@ -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));

Expand Down
22 changes: 22 additions & 0 deletions test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 26 additions & 7 deletions test/conformance/memory/urMemImageCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions test/conformance/platform/urPlatformCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ TEST_F(urPlatformCreateWithNativeHandleTest, Success) {
}
}

TEST_F(urPlatformCreateWithNativeHandleTest,
SuccessWithExplicitUnOwnedNativeHandle) {
TEST_F(urPlatformCreateWithNativeHandleTest, SuccessWithProperties) {
for (auto platform : platforms) {
ur_native_handle_t native_handle = 0;
{
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
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;
Expand Down
18 changes: 18 additions & 0 deletions test/conformance/program/urProgramCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 24 additions & 1 deletion test/conformance/queue/urQueueCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e456967

Please sign in to comment.