【发布时间】:2019-04-19 22:24:22
【问题描述】:
我读过
os.environ["CUDA_VISIBLE_DEVICES"] = ''
注意 tensorflow 将在 CPU 上运行,并且
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
注意 tensorflow 将在 GPU 0 上运行。
我如何检查,使用的是哪个设备?
代码
# Creates a graph.
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))
只显示结果
[[ 22. 28.]
[ 49. 64.]]
并且没有使用过的设备等。
【问题讨论】:
标签: tensorflow gpu cpu