CUDA C并行编程--查询设备信息



#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
#include <stdio.h>

int main(int argc, char** argv){
    printf("%s starting ...\n", argv[0]);
    int deviceCount = 0;
    cudaError 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 avail device that support CUDA!\n");
    }
    else {
        printf("Detected %d CUDA device !\n", deviceCount);
    }
    int dev = 0, driverVersion = 0, runtimeVersion = 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, (driverVersion % 1000) / 10,
        runtimeVersion / 1000, (runtimeVersion % 100) / 10);
    // CUDA cap版本
    printf("    CUDA Capability Major / Minor version number :  %d.%d       \n", deviceProp.major, deviceProp.minor);    
    // CUDA 内存
    printf("    Total amount of global memory:  %.2f MBytes(%llu bytes)     \n",
        (float)deviceProp.totalGlobalMem / (pow(1024.0, 3)),
        (unsigned long long)deviceProp.totalGlobalMem); 
    // GPU 的时钟率
    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.maxTexture2D[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.maxTexture1DLayered[1],
        deviceProp.maxSurface2DLayered[0], deviceProp.maxSurface2DLayered[1], deviceProp.maxSurface2DLayered[2]);
    printf("    Total amount of constant memory per block: %lu bytes        \n", deviceProp.totalConstMem);
    printf("    Total amount shared memory per clock: %lu bytes             \n", deviceProp.sharedMemPerBlock);
    printf("    Total number of registers available per clock: %d           \n", deviceProp.regsPerBlock);
    printf("    Warp size:      %d                                          \n", deviceProp.warpSize);
    printf("    Maxinum number of threads per multiprocessor:%d             \n", deviceProp.maxThreadsPerMultiProcessor);
    printf("    Maxinum number of threads per block:%d                      \n", deviceProp.maxThreadsPerBlock);
    printf("    Max sizes of each dimension of a block : %d x %d x %d       \n",
        deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]);
    printf("    Max sizes of each dimension of a grid : %d x %d x %d        \n",
        deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]);    
    printf("    Max memory pitch:  %lu bytes                                \n", deviceProp.memPitch);
    return 0;
}

编译:

nvcc checkDeviceInfo.cu -o checkDeviceInfo

运行:

./checkDeviceInfo

输出:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值