在多个gpu上运行Tensorflow

时间:2017-12-06 10:38:18

标签: tensorflow tensorflow-gpu

我检查了网站,但一如既往地我不清楚。任何人都可以描述所有的步骤(从一开始)在GPU上运行任何张量流程序吗?

1 个答案:

答案 0 :(得分:1)

来自Tensorflow官方网站: https://www.tensorflow.org/tutorials/using_gpu

# Creates a graph.
c = []
for d in ['/device:GPU:2', '/device:GPU:3']:
  with tf.device(d):
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3])
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2])
    c.append(tf.matmul(a, b))
with tf.device('/cpu:0'):
  sum = tf.add_n(c)
# 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(sum))