安装cuda前关闭secure boot

禁用开源驱动nouveau

sudo vim /etc/modprobe.d/blacklist.conf
# 添加以下两行
blacklist nouveau
options nouveau modeset=0

# 更新内核
sudo update-initramfs -u
sudo reboot

# 查看是否禁用成功
lsmod | grep nouveau

# 查看哪些服务占用
sudo lsof | grep nvidia

# 禁用nvidia服务
# 停止gdm服务
sudo systemctl stop gdm3

# ubuntu 20.04
sudo systemctl stop lightdm

# 安装gcc
sudo apt update
sudo apt install build-essential

卸载驱动

sudo /usr/bin/nvidia-uninstall
sudo apt-get purge nvidia*

cuda

# 验证安装
# Verify running CUDA GPU jobs by compiling the samples and executing the deviceQuery or bandwidthTest programs.
cd /usr/local/cuda-7.0/samples
make
./deviceQuery

# 卸载cuda
sudo /usr/local/cuda-8.0/bin/uninstall_cuda-8.0.pl

查看显卡占用

nvidia-smi -l

# 查看GPU是否可用
lspci | grep -i nvidia

其实只安装cuda即可,cuda自带nvidia驱动

查看CUDA版本信息

# 添加cuda环境变量
export PATH=/usr/local/cuda/bin:${PATH}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}

# 更新动态链接库
ldconfig /usr/local/cuda-10.0/lib64

# 检测cuda安装情况
nvcc --version

cuDNN

# 安装cuDNN
sudo dpkg -i libcudnn8_x.x.x-1+cudax.x_amd64.deb
sudo dpkg -i libcudnn8-dev_8.x.x.x-1+cudax.x_amd64.deb
sudo dpkg -i libcudnn8-doc_8.x.x.x-1+cudax.x_amd64.deb

# 卸载cuDNN
dpkg -l | grep cudnn
dpkg --remove libcudnn8-doc
dpkg --remove libcudnn8-dev
dpkg --remove libcudnn8

# 验证cudnn安装
cp -r /usr/src/cudnn_samples_v8/ $HOME
cd  $HOME/cudnn_samples_v8/mnistCUDNN
# Compile the mnistCUDNN sample.
make clean && make
./mnistCUDNN
# Test passed!

# 查看cuDNN版本信息
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2

tensorflow找不到cudnn

CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/:$CUDNN_PATH/lib