开发者

How to get card specs programmatically in CUDA

开发者 https://www.devze.com 2023-02-25 02:40 出处:网络
I\'m just starting out with CUDA.开发者_Go百科 Is there a way of getting the card specs programmatically?You can use the cudaGetDeviceCount and cudaGetDeviceProperties APIs.

I'm just starting out with CUDA.开发者_Go百科 Is there a way of getting the card specs programmatically?


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;
    }
}

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.

The CUDA Programming guide has more detail in section 3.2.3.

0

精彩评论

暂无评论...
验证码 换一张
取 消