Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenCL] Retain native handle objects when properties dictate. #1024

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions source/adapters/opencl/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ convertURProfilingInfoToCL(const ur_profiling_info_t PropName) {
}
}

UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
ur_native_handle_t hNativeEvent,
[[maybe_unused]] ur_context_handle_t hContext,
[[maybe_unused]] const ur_event_native_properties_t *pProperties,
ur_event_handle_t *phEvent) {
UR_APIEXPORT ur_result_t UR_APICALL
urEventCreateWithNativeHandle(ur_native_handle_t hNativeEvent,
[[maybe_unused]] ur_context_handle_t hContext,
const ur_event_native_properties_t *pProperties,
ur_event_handle_t *phEvent) {
*phEvent = reinterpret_cast<ur_event_handle_t>(hNativeEvent);
if (!pProperties || !pProperties->isNativeHandleOwned) {
return urEventRetain(*phEvent);
}
return UR_RESULT_SUCCESS;
}

Expand Down
7 changes: 5 additions & 2 deletions source/adapters/opencl/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetNativeHandle(

UR_APIEXPORT ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
ur_native_handle_t hNativeKernel, ur_context_handle_t, ur_program_handle_t,
const ur_kernel_native_properties_t *, ur_kernel_handle_t *phKernel) {

const ur_kernel_native_properties_t *pProperties,
ur_kernel_handle_t *phKernel) {
*phKernel = reinterpret_cast<ur_kernel_handle_t>(hNativeKernel);
if (!pProperties || !pProperties->isNativeHandleOwned) {
return urKernelRetain(*phKernel);
}
return UR_RESULT_SUCCESS;
}

Expand Down
14 changes: 8 additions & 6 deletions source/adapters/opencl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,11 @@ urMemGetNativeHandle(ur_mem_handle_t hMem, ur_native_handle_t *phNativeMem) {
UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle(
ur_native_handle_t hNativeMem,
[[maybe_unused]] ur_context_handle_t hContext,
[[maybe_unused]] const ur_mem_native_properties_t *pProperties,
ur_mem_handle_t *phMem) {

const ur_mem_native_properties_t *pProperties, ur_mem_handle_t *phMem) {
*phMem = reinterpret_cast<ur_mem_handle_t>(hNativeMem);
if (!pProperties || !pProperties->isNativeHandleOwned) {
return urMemRetain(*phMem);
}
return UR_RESULT_SUCCESS;
}

Expand All @@ -343,10 +344,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreateWithNativeHandle(
[[maybe_unused]] ur_context_handle_t hContext,
[[maybe_unused]] const ur_image_format_t *pImageFormat,
[[maybe_unused]] const ur_image_desc_t *pImageDesc,
[[maybe_unused]] const ur_mem_native_properties_t *pProperties,
ur_mem_handle_t *phMem) {

const ur_mem_native_properties_t *pProperties, ur_mem_handle_t *phMem) {
*phMem = reinterpret_cast<ur_mem_handle_t>(hNativeMem);
if (!pProperties || !pProperties->isNativeHandleOwned) {
return urMemRetain(*phMem);
}
return UR_RESULT_SUCCESS;
}

Expand Down
7 changes: 5 additions & 2 deletions source/adapters/opencl/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetNativeHandle(

UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithNativeHandle(
ur_native_handle_t hNativeProgram, ur_context_handle_t,
const ur_program_native_properties_t *, ur_program_handle_t *phProgram) {

const ur_program_native_properties_t *pProperties,
ur_program_handle_t *phProgram) {
*phProgram = reinterpret_cast<ur_program_handle_t>(hNativeProgram);
if (!pProperties || !pProperties->isNativeHandleOwned) {
return urProgramRetain(*phProgram);
}
return UR_RESULT_SUCCESS;
}

Expand Down