After 4 days of tossing, I finally installed the tensorflow-gpu version. This tutorial is to make a record for myself, and the second is to give you a reference to save installation time as much as possible.
Hardware: CPU: i5-7400, GPU: GeForce GTX1050Ti
System: Ubuntu 16.04, cuda 8.0, cudnn v5
1 Preparations before installation
1.1 Check whether your GPU meets the installation conditions
Open a terminal and enter the following command:
lspci | grep -i nvidia
According to the displayed GPU information, go to the CUDA official website to check whether it is supported. You can also search for the NVIDIA GPU computing power table on Baidu. The computing power is greater than or equal to 3.0 and you can install it.
1.2 Check the gcc version in your system
Enter the following command in the terminal:
gcc --version
If you are also installing cuda 8.0, you need to lower the gcc compiler version to below 5.0. The downgrade operation is as follows:
Enter the following command in the terminal:
sudo apt-get install g++-4.9 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10 sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 sudo update-alternatives --set cc /usr/bin/gcc sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 sudo update-alternatives --set c++ /usr/bin/g++
1.3 Install the kernel header files
Enter the following command in the terminal:
sudo apt-get install linux-headers-$(uname -r)
1.4 Install some dependent libraries of cuda
Enter the following command in the terminal:
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
2 Install the NVIDIA driver
2.1 Disable nouveau before installing the driver
Enter the following command in the terminal:
lsmod | grep new
If there is output, nouveau is loading. Create a blacklist-nouveau.conf in /etc/modprobe.d, first cd to the target directory, and then enter the following command in the terminal:
sudo touch blacklist-new.conf sudo chmod a+w+r blacklist-nouveau.conf gedit blacklist-new.conf
In the file enter:
blacklist new options new modeset=0
After saving and exiting, type in the terminal:
sudo update-initramfs -u
After restarting the system, enter again in the terminal:
lsmod | grep new
Make sure there is no output.
2.2 Download the driver
Download the driver version corresponding to your graphics card (https://www.geforce.cn/drivers). Note that some of the latest driver versions require the support of gcc 5.4. If you are prompted to install the driver, gcc 5.4 can download the previous driver version.
2.3 Install the driver
If the driver has been installed using "Software and Updates" in the system settings, it is recommended to uninstall it. The terminal input is as follows:
sudo apt-get remove --purge nvidia*
To close the X service, enter in the terminal:
sudo service lightdm stop
Ctrl+Alt+F1 to enter text mode, cd to the downloaded driver directory, and enter the command:
sudo chmod +x NVIDIA-Linux-x86_64-375.66.run sudo ./NVIDIA-Linux-x86_64-375.66.run --no-opengl-files
After the installation is complete, restart the system, enter the graphical interface, and enter in the terminal:
nvidia-smi
Check if the driver is installed successfully.
You can also type in the terminal:
nvidia-settings
Check if the driver is installed successfully.
3 Install CUDA
3.1 Download CUDA
Here I downloaded the runfile of cuda 8.0 (https://developer.nvidia.com/cuda-80-download-archive).
3.2 Install CUDA
cd to the downloaded cuda directory and enter in the terminal:
sudo chmod a+x cuda_8.0.44_linux.run sudo sh cuda_8.0.44_linux.run
After execution, an installation statement will appear, press Q to exit. Then accept the installation, when you encounter the first prompt whether to install the NVIDIA driver, enter n (the second step is to install the driver), the second prompt whether to install the CUDA Toolkit, enter y, the default is to enter y or press Enter to use the default path Install.
After the installation is complete, add the configuration environment and enter in the terminal:
echo 'export PATH=/usr/local/cuda-8.0/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc
After restarting the system, enter in the terminal:
nvcc --version
The output is similar to the following information table on the successful installation.
3.3 Try to compile the Samples provided by CUDA
cd to the Samples directory (the default path is ~/NVIDIA_CUDA-8.0_Samples), and enter:
make
After the compilation is complete, you can find bin/x86_64/linux/release/ in the Samples directory, cd to this directory, and enter the terminal:
./deviceQuery
Enter the following:
4 Install cuDNN
4.1 Download cuDNN
Here I downloaded cudnn v5.1 (https://developer.nvidia.com/rdp/cudnn-archive).
4.2 Install cuDNN
cd to the downloaded cudnn directory and enter in the terminal:
tar xvzf cudnn-8.0-linux-x64-v5.1-ga.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 /usr/local/cuda/lib64/libcudnn*
5 Install TensorFlow
5.1 Refer to the official website
Go to the official website to check the TensorFlow version corresponding to cuda and cudnn (to correspond to the Python version, here I am Python 3.5).
5.2 Install tensorflow_gpu
Here I refer to the official website (https://www.tensorflow.org/install/), use tensorflow 1.0.0 installed by pip3, and enter the following in the terminal:
pip3 install --upgrade \https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp35-cp35m-linux_x86_64.whl
After installation, if the output of import tensorflow is as follows, it means that TensorFlow runs successfully.
6 Frequently Asked Questions
6.1 Driver installation error or login screen loop
To uninstall the driver, enter the following in the terminal:
sudo /usr/bin/nvidia-uninstall
6.2 CUDA installation errors
To uninstall cuda, the terminal input is as follows:
sudo /usr/local/cuda-7.5/bin/uninstall_cuda_7.5.pl
6.3 Dependency library error when installing cuda
Method 1: Change the software source to Tsinghua source
Method 2: Install an aptitude first, and enter in the terminal:
sudo apt-get install aptitude
Then use the aptitude tool to install qt-sdk, which will contain the required dependency libraries, enter in the terminal:
sudo aptitude install qt-sdk
7 Reference Blog
Ubuntu16.04+GTX1050+CUDA8.0 configure deep learning environment https://blog.csdn.net/sikao_luwei/article/details/69375126
Install TensorFlow (GPU acceleration) under ubuntu16.04 ---- detailed graphic tutorial https://blog.csdn.net/zhaoyu106/article/details/52793183
2. CUDA installation and testing https://blog.csdn.net/u012235003/article/details/54575758