【发布时间】:2023-06-27 18:07:01
【问题描述】:
我在运行 Ubuntu 14.04.4 LTS x64 的服务器上安装了 TensorFlow-GPU 1.0.0。
我知道我可以使用CUDA_VISIBLE_DEVICES 隐藏一个或多个 GPU。有时,我想隐藏所有 GPU,以便基于 TensorFlow 的程序只使用 CPU。结果我试了
username@server:/scratch/coding/src$ CUDA_VISIBLE_DEVICES="" python my_script.py
但这给了我错误信息:
E tensorflow/stream_executor/cuda/cuda_driver.cc:509] failed call to cuInit: CUDA_ERROR_NO_DEVICE
这是我使用的ConfigProto:
session_conf = tf.ConfigProto(
device_count={'CPU': 1, 'GPU': 1},
allow_soft_placement=True,
log_device_placement=False
)
sess = tf.Session(config=session_conf)
我知道我可以使用device_count={'GPU': 0} 来阻止基于TensorFlow 的程序使用GPU,但我想知道这是否可以在启动程序时从命令行实现(不更改ConfigProto)。
根据文档,选项 allow_soft_placement=True 应该让 TensorFlow 自动选择现有且受支持的设备来运行操作,以防指定的设备不存在。
当我看到这条消息时,我的第一反应是 CUDA 至少需要一个 GPU 才能成功加载,但我 read 说即使机器没有 GPU,也可以在机器上安装 GPU 驱动程序并使用 TensorFlow-GPU .
这是我用于测试的my_script.py 脚本:
import tensorflow as tf
a = tf.constant(1, name = 'a')
b = tf.constant(3, name = 'b')
c = tf.constant(9, name = 'c')
d = tf.add(a, b, name='d')
e = tf.add(d, c, name='e')
session_conf = tf.ConfigProto(
device_count={'CPU': 1, 'GPU': 1},
allow_soft_placement=True,
log_device_placement=False
)
sess = tf.Session(config=session_conf)
print(sess.run([d, e]))
【问题讨论】:
-
我认为这确实是一个警告而不是错误消息,我一直看到它并且一切正常
-
@YaroslavBulatov 很高兴知道。
-
@YaroslavBulatov 顺便说一句,欢迎您将您的评论转换为答案:0 赞和 0 答案的 Stack Exchange 问题可能会被自动删除。
标签: python tensorflow