cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

AndyS
Journeyman III

clCreateBuffer / clReleaseMemObject Leaks

Hi,

I'm using a 5770 with ATI Stream 2.1 on Win7 64bit, in a 64bit process. I have long-lived contexts, programs, kernels and make cl_mem buffers and tear them down frequently.

The library does not appear to properly refcount down / release the cl_mem objects.. for example (assume all setup is done):

cl_mem inputImageBuffer;

cl_mem tempImageBuffer;

cl_mem outputImageBuffer;

inputImageBuffer = clCreateBuffer(context,CL_MEM_READ_ONLY,width * height * 4,0,&status);

outputImageBuffer = clCreateBuffer(context,CL_MEM_READ_WRITE,width * height * 4,0,&status);

tempImageBuffer = clCreateBuffer(context,CL_MEM_READ_WRITE,width * height * 4,0,&status);

/* Execute some kernels, etc. etc. */

status = clReleaseMemObject(inputImageBuffer);

status = clReleaseMemObject(tempImageBuffer);

status = clReleaseMemObject(outputImageBuffer);

 

If you repeat this code N times, it will eventually fail to allocate the buffers at the top. N varies with width*height size, so it looks like a leak. I *am* however executing this code from many separate threads, abeit inside a critical section.

So, unless I've done something stupid (wouldn't be the first time ), either a.) A bug is preventing buffer release or b.) Using openCL from many threads, even though properly critical sectioned, is broken.

Thanks is advance for any advice.

AndyS





0 Likes
3 Replies
tlrmchlsmth
Journeyman III

I'm having a similar problem on 5870 with ATI Stream 2.1 on Win7 64bit.

If I do:

cl_int count; cl_mem a = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(cl_float) * globalSize, NULL, &err); clGetMemObjectInfo(a, CL_MEM_REFERENCE_COUNT, sizeof(cl_int), &count, NULL); //count will equal 1 as expected. //But then if i do: clEnqueueWriteBuffer(commandQ, a, CL_TRUE, 0, sizeof(cl_float) * num, (void*) a, 0, NULL, NULL); clGetMemObjectInfo(a, CL_MEM_REFERENCE_COUNT, sizeof(cl_int), &count, NULL); //count now equals 2. Is it supposed to? //The documentation doesn't say anything about clEnqueueWriteBuffere increasing a's reference count.

0 Likes

Hi,

EDIT: Hmm.. the sample you gave doesn't behave the same for me - enqueueWriteBuffer does not seems to increment refcount - for me it's setKernelArg!!

Thanks - I took the time to sprinkle some clGetMemObjectInfo's in my code (useful thing ). Seems like every time I do clSetKernelArg to pass a buffer into a kernel, the cl_mem object refcount increases. This might be how it's meant to work - but in that case I would expect API like clClearKernelArgs or something similar to drop the refcounts. Are we expected to manually release all argument buffers after each clEnqueueNDRangeKernel?

Thanks,

Andy

0 Likes

Have you tried calling clReleaseEvent for every clEnqueueNDRangeKernel call (see http://forums.amd.com/devforum/messageview.cfm?catid=390&threadid=131733&enterthread=y )?

0 Likes