Query Memory used on GPU

Hi there,

I could not find a way to query the actual amount of GPU memory used. Is there a way to get this informations from openCL. All I found was the overall maximum global memory available. What I want to know is the free global memory or the used global memory.

Or is there only the solution to wait until a query returns CL_OUT_OF_RESOURCES?


I suspect there isn’t such a query as it isn’t something that can really be calculated.

buffers and images only need to be ‘on card’ when a kernel using them is executing, they could otherwise be in system memory or even conceivable swapped to disk.

In other words, OpenCL’s api deliberately visualises these resources on purpose to make it easier to use, so ‘how much is left on the device’ isn’t terribly useful.

Err, virtualises that was supposed to be.

Thanks for the answer.

this means, an out of ressources error would only happend if the data for the kernel thats being computed is larger than the memory available on the card? Or can it happen that i run out of memory because the gpu tries to buffer some data for the next things in queue?


The precise details would depend on the driver and implementation - and such details are proprietary.

But both of those scenarios seem likely possible causes to me (of several).

Note that although the api allows virtualisation, it doesn’t mean a given implementation takes advantage of it … although I would think a mature implementation would need it to remain competitive although that is only conjecture.

what is the difference between
cl_mem input = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * DATA_SIZE, NULL, NULL);
clEnqueueWriteBuffer(command_queue, input, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputdata, 0, NULL, NULL);


cl_mem input = clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, ,sizeof(float) * DATA_SIZE, inputdata, NULL);