安装ubuntu CUDA

卸载显卡驱动:sudo apt-get remove –purge nvidia-*

一、检查GPU是否支持CUDA

lspci | grep -i nvidia

这个命令会列出你当前显卡的类型,然后去 http://developer.nvidia.com/
cuda-gpus这个网站检查是否支持。一般集成显卡用来作2D的显示,而不是用NVIDIA的。

二、接下来disabling Nouveau

lsmod | grep nouveau

这个命令会查看是否加载了nouveau。创建/etc/modprobe.d/blacklist-nouveau.conf 文件,然后输入:

blacklist nouveau options nouveau modeset=0

重新生成kernel initramfs

sudo update-initramfs -u

三设置启动级别
1、切换到文本模式 也就是runlevel 3,输入下面的命令

1): 运行 sudo gedit /etc/default/grub
2): 找到 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
3): 改为 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash text”
4): 运行 sudo update-grub #重新生成GRUB的启动菜单

2、由于此时NVIDIA的驱动还没安装,teminal的显示可能有异常,所以可以在boot参数后面加上nomodeset。

nomodeset的作用:
The newest kernels have moved the video mode setting into the kernel. So all the programming of the hardware specific clock rates and registers on the video card happen in the kernel rather than in the X driver when the X server starts.. This makes it possible to have high resolution nice looking splash (boot) screens and flicker free transitions from boot splash to login screen. Unfortunately,on some cards this doesnt work properly and you end up with a black screen. Adding the nomodeset parameter instructs the kernel to not load video drivers and use BIOS modes instead until X is loaded.
最新的内核已经把视频模式的设置放在内核来执行了,所以所有显卡相关的时钟频率设置、寄存器设置程序是在kernel里面执行,而不是等到X server启动后通过 X driver来实现,这使得我们在启动时可以看到不闪的和高分辨率的好看的启动界面,但是,在某些视频卡上不能兼容导致黑屏。可以通过增加nomodeset参数告诉内核不要加载显卡驱动而用BIOS模式直到图形界面运行后通过X server里的 X driver来来执行。

3、由于在nouveau还加载或者显卡处于活动状态时不能成功的安装显卡的驱动,所以要重启。

四、运行run文件开始安装cuda,因为集成显卡用来作2D的显示,所以不安装opengl,所以输入下面的命令

sudo sh cuda_<version>_linux.run --no-opengl-libs

五、Device Node Verification
增加下面的启动脚本

#!/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

假如脚本名字为test,可先将脚本test复制到/etc/init.d/目录下,然后用:
sudo chmod 755 /etc/init.d/test 更改权限
update-rc.d test defaults 99

卸载脚本:sudo update-rc.d -f test remove

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...