检查GPU运行情况:
nvidia smi
可以看到此时GPU没有被使用
运行代码:
import tensorflow as tf
with tf.device('/gpu: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)
此时再查看
nvidia smi
能够看到
能够看到GPU已经被调用
证明tensorflow可以使用GPU,cuda和cudnn安装版本合适
(运行注意是否默认使用CPU还是GPU,这里只能证明cuda和cudnn版本合适,你的电脑可以调用GPU)