Problems with cudaMemGetInfo with cuda 3.0


I’m having problems getting cudaMemGetInfo to work reliably using cuda 3.0. Here’s a simple example:

#include <iostream>

#include <cuda_runtime.h>

int main(int argc, char** argv)




	size_t free, total;

	cudaMemGetInfo(&free, &total);


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


	return 0;


Compiled like:

g++433 -I/apps/Linux64/cuda-3.0/include -c -o main.o main.cpp; g++433 -o simpletest -L/apps/Linux64/cuda-3.0/lib64 -lcudart main.o; ./simpletest

This outputs:

mem = 2746351616 140736011370496

Why isn’t it giving me an accurate figure for total memory? Additionally if I put this at different points in my codebase, I get an accurate total memory, but inaccurate free memory value, other times it just gives me an “unspecified driver error” when I try and call this function.

Any ideas why this particular function might be so problematic? (or if anyone can confirm this by running this simple test?) I’m using the new Fermi Tesla, but my second device is an FX4800 which sees the same problems. I’m on linux running the 195.36.24 NVidia driver and have rebooted my machine since upgrading to this driver.



I filed a bug report for this issue last week. It should be fixed in the 3.1 release.

From my testing, it looks like the most-significant bytes of the size_t variables ‘free’ and ‘total’ are not being set by the cudaMemGetInfo call. As a workaround, you could try initializing ‘total’ and ‘free’ to 0 before calling cudaMemGetInfo.



Ah, that makes complete sense. I really should have thought of that, good to know it’ll be fixed for the next release.