Skip to content

Commit

Permalink
Update cts tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongreig committed Nov 8, 2024
1 parent aa8042c commit 016ec39
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 41 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
5 changes: 3 additions & 2 deletions source/adapters/level_zero/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,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
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
3 changes: 0 additions & 3 deletions test/conformance/memory/memory_adapter_cuda.match
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
urMemImageCreateTest.InvalidSize/NVIDIA_CUDA_BACKEND___{{.*}}_
{{OPT}}urMemImageCremBufferCrateTestWith1DMemoryTypeParam.Success/NVIDIA_CUDA_BACKEND___{{.*}}___UR_MEM_TYPE_IMAGE1D_ARRAY
{{OPT}}urMemImageCreateTestWith2DMemoryTypeParam.Success/NVIDIA_CUDA_BACKEND___{{.*}}___UR_MEM_TYPE_IMAGE2D_ARRAY
urMemBufferCreateWithNativeHandleTest.Success/NVIDIA_CUDA_BACKEND___{{.*}}
urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/NVIDIA_CUDA_BACKEND___{{.*}}
urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/NVIDIA_CUDA_BACKEND___{{.*}}
4 changes: 0 additions & 4 deletions test/conformance/memory/memory_adapter_hip.match
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
urMemImageCreateTest.InvalidSize/AMD_HIP_BACKEND___{{.*}}
urMemImageGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}}
urMemImageGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}}
urMemBufferCreateWithNativeHandleTest.Success/AMD_HIP_BACKEND___{{.*}}
urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/AMD_HIP_BACKEND___{{.*}}
urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/AMD_HIP_BACKEND___{{.*}}
urMemImageCreateWithNativeHandleTest.Success/AMD_HIP_BACKEND___{{.*}}
1 change: 0 additions & 1 deletion test/conformance/memory/memory_adapter_level_zero.match
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_L
urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__UR_MEM_FLAG_READ_ONLY
urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urMemImageCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}
{{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_SIZE
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_RGBA__UR_IMAGE_CHANNEL_TYPE_SNORM_INT8
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_RGBA__UR_IMAGE_CHANNEL_TYPE_SNORM_INT16
Expand Down
5 changes: 0 additions & 5 deletions test/conformance/memory/memory_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,3 @@ urMemReleaseTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemRetainTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemReleaseTest.CheckReferenceCount/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemRetainTest.CheckReferenceCount/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemBufferCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemBufferCreateWithNativeHandleTest.InvalidNullHandle/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urMemBufferCreateWithNativeHandleTest.InvalidNullPointer/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
29 changes: 16 additions & 13 deletions test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateWithNativeHandleTest);

TEST_P(urMemBufferCreateWithNativeHandleTest, Success) {
ur_native_handle_t hNativeMem = 0;
ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &hNativeMem));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urMemGetNativeHandle(buffer, device, &hNativeMem));

// We cannot assume anything about a native_handle, not even if it's
// `nullptr` since this could be a valid representation within a backend.
Expand All @@ -29,25 +29,28 @@ TEST_P(urMemBufferCreateWithNativeHandleTest, Success) {
ASSERT_SUCCESS(urMemRelease(mem));
}

TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
ur_native_handle_t native_handle = 0;
ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &native_handle));
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,
/*.isNativeHandleOwned =*/true,
/*.isNativeHandleOwned =*/false,
};
ASSERT_SUCCESS(urMemBufferCreateWithNativeHandle(native_handle, context,
&props, &mem));
ASSERT_NE(nullptr, mem);
ASSERT_SUCCESS(
urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, &mem));
ASSERT_NE(mem, nullptr);

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);
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, SuccessWithUnOwnedNativeHandle) {
Expand Down
24 changes: 23 additions & 1 deletion test/conformance/memory/urMemImageCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemImageCreateWithNativeHandleTest);

TEST_P(urMemImageCreateWithNativeHandleTest, Success) {
ur_native_handle_t native_handle = 0;
ASSERT_SUCCESS(urMemGetNativeHandle(image, device, &native_handle));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urMemGetNativeHandle(image, device, &native_handle));

ur_mem_handle_t mem = nullptr;
ASSERT_SUCCESS(urMemImageCreateWithNativeHandle(
Expand All @@ -24,6 +24,28 @@ TEST_P(urMemImageCreateWithNativeHandleTest, Success) {
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;
ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_CONTEXT,
sizeof(ur_context_handle_t), &mem_context,
nullptr));
ASSERT_EQ(context, mem_context);
}

TEST_P(urMemImageCreateWithNativeHandleTest, InvalidNullHandle) {
ur_native_handle_t native_handle = 0;
ASSERT_SUCCESS(urMemGetNativeHandle(image, device, &native_handle));
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 @@ -46,6 +46,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 016ec39

Please sign in to comment.