Detect how much global memory is available?

Hey all,

before allocating global memory, is it possible to first detect how much is available? Is it possible to detect how much is allowed to be allocated or is their a good heuristic for guessing? Will a certain exception be thrown if too much is allocated?

this is what i use in my application, but in my case for some reason the results are suspicious. However i cannot be sure because the same GPU is used for display, try it yourself and tell me if it works.

void printGPUMemory(){

	size_t free=0, total=0;

	std::stringstream outPut;

	cudaMemGetInfo(&free, &total);

	outPut << "Open::GPU Mem Used=" << 100.0f*(float)(total-free)/(float)total << "% (" << (float)(total-free)/1000000.0f << " Mb " << "of " << (float)total/1000000.0f << " Mb)" << std::endl;

	printf( "%s", outPut.str().c_str() );

}

you will get messages with this format

Open::GPU Mem Used=33.1615% (177.796 Mb of 536.15 Mb)

this is what i use in my application, but in my case for some reason the results are suspicious. However i cannot be sure because the same GPU is used for display, try it yourself and tell me if it works.

void printGPUMemory(){

	size_t free=0, total=0;

	std::stringstream outPut;

	cudaMemGetInfo(&free, &total);

	outPut << "Open::GPU Mem Used=" << 100.0f*(float)(total-free)/(float)total << "% (" << (float)(total-free)/1000000.0f << " Mb " << "of " << (float)total/1000000.0f << " Mb)" << std::endl;

	printf( "%s", outPut.str().c_str() );

}

you will get messages with this format

Open::GPU Mem Used=33.1615% (177.796 Mb of 536.15 Mb)