首页 > 解决方案 > tensorflow 无法识别第二个 GPU (/gpu:1)

问题描述

我正在尝试使用 2 个 GPU,tensorflow 无法识别第二个。第二个 GPU 工作正常(在寡妇环境中)

When I set CUDA_VISIBLE_DEVICES=0 and run the program I see RTX2070 as GPU0
When I set CUDA_VISIBLE_DEVICES=1 and run the program I see GTX1050as GPU0
When I set CUDA_VISIBLE_DEVICES=0,1 and run the program I see RTX2070 as GPU0

所以基本上TF不识别GPU1,它同时一个GPU(GPU 0)有没有手动定义GPU1的命令?

卸载并重新安装,Cudann,python 3.7,tensorflow 和 keras(GPU 版本)。我在 Windows 10 上使用 anaconda。试图将 CUDA_VISIBLE_DEVICES 更改为 0、1。我没有看到任何错误,但第二个 GPU 没有出现在 python 的任何地方。

主 GPU 是 RTX2070 (8GB),第二个 GPU 是 GTX1050 (2GB)。在我提交之前,我花了一些时间寻找解决方案,并尽我所能在互联网上找到。驱动程序是最新的,安装了 64 位版本和最新版本的软件。除了没有出现第二个 GPU 之外,我没有看到任何问题。

这些代码在第一个 GPU 上运行良好,两者都具有 > 3.5 的计算能力。

标签: tensorflowkerasmultiple-gpu

解决方案


在此处提供解决方案(答案部分),即使它出现在评论部分(感谢 M 学生分享解决方案),以造福社区。

在代码开头添加这个解决了这个问题

import os 
os.environ["TF_MIN_GPU_MULTIPROCESSOR_COUNT"]="2" 
os.environ["CUDA_VISIBLE_DEVICES"]="0,1"

推荐阅读