OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

Who is responsible for releasing cl_events

Jerry_C_
Beginner
598 Views

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
598 Views

Hi Jerry,

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

0 Kudos
Reply