考虑到字体原因, 以下关键步骤均用英文. 经过实测, 整个过程未禁用 nouveau
NVIDIA GTX 166ti + CUDA10.0+cudnn7.6.2 + tensorflow-gpu1.14.0 + ubuntu18.04 + pycharm2019.2
1, Check the local environment under Ubuntu18.04 (在Ubuntu18.04下检查本机环境):
https://ubuntu.com/download/desktop # download ubuntu desktop version here if needed
1>, Settting--> Details: Ubuntu 18.04.03
# should dispaly "grapics: Intel" after the installation of Ubuntu.
2>, Software & Updates: Additional Drivers:
# should display two lines as following:
NVIDIA: nvidia-driver-430
X.Org X server # this line is selected
2, download: cuda_10.0.130_410.48_linux.run; cudnn-10.0-linux-x64-v7.6.2.24
https://www.nvidia.cn/Download/index.aspx?lang=cn # do NOT need download drivers
https://developer.nvidia.com/cuda-10.0-download-archive
https://developer.nvidia.com/rdp/cudnn-download # need login first
3, in Software & Updates: Additional Drivers, change to Nvidia-driver, need reboot;
then check: NVIDIA: "nvidia-driver-430" is selected
4, install CUDA, do NOT install driver;
5, copy the cudnn:
Copy the following files into the CUDA Toolkit directory, and change the file permissions.
$ 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 /usr/local/cuda/lib64/libcudnn*
$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
6, $ sudo gedit ~/.bashrc
export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
$ source ~/.bashrc
7, $ sudo apt-get ./install python3-pip
$ pip3 -V
$ sudo apt-get remove python-pip // uninstall pip for python2.7, don't do this~
8, pip3 install -r pip_install.txt, which contains:
tensorflow-gpu
numpy
scipy
matplotlib
pillow
9, python3 ./gpuTest.py ,which content is as following:
print("a test of gpu\n")
import tensorflow as tf
a = tf.constant([1.0,2.0,3.0],shape = [3], name='a')
b = tf.constant([1.0,2.0,3.0], shape = [3], name='b')
c = a +b
sess = tf.Session(config = tf.ConfigProto(log_device_placement =True))
cc = sess.run(c)
print(cc)
#should display as following:
add: (Add): /job:localhost/replica:0/task:0/device:GPU:0
a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
[2. 4. 6.]
10, if can't use GPU in pycharm:
pycharm --> Settings --> Project Interpreter --> Interpreter Paths --> add --> /usr/local/cuda-10.0/bin
sudo ldconfig /usr/local/cuda-10.0/lib64 // for pycharm
11, if "could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR", using sess as:
config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)