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.
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?