在使用GPU的是过程中,因为服务器上不仅仅只有一块GPU,这个时候为了很好的管理GPU资源,需要获取GPU的属性。
/**
* 获取GPU属性
*/
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
cudaDeviceProp prop;
int count;
// 获取有所少快GPU设备
cudaGetDeviceCount(&count);
for(unsigned i = 0; i < count; ++i)
{
// 获取GPU属性信息
cudaGetDeviceProperties(&prop, i);
cout << "name: " << prop.name << endl;
cout << "totalGlobalMem: " << prop.totalGlobalMem << endl;
cout << "sharedMemPerBlock: " << prop.sharedMemPerBlock << endl;
cout << "regsPerBlock: " << prop.regsPerBlock << endl;
cout << "warpSize: " << prop.warpSize << endl;
cout << "memPitch: " << prop.memPitch << endl;
cout << "canMapHostMemory: " << prop.canMapHostMemory << endl;
cout << "pciDeviceID: " << prop.pciDeviceID << endl;
cout << "tccDriver: " << prop.tccDriver << endl;
cout << "----------------------------------------------------"<< endl;
}
// 设置当前使用那块GPU
cudaSetDevice(count);
return 0;
}
参考资料
CUDA官方文档
https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE