CUDA测试设备属性的代码

#include <cuda_runtime.h>
#include <cuda.h>
#include <device_launch_parameters.h>


bool CUDA_initial(void)

{
int i;
int device_count;
if( cudaGetDeviceCount(&device_count) )
{
 printf(" There is zero device beyond 1.0/n"); 
 return false;
}
else 
{
 printf("There is %d device beyond 1.0/n",device_count);
}


for(i=0;i<device_count;i++)
{
  struct cudaDeviceProp device_prop;


 if(cudaGetDeviceProperties(&device_prop,i)==cudaSuccess)
 {
  printf("device properties is :\n"
 " device name is  %s\n"
 "/t totalGlobalMem is  %d\n"
 "/t sharedMemPerBlock is  %d\n"
 "/t regsPerBlock is  %d\n"
 "/t warpSize is  %d\n"
 "/t memPitch is  %d\n"
 "/t maxThreadsPerBlock is  %d\n"
 "/t maxThreadsDim [3] is  %d X %d X %d\n"
 "/t maxGridSize [3] is  %d X %d X %d\n"
 "/t totalConstMem is  %d\n"
 "/t device version is major  %d ,minor  %d\n"
 "/t clockRate is  %d\n"
 "/t textureAlignment is  %d\n"
 "/t deviceOverlap is  %d\n"
 "/t multiProcessorCount is  %d\n",
 device_prop.name,
 device_prop.totalGlobalMem,
 device_prop.sharedMemPerBlock,
 device_prop.regsPerBlock,
 device_prop.warpSize,
 device_prop.memPitch,
 device_prop.maxThreadsPerBlock,
 device_prop.maxThreadsDim[0],device_prop.maxThreadsDim[1],device_prop.maxThreadsDim[2],
 device_prop.maxGridSize[0],device_prop.maxGridSize[1],device_prop.maxGridSize[2],
 device_prop.totalConstMem,
 device_prop.major,device_prop.minor,
 device_prop.clockRate,
 device_prop.textureAlignment,
 device_prop.deviceOverlap,
 device_prop.multiProcessorCount);
  break;
 }
 }
 
 if(i==device_count)
 {
 printf("\nGet the propertites of device occurred error\n");
 return false;
 }


 if(cudaSetDevice(i)==cudaErrorInvalidDevice)
 {
 printf("\nSet Device occurred error\n");
 return false;
 }


}


int main()
{
if (CUDA_initial() == true)
printf("CUDA initial successed!\n");


getchar();
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值