Getting Device's Free Mem

Is there anyway to get the current amount of free memory without keeping track of the current memory used, calculating the memory that is used to display based on the system’s resolution, and then subtracting that from the total memory available on the device?

thank you

Look for cuMemGetInfo …

Thank you. I assume there is no way to do it from the runtime side

Correct, but you can safely run cuGetMemInfo() when you are using the runtime API. (This is an API design bug that hopefully someone will fix eventually.)

Is there a bug in cuMemInfo’s implementation in cuda 2.3 (have not tested it in previous versions), but I am getting

free = 786432 , total = 2

free = 759934976 , total = 938803200

free = 756789248 , total = 938803200

from the following code

unsigned int freeDeviceMemorySize(int device) {

	unsigned int free, total;

	cuMemGetInfo(&free, &total);

	printf("free = %d , total = %d\n", free, total);

	return free;


the last two outputs should be correct, but the first is not. This is on the 295 device

I am also putting


to init the device before any operation.

Did you create a context before calling cuMemGetInfo?

Did you create a context before calling cuMemGetInfo?

thanks. that was the problem