I need to check the amount of free gpu memory before running the cuda algorithm, hence I used cudaMemGetInfo() to get the amount of free memory. But the returned free memory is not taking into account the gpu memory consumed by other opengl applications which are running in parallel. The windows task manager reports the actual usage of the dedicated gpu memory considering the opengl applications but cudaMemGetInfo() doesn’t take into the gpu memory consumed by opengl applications.
Whereas Opengl memory info extension properly reflects the free gpu memory taking into account even the cuda consumptions except for the 512MB that is consumed by the cuda driver.
Also cudaMemGetInfo() returns saying only 3.2GB free of 4GB when no gpu applications are running. Whereas if I create cuda context and then call cudaMemGetInfo() it return saying only 3.2GB free of 3.5GB. So where is the 512MB? is it taken by the cuda context?
I use Cuda 9.2 with NVIDIA driver 452.57 on Quadro P1000.
In summary I would like to understand -
-
Why cudaMemGetInfo() not reflecting the gpu memory consumed by opengl applications when the same is reflected by the windows task manager?
-
Why is cudaMemGetInfo() consumes 0.8GB by default even when no gpu applications are running?
-
Why is cuda context consuming 512MB of gpu memory and as well it reduces this amount from the total memory reported by cudaMemGetInfo()?
size_t free=0, total=0, stackLimit=0; cudaSetDevice(0); cudaMemGetInfo( &free, &total ); std::cout << "CUDA memStat (free/total): \t\t" << free/(1024*1024) << "MB/" << total/(1024*1024) << "MB(" << (total-free)/(1024*1024) << ")\n"; CUcontext ctx; int err=cuCtxCreate(&ctx,0,info.nDevice); if (err == 0) { cuMemGetInfo(&free,&total); cuCtxDetach(ctx); } std::cout << "CUDA context memStat (free/total): \t" << free/(1024*1024) << "MB/" << total/(1024*1024) << "MB(" << (total-free)/(1024*1024) << ")\n"; GLint aDedicatedVidmem = 0; glGetIntegerv(GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicatedVidmem); total = aDedicatedVidmem * 1024; GLint aCurrentAvailableVidmem = 0; glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aCurrentAvailableVidmem); free = aCurrentAvailableVidmem * 1024; std::cout << "Opengl memStat (free/total): \t" << free/(1024*1024) << "MB/" << total/(1024*1024) << "MB(" << (total-free)/(1024*1024) << ")\n";
I get the following output when I have around 1175MB used by opengl applications
CUDA memStat (free/total): 3385MB/4096MB(710)
CUDA context memStat (free/total): 3354MB/3583MB(229)
Opengl memStat (free/total): 2375MB/4096MB(1720)
When I create a 256MB of cuda cache using cudaMalloc() then the output is
CUDA memStat (free/total): 3129MB/4096MB(966)
Cuda context memStat (free/total): 3098MB/3583MB(485)
Opengl memStat (free/total): 2026MB/4096MB(2069)
So cuda allocations are accounted by the opengl memory info extension but the opengl usage is not accounted by the cudaMemGetInfo()!