20211112:CUDA编程-获取GPU型号和属性

//获取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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小帅之狗腿子

一条New_Worker

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值