CudaMallocManaged - how to determine max available size

Hello friends,

I am using the unified memory option in my projects.
My question is how can i determine the maximum available bytes on my card.
For example i ran the same program (using many allocations of CudaMallocManaged)
on the GTX 970 i got an exception (out of memory) after reaching 1.8GB
on the GTX 750 Ti i got the same exception when 1.1GB were reached.

I know that i need to take in count the physical threads stacks and the kernel code and other kind of stuffs that the GPU is saving for it is own using but there is a method/tool to get good approximation?

You can query the amount of available and total device memory using cudaMemGetInfo.


size_t free_device_mem = 0;
size_t total_device_mem = 0;

cudaMemGetInfo(&free_device_mem, &total_device_mem);

printf("Currently available amount of device memory: %zu bytes\n", free_device_mem);
printf("Total amount of device memory: %zu bytes\n", total_device_mem);