有没有函数能返回GPU显存的占有率.

有没有函数能返回GPU显存的占有率.
就是用了多少显存

顶起,同问

1.如何查看空闲全局存储器?
添加代码:
#inlcude<cuda.h>
#include
static unsigned long inKB(unsigned long bytes)
{
return bytes/1024;
}
static unsigned long inMB(unsigned long bytes)
{
return bytes/(10241024);
}
static void printStats(unsigned long free, unsigned long total)
{
printf(“***** Free : %lu bytes (%lu KB) (%lu MB)\n”, free, inKB(free), inMB(free));
printf(“***** Total: %lu bytes (%lu KB) (%lu MB)\n”, total, inKB(total), inMB(total));
printf(“***** %f%% free, %f%% used\n”, 100.0
free/(double)total, 100.0*(total - free)/(double)total);
}
void getMeminfo()
{
unsigned int free, total;
int gpuCount, i;

CUresult res;   
CUdevice dev;   
CUcontext ctx;   
cuInit(0);   
cuDeviceGetCount(&gpuCount);   
printf("Detected %d GPU\n",gpuCount);   
for (i=0; i<gpuCount; i++)   
{   
	cuDeviceGet(&dev,i);   
	cuCtxCreate(&ctx, 0, dev);   
	res = cuMemGetInfo(&free, &total);   
	if(res != CUDA_SUCCESS)       
		printf("!!!! cuMemGetInfo failed! (status = %x)", res);   
	printf("***** Device: %d\n",i);   
	printStats(free, total);   
	cuCtxDetach(ctx);   
}   

}
运行过程可能出现链接问题:1>Main.cpp.obj : error LNK2001: 无法解析外部符号: _cuCtxDetach@**
参考解决方法:
到Project/Properties/Linker/Input下的添加依赖项上面增加cuda.lib。