Ubuntu 16.04下NVIDIA驱动安装、CUDA安装、cuDNN安装文档
参考: cuda、cudnn安装(多版本)
#!/bin/sh
#
# This is an explanatory file which describes NVIDIA drivers and CUDA + cuDNN
# Toolkit install steps.
#
# Author: hwrenx (hwrenx@126.com) 2019-05-01
exit 0 # should never run this script directly.
# ===================================================================================================
# CUDA Toolkit | Linux x86_64 Driver Version | Windows x86_64 Driver Version |
# --------------------------------------------------------------------------------------------------|
# CUDA 10.1.105 | >= 418.39 | >= 418.96 |
# CUDA 10.0.130 | >= 410.48 | >= 411.31 |
# CUDA 9.2 (9.2.148 Update 1) | >= 396.37 | >= 398.26 |
# CUDA 9.2 (9.2.88) | >= 396.26 | >= 397.44 |
# CUDA 9.1 (9.1.85) | >= 390.46 | >= 391.29 |
# CUDA 9.0 (9.0.76) | >= 384.81 | >= 385.54 |
# CUDA 8.0 (8.0.61 GA2) | >= 375.26 | >= 376.51 |
# CUDA 8.0 (8.0.44) | >= 367.48 | >= 369.30 |
# CUDA 7.5 (7.5.16) | >= 352.31 | >= 353.66 |
# CUDA 7.0 (7.0.28) | >= 346.46 | >= 347.62 |
# ===================================================================================================
# Should get NVIDIA driver via https://www.nvidia.cn/Download/index.aspx?lang=cn
NVIDIA_RUN_FILE=NVIDIA-Linux-x86_64-384.59.run
# CUDA version and NVIDIA driver must match
# Could get CUDA via https://developer.nvidia.com/cuda-toolkit-archive
CUDA_RUN_FILE=cuda_10.1.105_418.39_linux.run
CUDA_VERSION=10.1
# Corresponding cuDNN lib could be found in https://developer.nvidia.com/rdp/cudnn-archive
CUDNN_UNPACK_PATH=.
# Install needed librarys
sudo apt-get install freeglut3-dev \
build-essential \
libx11-dev \
libxmu-dev \
ibxi-dev \
libgl1-mesa-glx \
libglu1-mesa \
libglu1-mesa-dev
# Remove old nvidia drivers
sudo apt-get remove --purge nvidia*
# Grant permissions to the installation files
sudo chmod +x *.run
# Remove first in case anything remained
sudo sh $NVIDIA_RUN_FILE --uninstall
# sudo gedit /etc/modprobe.d/blacklist.conf
#
# ATTENTION: should only add once
# Disable open-source nvidia driver
# Throw it into blacklist :)
sudo echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
sudo echo "options nouveau modeset=0" >> /etc/modprobe.d/blacklist.conf
# Update
sudo update-initramfs -u
# Should run under cmd: Ctrl+Alt+(F1~F6)
sudo service lightdm stop
# Install driver, must disable openGL under ubuntu 16+
# Or there may have loop login appearance
# Choosing all default option is ok
sudo sh $NVIDIA_RUN_FILE –no-opengl-files # --no-x-check --no-nouveau-check --disable-nouveau
# Try print driver log to check whether the installation is successful
nvidia-smi
# Restart the graphical interface
# Ctrl+Alt+F7
sudo service lightdm restart
# Reboot
sudo reboot
# Install CUDA
sudo sh $CUDA_RUN_FILE --no-opengl-libs
# ATTENTION: should only add once
echo "export PATH=/usr/local/cuda/bin:$PATH" >>~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH" >>~/.bashrc
echo "export CUDA_HOME=/usr/local/cuda" >>~/.bashrc
# Link cuda files considering multi-version condition
sudo ln -s /usr/local/cuda-$CUDA_VERSION /usr/local/cuda
# Validate
source ~/.bashrc
# Try CUDA
nvcc --version
# Copy cuDNN files into CUDA
cd $CUDNN_UNPACK_PATH
sudo cp cuda/include/cudnn.h /usr/local/cuda-$CUDA_VERSION/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-$CUDA_VERSION/lib64
sudo chmod a+r /usr/local/cuda-$CUDA_VERSION/include/cudnn.h /usr/local/cuda-$CUDA_VERSION/lib64/libcudnn*
网友评论