CUDA:设备信息查询

CUDA查询设备信息:

CUDA C中的cudaGetDeviceProperties函数可以很方便的获取到设备的信息,函数原型是:

cudaError_t CUDARTAPI cudaGetDeviceProperties(struct cudaDeviceProp *prop, int device);

第一个参数prop指向的是一个cudaDeviceProp类型的结构cudaDeviceProp结构中包含了设备的相关属性,下图是 其中的几个属性信息:

图1  cudaDeviceProp  部分属性

部分属性信息的相关说明如下:

图2 属性说明

获取设备信息实现代码:

#include<cuda_runtime.h>

#include<stdio.h>

#include<iostream>

int main(int argc, char **argv)

{

printf("%s Starting...\n", argv[0]);

int deviceCount = 0;

cudaError_t error_id = cudaGetDeviceCount(&deviceCount);

if (error_id != cudaSuccess)

{

printf("cudaGetDeviceCount returned %d\n->%s\n", (int)error_id,

cudaGetErrorString(error_id));

printf("Result=FALL\n");

exit (EXIT_FAILURE);

}

if (deviceCount == 0)

{

printf("There are no available device(s) that support CUDA\n");

}

else

{

printf("Detectd %d CUDA Capable device(s)\n", deviceCount);

}

int dev, driverVersion = 0, runtimeVersion = 0;

dev = 0;

cudaSetDevice(dev);

cudaDeviceProp deviceProp;

cudaGetDeviceProperties(&deviceProp, dev);

printf("Device %d: \"%s\"\n", dev, deviceProp.name);

cudaDriverGetVersion(&driverVersion);

cudaRuntimeGetVersion(&runtimeVersion);

printf("CUDA Driver Version /Runtime Version %d.%d  /%d.%d\n",

driverVersion / 1000, (runtimeVersion % 100) / 10,

runtimeVersion / 1000, (runtimeVersion % 100) / 10);

printf("CUDA Capability Major/Minor version number:  %d.%d\n", deviceProp.major, deviceProp.minor);

printf("Total amount of global memory: %.2f GBytes (%llu bytes)\n",

(float)deviceProp.totalGlobalMem / (pow(1024.0, 3)), (unsigned long long)deviceProp.totalGlobalMem);

printf("GPU Clock rate: %.0f MHz (%0.2f GHz)\n", deviceProp.clockRate*1e-3f, deviceProp.clockRate*1e-6f);

printf("Memory Clock rate:  %.0f Mhz\n", deviceProp.memoryClockRate*1e-3f);

printf("Memory Bus Width:  %d-bit\n", deviceProp.memoryBusWidth);

if (deviceProp.l2CacheSize)

{

printf("L2 Cache Size: %d bytes\n", deviceProp.l2CacheSize);

}

printf("Max Texture Dimension Size (x,y,z) 1D=(%d),2D=(%d,%d),3D=(%d,%d,%d)\n",

deviceProp.maxTexture1D, deviceProp.maxTexture2D[0], deviceProp.maxSurface2D[1], deviceProp.maxTexture3D[0],

deviceProp.maxTexture3D[1], deviceProp.maxTexture3D[2]);

printf("Max Layered Texture Size (dim) x layers 1D=(%d) x%d,2D=(%d,%d)x %d\n", deviceProp.maxTexture1DLayered[0], deviceProp.maxSurface1DLayered[1],

deviceProp.maxTexture2DLayered[0], deviceProp.maxTexture2DLayered[1], deviceProp.maxTexture2DLayered[2]);

printf("Total amount of constant memory: %lu bytes\n", deviceProp.totalConstMem);

printf("Total amount of shared memory per block: %lu bytes\n", deviceProp.sharedMemPerBlock);

printf("Total number of registers available per block: %d\n", deviceProp.regsPerBlock);

printf("Warp size: %d\n", deviceProp.warpSize);

printf("Maximum number of threads per multiprocessor: %d\n", deviceProp.maxThreadsPerMultiProcessor);

printf("Maximum number of threads per block: %d\n", deviceProp.maxThreadsPerBlock);

printf("Maximum sizes of each dimension of a block: %d x %d x%d\n", deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]);

printf("Maximum sizes of each dimension of a block: %d x %d x%d\n", deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]);

printf("Maximum memory pitch: %lu bytes\n", deviceProp.memPitch);

getchar();

exit(EXIT_FAILURE);

}

查询设备信息结果如下图:

图3 设备信息
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ~/samples/NVIDIA_CUDA-9.1_Samples/1_Utilities/deviceQuery...
    jianpengma阅读 1,726评论 0 0
  • 超高速音视频编码器用法: ffmpeg [options] [[infile options] -i infile...
    吉凶以情迁阅读 4,858评论 0 4
  • 在C语言中,五种基本数据类型存储空间长度的排列顺序是: A)char B)char=int<=float C)ch...
    夏天再来阅读 4,148评论 0 2
  • CUDA从入门到精通(零):写在前面 本文原版链接: 在老板的要求下,本博主从2012年上高性能计算课程开始接触C...
    Pitfalls阅读 3,841评论 1 3
  • 故乡灰黄色的土地 因承载过我的奔跑和身影 没有清冷与萧瑟 只有亲切和温情 高高矗立的大杨树 因遮挡过我头顶的烈日和...
    北疆牧者阅读 839评论 0 6

友情链接更多精彩内容