Skip to content

Commit 690fef3

Browse files
committed
Merge branch 'aaron/clRetainNativeHandles' into aaron/clCTSFixMegaBranch
2 parents 42d00cd + 371e1b8 commit 690fef3

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

source/adapters/opencl/event.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ convertURProfilingInfoToCL(const ur_profiling_info_t PropName) {
5454
}
5555
}
5656

57-
UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
58-
ur_native_handle_t hNativeEvent,
59-
[[maybe_unused]] ur_context_handle_t hContext,
60-
[[maybe_unused]] const ur_event_native_properties_t *pProperties,
61-
ur_event_handle_t *phEvent) {
57+
UR_APIEXPORT ur_result_t UR_APICALL
58+
urEventCreateWithNativeHandle(ur_native_handle_t hNativeEvent,
59+
[[maybe_unused]] ur_context_handle_t hContext,
60+
const ur_event_native_properties_t *pProperties,
61+
ur_event_handle_t *phEvent) {
6262
*phEvent = reinterpret_cast<ur_event_handle_t>(hNativeEvent);
63+
if (!pProperties || !pProperties->isNativeHandleOwned) {
64+
return urEventRetain(*phEvent);
65+
}
6366
return UR_RESULT_SUCCESS;
6467
}
6568

source/adapters/opencl/kernel.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetNativeHandle(
336336

337337
UR_APIEXPORT ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
338338
ur_native_handle_t hNativeKernel, ur_context_handle_t, ur_program_handle_t,
339-
const ur_kernel_native_properties_t *, ur_kernel_handle_t *phKernel) {
340-
339+
const ur_kernel_native_properties_t *pProperties,
340+
ur_kernel_handle_t *phKernel) {
341341
*phKernel = reinterpret_cast<ur_kernel_handle_t>(hNativeKernel);
342+
if (!pProperties || !pProperties->isNativeHandleOwned) {
343+
return urKernelRetain(*phKernel);
344+
}
342345
return UR_RESULT_SUCCESS;
343346
}
344347

source/adapters/opencl/memory.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,11 @@ urMemGetNativeHandle(ur_mem_handle_t hMem, ur_native_handle_t *phNativeMem) {
332332
UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle(
333333
ur_native_handle_t hNativeMem,
334334
[[maybe_unused]] ur_context_handle_t hContext,
335-
[[maybe_unused]] const ur_mem_native_properties_t *pProperties,
336-
ur_mem_handle_t *phMem) {
337-
335+
const ur_mem_native_properties_t *pProperties, ur_mem_handle_t *phMem) {
338336
*phMem = reinterpret_cast<ur_mem_handle_t>(hNativeMem);
337+
if (!pProperties || !pProperties->isNativeHandleOwned) {
338+
return urMemRetain(*phMem);
339+
}
339340
return UR_RESULT_SUCCESS;
340341
}
341342

@@ -344,10 +345,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreateWithNativeHandle(
344345
[[maybe_unused]] ur_context_handle_t hContext,
345346
[[maybe_unused]] const ur_image_format_t *pImageFormat,
346347
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
347-
[[maybe_unused]] const ur_mem_native_properties_t *pProperties,
348-
ur_mem_handle_t *phMem) {
349-
348+
const ur_mem_native_properties_t *pProperties, ur_mem_handle_t *phMem) {
350349
*phMem = reinterpret_cast<ur_mem_handle_t>(hNativeMem);
350+
if (!pProperties || !pProperties->isNativeHandleOwned) {
351+
return urMemRetain(*phMem);
352+
}
351353
return UR_RESULT_SUCCESS;
352354
}
353355

source/adapters/opencl/program.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetNativeHandle(
299299

300300
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithNativeHandle(
301301
ur_native_handle_t hNativeProgram, ur_context_handle_t,
302-
const ur_program_native_properties_t *, ur_program_handle_t *phProgram) {
303-
302+
const ur_program_native_properties_t *pProperties,
303+
ur_program_handle_t *phProgram) {
304304
*phProgram = reinterpret_cast<ur_program_handle_t>(hNativeProgram);
305+
if (!pProperties || !pProperties->isNativeHandleOwned) {
306+
return urProgramRetain(*phProgram);
307+
}
305308
return UR_RESULT_SUCCESS;
306309
}
307310

0 commit comments

Comments
 (0)