确定自己的TensorFlow是CPU还是GPU的版本

在Python环境中输入:


    import numpy  
    import tensorflow as tf  
    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))  

之后就会出现详细的信息:


    Device mapping:  
    /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K40c, pci bus  
    id: 0000:05:00.0  
    b: /job:localhost/replica:0/task:0/device:GPU:0  
    a: /job:localhost/replica:0/task:0/device:GPU:0  
    MatMul: /job:localhost/replica:0/task:0/device:GPU:0  
    [[ 22.  28.]  
     [ 49.  64.]]  

就能看到是GPU在工作还是CPU再工作了。

猜你喜欢

转载自blog.csdn.net/weixin_37251044/article/details/79790270