#配置#
×系统:manjaro19.01×
×CPU:i7-9750h×
×GPU:gtx1660ti×
×无核显×
#1.安装最新版的cuda和cudnn
sudo pacman -S cuda cudnn
上述命令为最新版本cuda和cudnn
若不想要最新版本可用 yay命令安装
#编译(大概30分钟)
cd /opt/cuda/samples/bin/x86_64/linux/release
./deviceQuery
#2.安装TensorFlow-gpu
pip install tensorflow-gpu==1.15
或者
pip install tensorflow-gpu==2.0
#3.验证安装是否成功和是够为gpu版本
import tensorflow as tf
# 新建一个 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)
# 新建session with log_device_placement并设置为True
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# 运行这个 op
print (sess.run(c))
#任务完成,关闭会话
sess.close()
运行结果:
Device mapping:
/job:localhost/replica:0/task:0/device:XLA_CPU:0 -> device: XLA_CPU device
/job:localhost/replica:0/task:0/device:XLA_GPU:0 -> device: XLA_GPU device
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1660 Ti, pci bus id: 0000:01:00.0, compute capability: 7.5
[[22. 28.]
[49. 64.]]