OpenCL Events causing memory leaks

Started by Kuko, August 02, 2011, 15:10:00

Previous topic - Next topic

Kuko

Hi, I have realized that any call to an clEnqueue* Command, like clEnqueueNDRangeKernel, with the last argument (PointerBuffer event) not set to null consumes a certain amount of System Memory, which is not released afterwards.
You can easily verify this by changing line 60 in the OpenCL Sum Example
clEnqueueNDRangeKernel(queue, kernel, 1, null, kernel1DGlobalWorkSize, null, null, null);


to
PointerBuffer ev = new PointerBuffer(1);  
for(int i=0; i<10000000;i++){
       clEnqueueNDRangeKernel(queue, kernel, 1, null, kernel1DGlobalWorkSize, null, null, ev);
}


for Example. Note: executing this will burn your main memory in seconds.
I have verified this on an Intel CPU, an Ati GPU and an Nvidia GPU with Linux and Windows. The memory used by GPU remains constant.

Is this a bug or is there a way to manually release the memory?

spasi

CLEvent, like most CL objects, is "retainable". That means, it has a reference count that can be increased (clRetain<Type>) or decreased (clRelease<Type>). After a call to clEnqueueNDRangeKernel, the reference count is 1, so that's why you're seeing an increase in memory usage. This is how you get rid of the leak:

PointerBuffer ev = new PointerBuffer(1);  
for(int i=0; i<10000000;i++){
       clEnqueueNDRangeKernel(queue, kernel, 1, null, kernel1DGlobalWorkSize, null, null, ev);
       CLEvent e = queue.getCLEvent(ev.get(0));
       ... wait on event or whatever ...
       clReleaseEvent(e);
}