lu@computer:~/project$ ubuntu-drivers devices
WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
== /sys/devices/pci0000:00/0000:00:1c.4/0000:04:00.0 ==
modalias : pci:v000010DEd00001347sv00001043sd00001A6Dbc03sc02i00
vendor : NVIDIA Corporation
model : GM108M [GeForce 940M]
driver : nvidia-driver-465 - third-party non-free
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-450-server - distro non-free
driver : nvidia-driver-390 - distro non-free
driver : nvidia-driver-460 - third-party non-free recommended
driver : nvidia-driver-460-server - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
lu@computer:~/project$
sudo apt-get purge nvidia*
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
在文件内添加如下内容:
blacklist nouveau
options nouveau modeset=0
更新一下:
sudo update-initramfs -u
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-driver-418-server
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
注意:
1.具体驱动名称是“nvidia-driver-xxx”还是“nvidia-xxx”,需要根据上面“ubuntu-drivers devices”输出结果,由上图可见在ubuntu20.04 上是“nvidia-driver-xxx”
2.cuda10.0对应的驱动是410以上的版本,故这里安装418版本
nvidia-smi
注意:
1.也可以执行下面指令自动安装所推荐的驱动,但这种方式没法选择驱动版本
sudo ubuntu-drivers autoinstall
链接:https://developer.nvidia.com/cuda-toolkit-archive
执行如下命令:
sudo bash cuda_10.0.130_410.48_linux.run
压住回车键,直到服务条款显示到100%。接着按下面的步骤选择:
accept
n(不要安装driver)
y
y
y
打开主目录下的 .bashrc文件添加如下路径,例如我的.bashrc文件在/home/lu/下。
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
export PATH=$PATH:/usr/local/cuda-10.0/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.0
终端运行:source ~/.bashrc
检查:nvcc --version
按需求下载cudnn的安装文件:https://developer.nvidia.com/rdp/cudnn-archive
解压下载的文件,可以看到cuda文件夹,在当前目录打开终端,执行如下命令:
sudo cp cuda/include/cudnn* /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn*
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
在终端输入
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2