//获取GPU名字代码:
int cudaGetGpuName(char *name[], int *Num) {
int i;
int Count = 0;
cudaError_t error_id = cudaGetDeviceCount(&Count);
if (error_id != cudaSuccess) {
APP_ERR("cuda get device count failed, ret:%d, %s", (int)error_id, cudaGetErrorString(error_id));
return -1;
}
if (Count > 16) {
APP_WARRING("too large gpu num : %d", deviceCount);
Count = 16;
}
// printf("cudaDeviceProp size:%d\n", sizeof(cudaDeviceProp));
// char datastr[1024];
for (i = 0; i < Count; i++) {
cudaSetDevice(i);
// prevent device version problem, not use struct cudaDeviceProp
cudaDeviceProp Prop;
cudaGetDeviceProperties(&Prop, i);
// printf("\nDevice %d: \"%s\"\n", i, datastr);
name[i] = (char *)malloc(256);
memset(name[i], 0, 256);
if (name[i] != NULL) {
strncpy(name[i], Prop.name, 256);
} else {
APP_ERR("malloc failed");
return -1;
}
}
*Num = Count;
return 0;
}