准备工作
1.检查自己的GPU是否是CUDA-capable
在终端中输入:
lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c03 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 10f1 (rev a1)
2.在终端中输入:
uname -r
可以查看自己的kernel版本信息
比如我的是
4.10.0-37-generic
那么就上网查找我的4.10的内核对应的ubuntu版本,查到我的对应的内核是ubuntu17.4,cuda下载9.0(后面要用)
3.在终端里面输入:
sudo apt-get install linux-headers-$(uname -r)
可以安装对应kernel版本的kernel header和package development
4.安装nvidia驱动
可以在 程序启动器–程序–设置–找到对应的推荐的nvidia 版本
sudo apt-get install nvidia-384.90
5 .查看nvidia的命令
nvidia-smi
比如我的是这样子:
Thu Nov 30 15:28:20 2017
+—————————————————————————–+
| NVIDIA-SMI 384.90 Driver Version: 384.90 |
|——————————-+———————-+———————-+
| 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 GTX 106… Off | 00000000:01:00.0 On | N/A |
| 49% 28C P8 9W / 120W | 309MiB / 6071MiB | 0% Default |
+——————————-+———————-+———————-+
+—————————————————————————–+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1187 G /usr/lib/xorg/Xorg 41MiB |
| 0 1246 G /usr/bin/sddm-greeter 40MiB |
| 0 1845 G /usr/lib/xorg/Xorg 134MiB |
| 0 2014 G kwin_x11 25MiB |
| 0 2017 G /usr/bin/krunner 1MiB |
| 0 2019 G /usr/bin/plasmashell 62MiB |
+—————————————————————————–+
搜索nvidia驱动:
apt-cache search nvidia | more
glxinfo | grep rendering
dpkg -l | grep nvidia
lspci | grep -i nvidia
lsmod | grep nvidia
7.正式安装过程:
官网下载cuda-9.0.run(https://developer.nvidia.com/cuda-downloads);
下载deb 包就可以了。
8.然后按照官方给的方法安装cuda9.0
Installation Instructions:
sudo dpkg -i cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64.deb
sudo apt-key add /var/cuda-repo-
sudo apt-get update
sudo apt-get install cuda
(最后开始安装cuda以及显卡驱动(安装cuda的同时就会把显卡驱动也全部安装好,这个真的很方便。但是下载的时间有点长,有人说安装cuda的同时会把显卡驱动安好,这个我没有试过,但是我的建议是还是先把nvida的驱动安装好)
9.安装完毕后:
测试一下nvidia 信息:
nvidia-smi
如果没有出错,进行下一步,当然可以经常用第6步的命令查看下显卡驱动
然后:
测试一下cuda的相关例子,我将 cuda9.0下的sample拷贝到一个临时目录下进行编译:
cp -r /usr/local/cuda-9.0/samples/ .
cd samples/
make
然后运行几个例子来看一下:
cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
make
sudo ./deviceQuery
如果显示:
Detected 1 CUDA Capable device(s)
Device 0: “GeForce GTX 1060 6GB”
CUDA Driver Version / Runtime Version 9.0 / 9.0
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 6071 MBytes (6366363648 bytes)
(10) Multiprocessors, (128) CUDA Cores/MP: 1280 CUDA Cores
GPU Max Clock rate: 1759 MHz (1.76 GHz)
Memory Clock rate: 4004 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 1572864 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 9.0, NumDevs = 1
Result = PASS
注意到最后有个pass,说明安装成功了!
10.最后在 ~/.bashrc 里再设置一下cuda的环境变量:
export PATH=/usr/local/cuda/binPATH:+:$PATHexportLDLIBRARYPATH=/usr/local/cuda/lib64{LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda
source ~/.bashrc (让其生效。)
11.相关的参考:
1:https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1704&target_type=deblocal
2:http://m.blog.csdn.net/qq_20836725/article/details/45917909
(这个版本里面是进入到命令行模式安装的,其实最新的版本,cuda9.0是不需要的)
3:http://blog.csdn.net/u012235003/article/details/54575758
4:https://www.cnblogs.com/upright/p/4982319.html
5:http://developer.download.nvidia.com/compute/cuda/7.5/Prod/docs/sidebar/CUDA_Installation_Guide_Linux.pdf
6:https://ju.outofmemory.cn/entry.38690(这篇博客给了我很大的启发,ubuntu17.04+nvidia gtx 1080+cuda 9.0+)