Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Jerry_C_
Beginner
70 Views

Who is responsible for releasing cl_events

Hi,

today i encountered a strange memory increase when i run my OpenCL application. In my case the issue seems to be the OpenCL cl_events.

I use clEnqueueNDRangeKernel(..., &my_event); which returns an OpenCL event. Later in my application i use clWaitForEvents();

Who is responsible for releasing "my_event"? When i only use the commands above i get a memory increase every cycle i call clEnqueueNDRangeKernel(...). When i call clReleaseEvent(my_event); after calling clWaitForEvents(); than the memory leak is gone.

I cannot found something in the OpenCL specification. Thus which code is correct?

clEnqueueNDRangeKernel(..., &my_event);
...
clWaitForEvents(1, &my_event);

or

clEnqueueNDRangeKernel(..., &my_event);
...
clWaitForEvents(1, &my_event);
clReleaseEvent(my_event);

I also checked the reference count of my_event after a call to clWaitForEvents(...) with clGetEventInfo(my_event, CL_EVENT_REFERENCE_COUNT,...). The reference count is still 1 and not 0. So it seems that without clReleaseEvent() the reference count nether gets 0 and thus the resources for the event are not released.

jerry

0 Kudos
1 Reply
Robert_I_Intel
Employee
70 Views

Hi Jerry,

The latter code is correct: you are responsible for releasing events, otherwise you will leak events as you have observed.