Skip to content

Commit

Permalink
sync retain/release cl handles with ur handles
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Feb 16, 2024
1 parent 51dacd4 commit 456e1c6
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ UR_APIEXPORT ur_result_t UR_APICALL
urContextRelease(ur_context_handle_t hContext) {
if (hContext->decrementReferenceCount() == 0) {
delete hContext;
} else {
CL_RETURN_ON_FAILURE(clReleaseContext(hContext->get()));
}
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL
urContextRetain(ur_context_handle_t hContext) {
CL_RETURN_ON_FAILURE(clRetainContext(hContext->get()));
hContext->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}
Expand Down
10 changes: 7 additions & 3 deletions source/adapters/opencl/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
// Root devices ref count are unchanged through out the program lifetime.
UR_APIEXPORT ur_result_t UR_APICALL urDeviceRetain(ur_device_handle_t hDevice) {
if (hDevice->ParentDevice) {
CL_RETURN_ON_FAILURE(clRetainDevice(hDevice->get()));
hDevice->incrementReferenceCount();
}

Expand All @@ -1018,10 +1019,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceRetain(ur_device_handle_t hDevice) {
// Root devices ref count are unchanged through out the program lifetime.
UR_APIEXPORT ur_result_t UR_APICALL
urDeviceRelease(ur_device_handle_t hDevice) {
if (hDevice->ParentDevice && hDevice->decrementReferenceCount() == 0) {
delete hDevice;
if (hDevice->ParentDevice) {
if (hDevice->decrementReferenceCount() == 0) {
delete hDevice;
} else {
CL_RETURN_ON_FAILURE(clReleaseDevice(hDevice->get()));
}
}

return UR_RESULT_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/opencl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ur_device_handle_t_ {
}
}

~ur_device_handle_t_() { clReleaseDevice(Device); }
~ur_device_handle_t_() {}

uint32_t incrementReferenceCount() noexcept { return ++RefCount; }

Expand Down
3 changes: 3 additions & 0 deletions source/adapters/opencl/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetNativeHandle(
UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) {
if (hEvent->decrementReferenceCount() == 0) {
delete hEvent;
} else {
CL_RETURN_ON_FAILURE(clReleaseEvent(hEvent->get()));
}
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) {
CL_RETURN_ON_FAILURE(clRetainEvent(hEvent->get()));
hEvent->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions source/adapters/opencl/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
}

UR_APIEXPORT ur_result_t UR_APICALL urKernelRetain(ur_kernel_handle_t hKernel) {
CL_RETURN_ON_FAILURE(clRetainKernel(hKernel->get()));
hKernel->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}
Expand All @@ -280,6 +281,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urKernelRelease(ur_kernel_handle_t hKernel) {
if (hKernel->decrementReferenceCount() == 0) {
delete hKernel;
} else {
CL_RETURN_ON_FAILURE(clReleaseKernel(hKernel->get()));
}
return UR_RESULT_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions source/adapters/opencl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
}

UR_APIEXPORT ur_result_t UR_APICALL urMemRetain(ur_mem_handle_t hMem) {
CL_RETURN_ON_FAILURE(clRetainMemObject(hMem->get()));
hMem->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
if (hMem->decrementReferenceCount() == 0) {
delete hMem;
} else {
CL_RETURN_ON_FAILURE(clReleaseMemObject(hMem->get()));
}
return UR_RESULT_SUCCESS;
}
3 changes: 3 additions & 0 deletions source/adapters/opencl/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t hDevice,

UR_APIEXPORT ur_result_t UR_APICALL
urProgramRetain(ur_program_handle_t hProgram) {
CL_RETURN_ON_FAILURE(clRetainProgram(hProgram->get()));
hProgram->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}
Expand All @@ -354,6 +355,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urProgramRelease(ur_program_handle_t hProgram) {
if (hProgram->decrementReferenceCount() == 0) {
delete hProgram;
} else {
CL_RETURN_ON_FAILURE(clReleaseProgram(hProgram->get()));
}
return UR_RESULT_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions source/adapters/opencl/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueFlush(ur_queue_handle_t hQueue) {
}

UR_APIEXPORT ur_result_t UR_APICALL urQueueRetain(ur_queue_handle_t hQueue) {
CL_RETURN_ON_FAILURE(clRetainCommandQueue(hQueue->get()));
hQueue->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urQueueRelease(ur_queue_handle_t hQueue) {
if (hQueue->decrementReferenceCount() == 0) {
delete hQueue;
} else {
CL_RETURN_ON_FAILURE(clReleaseCommandQueue(hQueue->get()));
}
return UR_RESULT_SUCCESS;
}
3 changes: 3 additions & 0 deletions source/adapters/opencl/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ urSamplerGetInfo(ur_sampler_handle_t hSampler, ur_sampler_info_t propName,

UR_APIEXPORT ur_result_t UR_APICALL
urSamplerRetain(ur_sampler_handle_t hSampler) {
CL_RETURN_ON_FAILURE(clRetainSampler(hSampler->get()));
hSampler->incrementReferenceCount();
return UR_RESULT_SUCCESS;
}
Expand All @@ -205,6 +206,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urSamplerRelease(ur_sampler_handle_t hSampler) {
if (hSampler->decrementReferenceCount() == 0) {
delete hSampler;
} else {
CL_RETURN_ON_FAILURE(clRetainSampler(hSampler->get()));
}
return UR_RESULT_SUCCESS;
}
Expand Down

0 comments on commit 456e1c6

Please sign in to comment.