如何使用cuMemGetInfo函數

首先,運行時和驅動層函數聯合使用的話,需要加上動態庫libcuda.so
其次,要使用cuMemGetInfo,不止是這一個驅動函數,而是所有的驅動函數使用之前,必須都要先調用cuInit(0)函數
然後,在cuMemGetInfo之前,先調用cudaMalloc函數,隨便分配什麼東西都行,要不然cuMemGetInfo不知道要獲取多少,this is silly, I know......
下面是例子:
void main()
{
CUresult uRet;
int *dn;
cudaMalloc((void **)&dn, 1 * sizeof(int));


uRet = cuInit(0);
printf("%d\n", (int)uRet);


size_t free;


size_t total;


uRet = cuMemGetInfo(&free, &total);


        if(uRet == CUDA_SUCCESS)
          printf("free = %d\n total = %d\n", free, total);
}




       
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章