Skip to content

Commit 371e1b8

Browse files
committed
[OpenCL] Retain native handle objects when properties dictate.
1 parent 55d432c commit 371e1b8

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
@@ -50,12 +50,15 @@ convertURProfilingInfoToCL(const ur_profiling_info_t PropName) {
5050
}
5151
}
5252

53-
UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
54-
ur_native_handle_t hNativeEvent,
55-
[[maybe_unused]] ur_context_handle_t hContext,
56-
[[maybe_unused]] const ur_event_native_properties_t *pProperties,
57-
ur_event_handle_t *phEvent) {
53+
UR_APIEXPORT ur_result_t UR_APICALL
54+
urEventCreateWithNativeHandle(ur_native_handle_t hNativeEvent,
55+
[[maybe_unused]] ur_context_handle_t hContext,
56+
const ur_event_native_properties_t *pProperties,
57+
ur_event_handle_t *phEvent) {
5858
*phEvent = reinterpret_cast<ur_event_handle_t>(hNativeEvent);
59+
if (!pProperties || !pProperties->isNativeHandleOwned) {
60+
return urEventRetain(*phEvent);
61+
}
5962
return UR_RESULT_SUCCESS;
6063
}
6164

source/adapters/opencl/kernel.cpp

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

336336
UR_APIEXPORT ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
337337
ur_native_handle_t hNativeKernel, ur_context_handle_t, ur_program_handle_t,
338-
const ur_kernel_native_properties_t *, ur_kernel_handle_t *phKernel) {
339-
338+
const ur_kernel_native_properties_t *pProperties,
339+
ur_kernel_handle_t *phKernel) {
340340
*phKernel = reinterpret_cast<ur_kernel_handle_t>(hNativeKernel);
341+
if (!pProperties || !pProperties->isNativeHandleOwned) {
342+
return urKernelRetain(*phKernel);
343+
}
341344
return UR_RESULT_SUCCESS;
342345
}
343346

source/adapters/opencl/memory.cpp

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

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

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)