按位置选择的CUDA GPU,但如何将默认设置为设备0以外的东西? [英] CUDA GPU selected by position, but how to set default to be something other than device 0?

查看:55
本文介绍了按位置选择的CUDA GPU,但如何将默认设置为设备0以外的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在家里的机器上安装了第二个 GPU (Tesla K40),我的搜索表明第一个 PCI 插槽成为为 CUDA 作业选择的默认 GPU.一个很好的链接解释它可以在这里找到:

I've recently installed a second GPU (Tesla K40) on my machine at home and my searches have suggested that the first PCI slot becomes the default GPU chosen for CUDA jobs. A great link is explaining it can be found here:

默认 GPU 分配

我原来的 GPU 是 TITAN X,也启用了 CUDA,但它确实最适合单精度计算,而 Tesla 更适合双精度.我对小组的问题是,是否有办法将我的默认 CUDA 编程设备设置为始终是第二个?显然我可以在代码中指定每次使用哪个设备,但我希望我可以配置我的设备,使其始终默认使用特斯拉卡.

My original GPU is a TITAN X, also CUDA enabled, but it's really best for single precision calculations and the Tesla better for double precision. My question for the group is whether there is a way to set up my default CUDA programming device to be the second one always? Obviously I can specify in the code each time which device to use, but I'm hoping that I can configure my set such that it will always default to using the Tesla card.

或者是打开盒子并物理交换设备位置的唯一方法?不知怎的,这对我来说似乎是错误的......

Or is the only way to open the box up and physically swap positions of the devices? Somehow that seems wrong to me....

我们将不胜感激任何要跟进的建议或相关链接.

Any advice or relevant links to follow up on would be greatly appreciated.

推荐答案

正如你已经指出的,cuda 运行时有 它自己的启发式,用于对 GPU 进行排序并为其分配设备索引.

As you've already pointed out, the cuda runtime has its own heuristic for ordering GPUs and assigning devices indices to them.

CUDA_VISIBLE_DEVICES 环境变量 将允许您修改此顺序.

The CUDA_VISIBLE_DEVICES environment variable will allow you to modify this ordering.

例如,假设在普通使用中,我的显示设备被枚举为设备0,而我首选的CUDA GPU被枚举为设备1.没有任何使用cudaSetDevice编写的应用程序,例如,将默认使用枚举为 0 的设备.如果我想更改它,在 linux 下我可以使用类似:

For example, suppose that in ordinary use, my display device is enumerated as device 0, and my preferred CUDA GPU is enumerated as device 1. Applications written without any usage of cudaSetDevice, for example, will default to using the device enumerated as 0. If I want to change this, under linux I could use something like:

CUDA_VISIBLE_DEVICES="1" ./my_app

使 cuda 运行时枚举通常是设备 1 的设备作为该应用程序运行的设备 0(在这种情况下,普通设备 0 将对 CUDA 隐藏").只需导出该变量(例如 bash),您就可以使该会话永久":

to cause the cuda runtime to enumerate the device that would ordinarily be device 1 as device 0 for this application run (and the ordinary device 0 would be "hidden" from CUDA, in this case). You can make this "permanent" for the session simply by exporting that variable (e.g., bash):

export CUDA_VISIBLE_DEVICES="1"
./my_app

如果我只是想颠倒默认的 CUDA 运行时排序,但仍然让两个 GPU 都可用于应用程序,我可以执行以下操作:

If I simply wanted to reverse the default CUDA runtime ordering, but still make both GPUs available to the application, I could do something like:

CUDA_VISIBLE_DEVICES="1,0" ./deviceQuery

还有其他规范选项,例如使用 nvidia-smi 提供的 GPU UUID 标识符(而不是设备索引).

There are other specification options, such as using GPU UUID identifiers (instead of device indices) as provided by nvidia-smi.

请参阅文档这篇文章.

这篇关于按位置选择的CUDA GPU,但如何将默认设置为设备0以外的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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