关闭

(2)查询CUDA设备

389人阅读 评论(0) 收藏 举报
分类:

调用CUDA提供API查询当前计算机支持CUDA 的设备信息:

(打印出部分信息)

 

#include "stdafx.h"
#include "cuda_runtime_api.h"

int main(int argc, _TCHAR* argv[])
{

 //get Devices count 
 int nDevCount = -1;
 cudaError_t nErr;

 nErr = cudaGetDeviceCount(&nDevCount);

 if (cudaSuccess != nErr)
 {
  printf("Get devices count failed !\n");
  return -1;
 }
 if (nDevCount <= 0)
 {
  printf("You have no graphics card support CUDA !\n");
 }
 else
 {
  printf("You have %d graphics card support CUDA !\n", nDevCount);
 }

 //Get devices info
 cudaDeviceProp pProp;
 nErr = cudaGetDeviceProperties(&pProp, 0);
 if (cudaSuccess != nErr)
 {
  printf("Get devices info failed !\n");
  return -1;
 }
 printf("Name: %s\n", pProp.name);
 printf("totalGlobalMemory: %lld\n", pProp.totalGlobalMem);
 printf("totalConstMemory :%lld\n", pProp.totalConstMem);
 printf("clockRate: %d\n", pProp.clockRate);
 printf("multiProcessorCount :%d\n", pProp.multiProcessorCount);
 printf("major:%d\n", pProp.major);
 printf("minor :%d\n", pProp.minor);
 printf("maxThreadsPerBlock :%d\n", pProp.maxThreadsPerBlock);

 int i = 0;
 scanf("%d", &i);
 
 return 0;
}

运行结果:

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1158次
    • 积分:32
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档