Ubuntu 18.04 安装cuda

1. 查看服务器信息

cat /etc/issue
Ubuntu 18.04.2 LTS

uname -a 
Linux cool-Aspire-E1-471G 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

2. 寻找合适的驱动版本.执行命令ubuntu-drivers devices显示GeForce GT 620M/630M/635M/640M建议的驱动版本是390

 == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
 modalias : pci:v000010DEd00000DE9sv00001025sd00000732bc03sc00i00
 vendor   : NVIDIA Corporation
 model    : GF108M [GeForce GT 620M/630M/635M/640M LE]
 driver   : nvidia-340 - distro non-free
 driver   : nvidia-304 - third-party free
 driver   : nvidia-driver-390 - distro non-free recommended
 driver   : xserver-xorg-video-nouveau - distro free builtin

 == /sys/devices/pci0000:00/0000:00:1c.7/0000:09:00.0 ==
 modalias : pci:v000014E4d00004727sv0000105Bsd0000E042bc02sc80i00
 vendor   : Broadcom Limited
 model    : BCM4313 802.11bgn Wireless Network Adapter
 driver   : bcmwl-kernel-source - distro non-free

3. 安装nvidia driver,我的电脑是 独显加集显所以可以先卸载。如果你的是独显你就直接关掉终端吧要不然执行下边命令后就没有终端了

# 卸载
sudo apt-get --purage remove nvida-*

# 安装
sudo apt-get install nvidia-390

# 重启
sudo reboot

4. 重启正常开机后,查看驱动的安装状态

sudo nvidia-smi

Wed Mar 27 21:02:55 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.116                Driver Version: 390.116                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GT 630M     Off  | 00000000:01:00.0 N/A |                  N/A |
| N/A   46C    P8    N/A /  N/A |    371MiB /   964MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0                    Not Supported                                       |
+-----------------------------------------------------------------------------+

5. 先查看cuda各版本支持情况

Table 1. Native Linux Distribution Support in CUDA 10.1
Distribution    Kernel* GCC GLIBC   ICC PGI XLC CLANG
x86_64
RHEL 7.6    3.10    4.8.5   2.17    19.0    18.x, 19.x  NO  7.0.0
RHEL 6.10   2.6.32  4.4.7   2.12
CentOS 7.6  3.10    4.8.5   2.17
CentOS 6.10 2.6.32  4.4.7   2.12
Fedora 29   4.16    8.0.1   2.27
OpenSUSE Leap 15.0  4.15.0  7.3.1   2.26
SLES 15.0   4.12.14 7.2.1   2.26
SLES 12.4   4.12.14 4.8.5   2.22
Ubuntu 18.10    4.18.0  8.2.0   2.28
Ubuntu 18.04.1 (**) 4.15.0  7.3.0   2.27
Ubuntu 16.04.5 (**) 4.4 5.4.0   2.23
Ubuntu 14.04.5 (**) 3.13    4.8.4   2.19
POWER8(***)
RHEL 7.6    3.10    4.8.5   2.17    NO  18.x, 19.x  13.1.x, 16.1.x  7.0.0
Ubuntu 18.04.1  4.15.0  7.3.0   2.27    NO  18.x, 19.x  13.1.x, 16.1.x  7.0.0
POWER9(****)
Ubuntu 18.04.1  4.15.0  7.3.0   2.27    NO  18.x, 19.x  13.1.x, 16.1.x  7.0.0
RHEL 7.6 IBM Power LE   4.14.0  4.8.5   2.17    NO  18.x, 19.x  13.1.x, 16.1.x  7.0.0

6. 安装

去官网 https://developer.nvidia.com/cuda-downloads 选择对应的版本

注意根据你的服务器版本支持不同
Installation Instructions:
`sudo dpkg -i cuda-repo-ubuntu1804-10-1-local-10.1.105-418.39_1.0-1_amd64.deb`
`sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub`
`sudo apt-get update`
`sudo apt-get install cuda`

7. 测试安装成功

cd /usr/local/cuda-{version}/samples/1_Utilities/deviceQuery/

# 执行
./deviceQuery