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

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

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

问题描述

限时删除!!

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

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

推荐答案

您可以使用和 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 ,请查看 deviceQuery 项目,该项目可在%NVSDKCOMPUTE_ROOT%\C\src 目录中找到。它显示了如何使用CUDA运行时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.

在3.2.3节中有更详细的说明。

The CUDA Programming guide has more detail in section 3.2.3.

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

1403页,肝出来的..

09-06 22:57