更改 TensorFlow 中的默认 GPU [英] Change default GPU in TensorFlow

查看:49
本文介绍了更改 TensorFlow 中的默认 GPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,默认 GPU 是 id 最低的那个:

Based on the documentation, the default GPU is the one with the lowest id:

如果您的系统中有多个 GPU,那么最低的 GPU默认情况下会选择 ID.

If you have more than one GPU in your system, the GPU with the lowest ID will be selected by default.

是否可以从命令行或一行代码更改此默认值?

Is it possible to change this default from command line or one line of code?

推荐答案

Suever's answer 正确显示了如何固定您的操作到特定的 GPU.但是,如果您在同一台机器上运行多个 TensorFlow 程序,建议您设置 CUDA_VISIBLE_DEVICES 环境变量,用于在启动进程之前暴露不同的 GPU.否则,TensorFlow 将尝试在所有可用 GPU 上分配几乎全部内存,这会阻止其他进程使用这些 GPU(即使当前进程没有使用它们).

Suever's answer correctly shows how to pin your operations to a particular GPU. However, if you are running multiple TensorFlow programs on the same machine, it is recommended that you set the CUDA_VISIBLE_DEVICES environment variable to expose different GPUs before starting the processes. Otherwise, TensorFlow will attempt to allocate almost the entire memory on all of the available GPUs, which prevents other processes from using those GPUs (even if the current process isn't using them).

请注意,如果您使用 CUDA_VISIBLE_DEVICES,设备名称 "/gpu:0""/gpu:1" 等.引用当前进程中的第 0 个和第 1 个可见设备.

Note that if you use CUDA_VISIBLE_DEVICES, the device names "/gpu:0", "/gpu:1", etc. refer to the 0th and 1st visible devices in the current process.

这篇关于更改 TensorFlow 中的默认 GPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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