gpt4 book ai didi

cuda - 如何在 CUDA 中以编程方式获取卡规范

转载 作者:行者123 更新时间:2023-12-02 21:01:09 25 4
gpt4 key购买 nike

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

最佳答案

您可以使用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计算SDK,请查看deviceQuery项目,该项目位于%NVSDKCOMPUTE_ROOT%\C\src 目录。它展示了如何使用 CUDA Runtime API 调用查询所有设备属性。

CUDA Programming guide第 3.2.3 节中有更多详细信息。

更新:

deviceQuery 示例不再与 CUDA 工具包一起打包,您可以在 GitHub 上找到它相反。

关于cuda - 如何在 CUDA 中以编程方式获取卡规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5689028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com