如何在CUDA中以编程方式获取卡规格

时间:2011-04-16 19:31:33

标签: cuda nvidia specs

我刚刚开始使用CUDA。有没有办法以编程方式获取卡规格?

2 个答案:

答案 0 :(得分:20)

您可以使用cudaGetDeviceCountcudaGetDeviceProperties API。

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 ,请查看可在deviceQuery目录中找到的%NVSDKCOMPUTE_ROOT%\C\src项目。它显示了如何使用CUDA Runtime API调用查询所有设备属性。

CUDA Programming guide在第3.2.3节中有更详细的内容。

答案 1 :(得分:1)

此PDF描述了如何操作: http://developer.download.nvidia.com/compute/cuda/3_2/toolkit/docs/CUDA_Developer_Guide_for_Optimus_Platforms.pdf

(我用Google搜索[cuda get gpu capabilities]。)

特别是,cudaGetDeviceProperties看起来很有趣。