如何在CUDA中以程序方式获取卡规格 [英] How to get card specs programatically in CUDA

查看:161
本文介绍了如何在CUDA中以程序方式获取卡规格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用CUDA。

I'm just starting out with CUDA. Is there a way of getting the card specs programatically?

推荐答案

您可以使用 cudaGetDeviceCount cudaGetDeviceProperties API。

You can use the cudaGetDeviceCount and cudaGetDeviceProperties APIs.

void DisplayHeader()
{
    const int kb = 1024;
    const int mb = kb * kb;
    wcout << "NBody.GPU" << endl << "=========" << endl << endl;

    wcout << "CUDA version:   v" << CUDART_VERSION << endl;    
    wcout << "Thrust version: v" << THRUST_MAJOR_VERSION << "." << THRUST_MINOR_VERSION << endl << endl; 

    int devCount;
    cudaGetDeviceCount(&devCount);
    wcout << "CUDA Devices: " << endl << endl;

    for(int i = 0; i < devCount; ++i)
    {
        cudaDeviceProp props;
        cudaGetDeviceProperties(&props, i);
        wcout << i << ": " << props.name << ": " << props.major << "." << props.minor << endl;
        wcout << "  Global memory:   " << props.totalGlobalMem / mb << "mb" << endl;
        wcout << "  Shared memory:   " << props.sharedMemPerBlock / kb << "kb" << endl;
        wcout << "  Constant memory: " << props.totalConstMem / kb << "kb" << endl;
        wcout << "  Block registers: " << props.regsPerBlock << endl << endl;

        wcout << "  Warp size:         " << props.warpSize << endl;
        wcout << "  Threads per block: " << props.maxThreadsPerBlock << endl;
        wcout << "  Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1]  << ", " << props.maxThreadsDim[2] << " ]" << endl;
        wcout << "  Max grid dimensions:  [ " << props.maxGridSize[0] << ", " << props.maxGridSize[1]  << ", " << props.maxGridSize[2] << " ]" << endl;
        wcout << endl;
    }
}

如果您已安装 GPU Computing SDK c。 c $> c $> 项目中找到%NVSDKCOMPUTE_ROOT%\C \src 目录。它显示了如何使用CUDA Runtime API调用查询所有设备属性。

If you have installed the GPU Computing SDK, have a look at the deviceQuery project which can be found in the %NVSDKCOMPUTE_ROOT%\C\src directory. It shows how to query for all the device properties using CUDA Runtime API calls.

CUDA编程指南在第3.2.3节中有更多细节。

The CUDA Programming guide has more detail in section 3.2.3.

这篇关于如何在CUDA中以程序方式获取卡规格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆