【发布时间】:2018-11-05 15:19:47
【问题描述】:
从 tensorflow 网站 (https://www.tensorflow.org/guide/using_gpu) 我找到了以下代码来手动指定使用 CPU 而不是 GPU:
# Creates a graph.
with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
我尝试在我的机器(有 4 个 GPU)上运行它并收到以下错误:
2018-11-05 10:02:30.636733: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:18:00.0
totalMemory: 10.92GiB freeMemory: 10.76GiB
2018-11-05 10:02:30.863280: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 1 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:3b:00.0
totalMemory: 10.92GiB freeMemory: 10.76GiB
2018-11-05 10:02:31.117729: E tensorflow/core/common_runtime/direct_session.cc:158] Internal: failed initializing StreamExecutor for CUDA device ordinal 2: Internal: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_OUT_OF_MEMORY; total memory reported: 11721506816
Traceback (most recent call last):
File "./tf_test.py", line 10, in <module>
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
File ".../anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1566, in __init__
super(Session, self).__init__(target, graph, config=config)
File ".../anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 636, in __init__
self._session = tf_session.TF_NewSession(self._graph._c_graph, opts)
tensorflow.python.framework.errors_impl.InternalError: Failed to create session.
似乎当我创建会话时,tensorflow 尝试在所有设备上初始化流执行器。不幸的是,我的同事现在正在使用其中一个 GPU。我希望他对一个 GPU 的充分使用不会妨碍我使用另一个设备(无论是 GPU 还是 CPU),但事实似乎并非如此。
有人知道解决方法吗?也许要添加到配置中?这是可以在 tensorflow 中修复的吗?
仅供参考...这是“gpustat -upc”的输出:
<my_hostname> Mon Nov 5 10:19:47 2018
[0] GeForce GTX 1080 Ti | 36'C, 0 % | 10 / 11178 MB |
[1] GeForce GTX 1080 Ti | 41'C, 0 % | 10 / 11178 MB |
[2] GeForce GTX 1080 Ti | 38'C, 0 % | 11097 / 11178 MB | <my_colleague>:python2/148901(11087M)
[3] GeForce GTX 1080 Ti | 37'C, 0 % | 10 / 11178 MB |
【问题讨论】:
标签: python tensorflow gpgpu