Skip to content

Commit c8b8a3e

Browse files
committed
Fix CTS tests.
1 parent 3a1a3e4 commit c8b8a3e

File tree

8 files changed

+34
-44
lines changed

8 files changed

+34
-44
lines changed

scripts/core/PROG.rst

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,6 @@ ${x}QueueRetain. An application must call ${x}QueueRelease
287287
when a queue object is no longer needed. When a queue object's reference count becomes
288288
zero, it is deleted by the runtime.
289289

290-
Native Driver Access
291-
----------------------------------
292-
293-
The runtime API provides accessors for native handles.
294-
For example, given a ${x}_program_handle_t, we can
295-
call ${x}ProgramGetNativeHandle to retrieve a ${x}_native_handle_t.
296-
We can then leverage a platform extension to convert the
297-
native handle to a driver handle. For example, OpenCL platform
298-
may expose an extension ${x}ProgramCreateWithNativeHandle to retrieve
299-
a cl_program.
300-
301290
Memory
302291
======
303292

@@ -361,10 +350,9 @@ Native Handle Ownership
361350
-----------------------
362351

363352
By default a ${X} object constructed from a native handle doesn't own the
364-
native handle, it is guaranteed not to modify the native handle's reference
365-
count or otherwise cause its resources to be released. A ${X} object that
366-
doesn't own its associated native handle **must** be destroyed before the
367-
native handle is.
353+
native handle, it is guaranteed not to retain a reference to the native handle,
354+
or cause its resources to be released. A ${X} object that doesn't own its
355+
associated native handle **must** be destroyed before the native handle is.
368356

369357
Ownership of the native handle can be tranferred to the ${X} object by passing
370358
``isNativeHandleOwned = true`` in the native properties struct when calling the

source/adapters/cuda/queue.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
284284
std::vector<CUstream> ComputeCuStreams(1, CuStream);
285285
std::vector<CUstream> TransferCuStreams(0);
286286

287+
auto isNativeHandleOwned =
288+
pProperties ? pProperties->isNativeHandleOwned : false;
289+
287290
// Create queue and set num_compute_streams to 1, as computeCuStreams has
288291
// valid stream
289-
*phQueue =
290-
new ur_queue_handle_t_{std::move(ComputeCuStreams),
291-
std::move(TransferCuStreams),
292-
hContext,
293-
hDevice,
294-
CuFlags,
295-
Flags,
296-
/*priority*/ 0,
297-
/*backend_owns*/ pProperties->isNativeHandleOwned};
292+
*phQueue = new ur_queue_handle_t_{std::move(ComputeCuStreams),
293+
std::move(TransferCuStreams),
294+
hContext,
295+
hDevice,
296+
CuFlags,
297+
Flags,
298+
/*priority*/ 0,
299+
/*backend_owns*/ isNativeHandleOwned};
298300
(*phQueue)->NumComputeStreams = 1;
299301

300302
return UR_RESULT_SUCCESS;

source/adapters/hip/memory.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ UR_APIEXPORT ur_result_t UR_APICALL
302302
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
303303
ur_native_handle_t *phNativeMem) {
304304
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
305+
if (hMem->isImage()) {
306+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
307+
}
305308
#if defined(__HIP_PLATFORM_NVIDIA__)
306309
if (sizeof(BufferMem::native_type) > sizeof(ur_native_handle_t)) {
307310
// Check that all the upper bits that cannot be represented by

source/adapters/hip/queue.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
318318
std::vector<hipStream_t> ComputeHIPStreams(1, HIPStream);
319319
std::vector<hipStream_t> TransferHIPStreams(0);
320320

321+
auto isNativeHandleOwned =
322+
pProperties ? pProperties->isNativeHandleOwned : false;
323+
321324
// Create queue and set num_compute_streams to 1, as computeHIPStreams has
322325
// valid stream
323-
*phQueue =
324-
new ur_queue_handle_t_{std::move(ComputeHIPStreams),
325-
std::move(TransferHIPStreams),
326-
hContext,
327-
hDevice,
328-
HIPFlags,
329-
Flags,
330-
/*priority*/ 0,
331-
/*backend_owns*/ pProperties->isNativeHandleOwned};
326+
*phQueue = new ur_queue_handle_t_{std::move(ComputeHIPStreams),
327+
std::move(TransferHIPStreams),
328+
hContext,
329+
hDevice,
330+
HIPFlags,
331+
Flags,
332+
/*priority*/ 0,
333+
/*backend_owns*/ isNativeHandleOwned};
332334
(*phQueue)->NumComputeStreams = 1;
333335

334336
return UR_RESULT_SUCCESS;

source/adapters/level_zero/kernel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,9 @@ ur_result_t urKernelCreateWithNativeHandle(
11181118
ze_kernel_handle_t ZeKernel = ur_cast<ze_kernel_handle_t>(NativeKernel);
11191119
ur_kernel_handle_t_ *Kernel = nullptr;
11201120
try {
1121-
Kernel = new ur_kernel_handle_t_(ZeKernel, Properties->isNativeHandleOwned,
1122-
Context);
1123-
if (Properties->isNativeHandleOwned) {
1121+
auto OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false;
1122+
Kernel = new ur_kernel_handle_t_(ZeKernel, OwnNativeHandle, Context);
1123+
if (OwnNativeHandle) {
11241124
// If ownership is passed to the adapter we need to pass the kernel
11251125
// to this vector which is then used during ZeKernelRelease.
11261126
Kernel->ZeKernels.push_back(ZeKernel);

source/adapters/level_zero/program.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@ ur_result_t urProgramGetNativeHandle(
937937
}
938938
}
939939
if (!Module)
940-
return UR_RESULT_ERROR_INVALID_OPERATION;
940+
// L0 only supprts returning native handle from built programs.
941+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
941942

942943
*ZeModule = Module;
943944
return UR_RESULT_SUCCESS;

source/adapters/opencl/ur_interface_loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ urGetMemProcAddrTable(ur_api_version_t Version, ur_mem_dditable_t *pDdiTable) {
159159
pDdiTable->pfnGetNativeHandle = urMemGetNativeHandle;
160160
pDdiTable->pfnImageCreate = urMemImageCreate;
161161
pDdiTable->pfnImageGetInfo = urMemImageGetInfo;
162+
pDdiTable->pfnImageCreateWithNativeHandle = urMemImageCreateWithNativeHandle;
162163
pDdiTable->pfnRelease = urMemRelease;
163164
pDdiTable->pfnRetain = urMemRetain;
164165
return UR_RESULT_SUCCESS;

test/conformance/memory/urMemImageCreateWithNativeHandle.cpp

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

1818
TEST_P(urMemImageCreateWithNativeHandleTest, Success) {
19-
<<<<<<< HEAD
2019
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.)
26-
2720
ur_native_handle_t native_handle = 0;
2821
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
2922
urMemGetNativeHandle(image, device, &native_handle));

0 commit comments

Comments
 (0)