前言
在安装GPU环境下的软件工具,特别是CUDA/CUDNN等,一定要先把GPU环境搭建好。
NVIDIA驱动安装会遇到各种问题,真希望黄教主可以将各个工具如何安装使用讲解的更加细致、清楚一些,有时候按照官网的步骤安装也会遇到各种问题。
NVIDIA驱动的安装一定要与显卡类型、linux内核版本匹配,驱动安装好之后,软件工具的安装版本也一定要与驱动版本、内核版本匹配,这个容易出问题。
博主使用*.run文件安装NVIDIA驱动,可以参考NVIDIA官网here。
操作过程
首先,需要验证本地环境是否适合安装NVIDIA驱动,安装之前需要一些准备工作,参考here;
然后,安装Nvidia显卡的官方驱动和系统自带的nouveau驱动冲突,需要禁用Nouveau驱动Disable the Nouveau drivers 。
1)创建一个文件/etc/modprobe.d/blacklist-nouveau.conf,文件内容如下。
blacklist nouveau options nouveau modeset=0
2) 重新生成initramfs内核;
sudo update-initramfs -u
3)使用Alt+Ctrl+F1退出图形模式,进入命令行模式。
4)关闭图像界面模式;
sudo service lightdm stop
5) 运行CUDA Toolkit的run文件。
sudo sh cuda_xxx.run
运行的过程中,记得其中的OpenGl选项选择no,特别注意选择yes/no的时候要仔细点。
6) 安装完成之后需要重启图像界面,但是在进入图形模式之前,需要开启lightdm,一定要记住.
sudo service lightdm start
7) 使用Alt+Ctrl+F7退出命令行模式,进入图形模式。
另外,在安装驱动和CUDA之前需要将之前安装的文件卸载。
基于CUDA Toolkit的run文件安装时,卸载驱动方法如下:
# Use the following command to uninstall a Toolkit runfile installation: $ sudo /usr/local/cuda-X.Y/bin/uninstall_cuda_X.Y.pl # Use the following command to uninstall a Driver runfile installation: $ sudo /usr/bin/nvidia-uninstall
8) 安装之后需要查看是否有正确的文件权限。
Check that the device files/dev/nvidia* exist and have the correct (0666) file permissions. These files are used by the CUDA Driver to communicate with the kernel-mode portion of the NVIDIA Driver. Applications that use the NVIDIA driver, such as a CUDA application or the X server (if any), will normally automatically create these files if they are missing using the setuidnvidia-modprobe tool that is bundled with the NVIDIA Driver. However, some systems disallow setuid binaries, so if these files do not exist, you can create them manually by using a startup script such as the one below:
查看命令
ls /dev/nvidia*
如果没有需要创建如下文件,文件名自定义。
#!/bin/bash /sbin/modprobe nvidia if [ "$?" -eq 0 ]; then # Count the number of NVIDIA controllers found. NVDEVS=`lspci | grep -i NVIDIA` N3D=`echo "$NVDEVS" | grep "3D controller" | wc -l` NVGA=`echo "$NVDEVS" | grep "VGA compatible controller" | wc -l` N=`expr $N3D + $NVGA - 1` for i in `seq 0 $N`; do mknod -m 666 /dev/nvidia$i c 195 $i done mknod -m 666 /dev/nvidiactl c 195 255 else exit 1 fi /sbin/modprobe nvidia-uvm if [ "$?" -eq 0 ]; then # Find out the major device number used by the nvidia-uvm driver D=`grep nvidia-uvm /proc/devices | awk '{print $1}'` mknod -m 666 /dev/nvidia-uvm c $D 0 else exit 1 fi
9) 安装完成之后可能会出现界面分辨率不正常的问题,可参考here;
也可能遇到无法进入图像界面的情况,可尝试使用以下命令。
使用Alt+Ctrl+F1进入命令行模式,然后kill系统进程。
sudo pkill Xorg or sudo restart lightdm
总结
目前博主已经多次安装过CUDA和NVIDIA,期间遇到过各种意想不到的问题,参考过很多博客,特别注意一点安装NVIDIA驱动之后一定不能随随便便更新系统环境,因为不小心系统NVIDIA驱动就被更新了,这时候就惨了,你需要冲新安装NVIDIA驱动和CUDA等,安装的时候最好是参考NVIDIA官网,结合着博客,进行操作。
参考
1. https://oldpan.me/archives/pytorch-gpu-ubuntu-nvidia-cuda90 ;
2. https://docs.nvidia.com/cuda/archive/9.0/cuda-installation-guide-linux/index.html#runfile-nouveau;
3. https://blog.csdn.net/u011884290/article/details/52082809;
4. https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.13/;
5. https://developer.nvidia.com/cuda-toolkit-archive;
6. 官网;
7. tensorflow各个版本的CUDA以及Cudnn版本对应关系;
完