Skip to content

Commit

Permalink
Fix CTS tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongreig committed Nov 8, 2024
1 parent 016ec39 commit 6664a86
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 60 deletions.
18 changes: 3 additions & 15 deletions scripts/core/PROG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,6 @@ ${x}QueueRetain. An application must call ${x}QueueRelease
when a queue object is no longer needed. When a queue object's reference count becomes
zero, it is deleted by the runtime.

Native Driver Access
----------------------------------

The runtime API provides accessors for native handles.
For example, given a ${x}_program_handle_t, we can
call ${x}ProgramGetNativeHandle to retrieve a ${x}_native_handle_t.
We can then leverage a platform extension to convert the
native handle to a driver handle. For example, OpenCL platform
may expose an extension ${x}ProgramCreateWithNativeHandle to retrieve
a cl_program.

Memory
======

Expand Down Expand Up @@ -343,10 +332,9 @@ Native Handle Ownership
-----------------------

By default a ${X} object constructed from a native handle doesn't own the
native handle, it is guaranteed not to modify the native handle's reference
count or otherwise cause its resources to be released. A ${X} object that
doesn't own its associated native handle **must** be destroyed before the
native handle is.
native handle, it is guaranteed not to retain a reference to the native handle,
or cause its resources to be released. A ${X} object that doesn't own its
associated native handle **must** be destroyed before the native handle is.

Ownership of the native handle can be tranferred to the ${X} object by passing
``isNativeHandleOwned = true`` in the native properties struct when calling the
Expand Down
20 changes: 11 additions & 9 deletions source/adapters/cuda/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
std::vector<CUstream> ComputeCuStreams(1, CuStream);
std::vector<CUstream> TransferCuStreams(0);

auto isNativeHandleOwned =
pProperties ? pProperties->isNativeHandleOwned : false;

// Create queue and set num_compute_streams to 1, as computeCuStreams has
// valid stream
*phQueue =
new ur_queue_handle_t_{std::move(ComputeCuStreams),
std::move(TransferCuStreams),
hContext,
hDevice,
CuFlags,
Flags,
/*priority*/ 0,
/*backend_owns*/ pProperties->isNativeHandleOwned};
*phQueue = new ur_queue_handle_t_{std::move(ComputeCuStreams),
std::move(TransferCuStreams),
hContext,
hDevice,
CuFlags,
Flags,
/*priority*/ 0,
/*backend_owns*/ isNativeHandleOwned};
(*phQueue)->NumComputeStreams = 1;

return UR_RESULT_SUCCESS;
Expand Down
3 changes: 3 additions & 0 deletions source/adapters/hip/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ UR_APIEXPORT ur_result_t UR_APICALL
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
ur_native_handle_t *phNativeMem) {
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
if (hMem->isImage()) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
#if defined(__HIP_PLATFORM_NVIDIA__)
if (sizeof(BufferMem::native_type) > sizeof(ur_native_handle_t)) {
// Check that all the upper bits that cannot be represented by
Expand Down
20 changes: 11 additions & 9 deletions source/adapters/hip/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
std::vector<hipStream_t> ComputeHIPStreams(1, HIPStream);
std::vector<hipStream_t> TransferHIPStreams(0);

auto isNativeHandleOwned =
pProperties ? pProperties->isNativeHandleOwned : false;

// Create queue and set num_compute_streams to 1, as computeHIPStreams has
// valid stream
*phQueue =
new ur_queue_handle_t_{std::move(ComputeHIPStreams),
std::move(TransferHIPStreams),
hContext,
hDevice,
HIPFlags,
Flags,
/*priority*/ 0,
/*backend_owns*/ pProperties->isNativeHandleOwned};
*phQueue = new ur_queue_handle_t_{std::move(ComputeHIPStreams),
std::move(TransferHIPStreams),
hContext,
hDevice,
HIPFlags,
Flags,
/*priority*/ 0,
/*backend_owns*/ isNativeHandleOwned};
(*phQueue)->NumComputeStreams = 1;

return UR_RESULT_SUCCESS;
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,9 @@ ur_result_t urKernelCreateWithNativeHandle(
ze_kernel_handle_t ZeKernel = ur_cast<ze_kernel_handle_t>(NativeKernel);
ur_kernel_handle_t_ *Kernel = nullptr;
try {
Kernel = new ur_kernel_handle_t_(ZeKernel, Properties->isNativeHandleOwned,
Context);
if (Properties->isNativeHandleOwned) {
auto OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false;
Kernel = new ur_kernel_handle_t_(ZeKernel, OwnNativeHandle, Context);
if (OwnNativeHandle) {
// If ownership is passed to the adapter we need to pass the kernel
// to this vector which is then used during ZeKernelRelease.
Kernel->ZeKernels.push_back(ZeKernel);
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/level_zero/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ ur_result_t urProgramGetNativeHandle(
}
}
if (!Module)
return UR_RESULT_ERROR_INVALID_OPERATION;
// L0 only supprts returning native handle from built programs.
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;

*ZeModule = Module;
return UR_RESULT_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions source/adapters/opencl/ur_interface_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ urGetMemProcAddrTable(ur_api_version_t Version, ur_mem_dditable_t *pDdiTable) {
pDdiTable->pfnGetNativeHandle = urMemGetNativeHandle;
pDdiTable->pfnImageCreate = urMemImageCreate;
pDdiTable->pfnImageGetInfo = urMemImageGetInfo;
pDdiTable->pfnImageCreateWithNativeHandle = urMemImageCreateWithNativeHandle;
pDdiTable->pfnRelease = urMemRelease;
pDdiTable->pfnRetain = urMemRetain;
return UR_RESULT_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions test/conformance/event/event_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ urEventReleaseTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventGetNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventGetNativeHandleTest.InvalidNullPointerNativeEvent/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventCreateWithNativeHandleTest.SuccessWithProperties/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventSetCallbackTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventSetCallbackTest.ValidateParameters/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urEventSetCallbackTest.AllStates/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
Expand Down
1 change: 1 addition & 0 deletions test/conformance/kernel/kernel_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ urKernelCreateTest.InvalidNullPointerName/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.
urKernelCreateTest.InvalidNullPointerKernel/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urKernelCreateTest.InvalidKernelName/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urKernelCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urKernelCreateWithNativeHandleTest.SuccessWithProperties/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urKernelCreateWithNativeHandleTest.InvalidNullHandleContext/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urKernelCreateWithNativeHandleTest.InvalidNullPointerNativeKernel/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
urKernelGetGroupInfoTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE
Expand Down
2 changes: 2 additions & 0 deletions test/conformance/memory/memory_adapter_level_zero_v2.match
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_SRGBA__UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_SRGBA__UR_IMAGE_CHANNEL_TYPE_HALF_FLOAT
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_SRGBA__UR_IMAGE_CHANNEL_TYPE_FLOAT
{{OPT}}urMemImageCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}
{{OPT}}urMemImageCreateWithNativeHandleTest.SuccessWithProperties/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}
{{OPT}}urMemImageGetInfoTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_FORMAT
{{OPT}}urMemImageGetInfoTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_ELEMENT_SIZE
{{OPT}}urMemImageGetInfoTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_ROW_PITCH
Expand Down
25 changes: 2 additions & 23 deletions test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,9 @@ TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithProperties) {
ASSERT_SUCCESS(urMemRelease(mem));
}

TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {
ur_native_handle_t native_handle = 0;
ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &native_handle));

ur_mem_handle_t mem = nullptr;
ur_mem_native_properties_t props = {
/*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
/*.pNext =*/nullptr,
/*.isNativeHandleOwned =*/false,
};
ASSERT_SUCCESS(urMemBufferCreateWithNativeHandle(native_handle, context,
&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(urMemBufferCreateWithNativeHandleTest, InvalidNullHandle) {
ur_native_handle_t hNativeMem = 0;
ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &hNativeMem));
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urMemGetNativeHandle(buffer, device, &hNativeMem));

ur_mem_handle_t mem = nullptr;
ur_mem_native_properties_t props = {
Expand All @@ -91,7 +70,7 @@ TEST_P(urMemBufferCreateWithNativeHandleTest, InvalidNullHandle) {

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

ur_mem_native_properties_t props = {
/*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
Expand Down
1 change: 1 addition & 0 deletions test/conformance/program/program_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{{OPT}}urProgramCreateWithILTest.InvalidNullPointerProgram/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urProgramCreateWithILTest.BuildInvalidProgram/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urProgramCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urProgramCreateWithNativeHandleTest.SuccessWithProperties/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urProgramCreateWithNativeHandleTest.InvalidNullHandleContext/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urProgramCreateWithNativeHandleTest.InvalidNullPointerProgram/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}
{{OPT}}urProgramGetBuildInfoTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_PROGRAM_BUILD_INFO_STATUS
Expand Down

0 comments on commit 6664a86

Please sign in to comment.