Change default GPU in TensorFlow

后端 未结 4 1837
情深已故
情深已故 2020-12-24 08:16

Based on the documentation, the default GPU is the one with the lowest id:

If you have more than one GPU in your system, the GPU with the lowest ID

4条回答
  •  一生所求
    2020-12-24 09:01

    As is stated in the documentation, you can use tf.device('/gpu:id') to specify a device other than the default.

    # This will use the second GPU on your system
    with tf.device('/gpu:1'):
        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)
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
    print sess.run(c)
    

提交回复
热议问题