之前已經裝過一次了,不過沒有做記錄,現在又要翻一堆博客安裝,長點記性,自己記錄下。
環境 ubuntu16.04 python2.7
商家送過來時候已經裝好了顯卡驅動,所以省去了一大麻煩。
剩下的就是安裝cuda和cudnn。
顯卡驅動與cuda版本是有對應關系的,官網上貼出的匹配表
我的顯卡驅動是384.130,與cuda8對應,於是下載cuda8,官網進去后就是cuda10,舊版本的地址 https://developer.nvidia.com/cuda-toolkit-archive
下載好后,一路回車,然后在是否安裝顯卡驅動時輸入no,因為顯卡驅動已經有了,選yes會被覆蓋掉。
安裝的默認路徑是/usr/local/cuda-8.0,我們需要手動添加該路徑到環境中,如下
$ sudo gedit ~/.bashrc
然后在后面添加兩行
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
另外在profile中也要添加上面兩行
$ sudo gedit /etc/profile
重啟一下,輸入nvcc -V
輸出如下
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
此時,cuda已經裝好了,接下來安裝cudnn.
cudnn的版本與cuda也是有對應關系的,如下
看到網上的教程中cuda8與cudnn6搭配的比較多,於是我采用cudnn6.
下載cudnn需要注冊帳號,挺麻煩的,看到有一個博客中直接用wget下載,試了一下,速度飛快,還省去了注冊帳號的麻煩。
wget http://developer.download.nvidia.com/compute/redist/cudnn/v6.0/cudnn-8.0-linux-x64-v6.0.tgz
然后需要解壓,並將頭文件和動態鏈接庫復制到cuda路徑中,
$ tar -zxvf cudnn-8.0-linux-x64-v6.0.tgz
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h
$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
有好多教程最后要創建軟鏈接,我沒有創建,直接安裝了tensorflow-gpu
pip install tensorflow-gpu
默認安裝的是1.12,版本應該是高了,結果需要cuda9,於是卸載了,重新安裝1.3
pip install tensorflow-gpu==1.3
用python測試了一下,輸出如下
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.Session()
2018-11-20 00:34:37.313431: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-11-20 00:34:37.313493: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-11-20 00:34:37.313515: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-11-20 00:34:37.313538: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-11-20 00:34:37.313559: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2018-11-20 00:34:37.467953: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-11-20 00:34:37.468324: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 0 with properties:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.582
pciBusID 0000:01:00.0
Total memory: 10.91GiB
Free memory: 10.54GiB
2018-11-20 00:34:37.468342: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0
2018-11-20 00:34:37.468348: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0: Y
2018-11-20 00:34:37.468355: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0)
<tensorflow.python.client.session.Session object at 0x7f93d7d96250>
一切正常,安裝成功。
參考資料
https://blog.csdn.net/weixin_41864878/article/details/79621210
https://www.cnblogs.com/wmxfd/p/installation_of_nvidia_graphics_driver_and_cuda8_and_cudnn6.html
https://blog.csdn.net/qq_34057614/article/details/81228746
https://blog.csdn.net/xiangxianghehe/article/details/79177833
https://blog.csdn.net/qq_38522539/article/details/80678412
https://www.cnblogs.com/chay/p/8038251.html#_label3
https://blog.csdn.net/zong596568821xp/article/details/80410416
https://blog.csdn.net/twt520ly/article/details/79415787