安装NVIDIA驱动
查看可安装的硬件驱动:
1 | ubuntu-drivers devices |
== /sys/devices/pci0000:2c/0000:2c:00.0/0000:2d:00.0 ==
modalias : pci:v000010DEd00001BB1sv0000103Csd000011A3bc03sc00i00
vendor : NVIDIA Corporation
model : GP104GL [Quadro P4000]
manual_install: True
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-450-server - distro non-free recommended
driver : nvidia-driver-440-server - distro non-free
driver : nvidia-driver-390 - distro non-free
driver : nvidia-driver-450 - distro non-free
driver : nvidia-driver-435 - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
安装驱动:
1 | sudo ubuntu-drivers autoinstall |
安装完成以后进行重启:
1 | sudo reboot |
查看驱动版本:
1 | sudo dpkg --list | grep nvidia-* |
1 | ii libnvidia-cfg1-450-server:amd64 450.51.06-0ubuntu0.18.04.2 amd64 NVIDIA binary OpenGL/GLX configuration library |
参考资料:
安装CUDA
下载CUDA
前往下载页面选择和本机硬件系统相对应的CUDA版本,选好后会自动生成下载命令:
我的配置:Linux、x86_64、Ubuntu、18.04、runfile(local)
1 | wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run |
安装CUDA
由于我已经安装了驱动,在安装CUDA的时候会有一个提示,选择continue
。
之后会让你阅读声明,直接输入accept
回车就行了。
接下来会进入安装选项界面,可以配置一些安装参数。首先先把驱动取消勾选,其他保持默认即可。
安装完成后显示如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-11.1/
Samples: Installed in /home/ubuntu/, but missing recommended libraries
Please make sure that
- PATH includes /usr/local/cuda-11.1/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-11.1/lib64, or, add /usr/local/cuda-11.1/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.1/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least .00 is required for CUDA 11.1 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run --silent --driver
Logfile is /var/log/cuda-installer.log
验证CUDA
先配置环境变量:
1 | export PATH="/usr/local/cuda-11.1/bin:$PATH" |
然后输入:
1 | nvcc -V |
之前的配置正确的话会输出版本信息:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
编译samples例子:
1 | #编译并测试设备 deviceQuery: |
正常情况下会输出Result = PASS
将cuda的bin和lib写入系统环境:
打开~.bashrc
文件在末尾追加:
1 | export CUDA_HOME=/usr/local/cuda-11.1 |
参考资料:
安装cuDNN
下载cuDNN
下载地址:https://developer.nvidia.com/rdp/cudnn-archive
选择对应CUDA版本的cuDNN:cuDNN Library for Linux (x86_64)
经过多次尝试,官网的下载链接老是断开连接下载失败,于是在网上找到了一个镜像下载地址。只需要把下载链接中的版本号改为自己需要的就行了,然后复制到迅雷中下载,速度很快。下载好以后再传到服务器。
1 | http://file.ppwwyyxx.com/nvidia/cudnn-11.0-linux-x64-v8.0.2.39.tgz |
安装cuDNN
如果是在官网下载,下载下来的文件格式为.solitairetheme8
,要解压的话需要转换为.tgz
格式,直接修改后缀即可。
首先将压缩包解压:
1 | tar -xvf cudnn-11.0-linux-x64-v8.0.2.39.tgz |
解压好以后会看到一个cuda
文件夹,接下来执行如下命令:
1 | # 复制cudnn头文件 |
整个安装过程实际上就是把cuDNN的头文件和静态库文件拷贝到CUDA的相应目录下。
验证cuDNN
1 | cat /usr/local/cuda/include/cudnn.h |
参考资料: