1.调整分辨率
安装完毕后Ubuntu 16.04的分辨率很低,在显卡驱动未安装之前,可以手动修改一下grub文件:
[javascript] view plain copy
1. sudo vim /etc/default/grub
2. #The resolution used on graphical terminal
3. # note that you can use only modes which your graphic card supports via VBE
4. # you can see them in real GRUB with the command 'vbeinfo'
5. # GRUB_GFXMODE=640x480
将 GRUB_GFXMODE=640x480 改为 GRUB_GFXMODE=1024x768
然后用下面命令更新:
[javascript] view plain copy
1. sudo update-grub
2.更新UbuntuLTS 16.04源,此处用的是中科大的源
[javascript] view plain copy
1. cd /etc/apt/
2. sudo cp sources.list sources.list.bak
3. sudo vi sources.list
把下面的这些源添加到source.list文件头部:
[javascript] view plain copy
1. deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
2. deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
3. deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
4. deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
5. deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
6. deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
7. deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
8. deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
9. deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
10. deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
最后更新源和更新已安装的包:
[javascript] view plain copy
1. sudo apt-get update
2. sudo apt-get upgrade
3. sudo apt-get install build-essential
4. sudo apt-get autoremove
3.安装git
[javascript] view plain copy
1. sudo apt-get install git
4.安装pip
[javascript] view plain copysudo apt-get update
- sudo apt-get install python-pip
- sudo pip install --upgrade pip
- sudo pip install --upgrade virtualenv
5.安装NVIDIA驱动
查看显卡型号
lspci | grep -i nvidia
我们将使用apt-get来安装驱动。到 “Proprietary GPU Drivers” PPA中查看是否有你最新的驱动。注意,最新的驱动一定是最稳定的。你也可以安装网页上推荐的驱动版本。添加”Proprietary GPU Drivers” PPA 资源库。在写这篇文章的时候,最新版本是361.42,然而推荐版本是352:
sudo add-apt-repositoryppa:graphics-drivers/ppa
第一次运行出现如下的警告:
Fresh drivers from upstream, currently shipping Nvidia.
## Current Status
We currently recommend: `nvidia-361`, Nvidia's current longlived branch.
For GeForce 8 and 9 series GPUs use `nvidia-340`
For GeForce 6 and 7 series GPUs use `nvidia-304`
## What we're working on right now:
- Normal driver updates
- Investigating how to bring this goodness to distro on a cadence.
## WARNINGS:
This PPA is currently in testing, you should be experiencedwith packaging before you dive in here. Give us a few days to sort out thekinks.
Volunteers welcome! See also:https://github.com/mamarley/nvidia-graphics-drivers/
http://www.ubuntu.com/download/desktop/contribute
更多信息:https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa
按回车继续或者 Ctrl+c 取消添加
回车后继续:
sudo apt-get update
sudo apt-get installnvidia-367
sudo apt-getinstall mesa-common-dev
sudo apt-getinstall freeglut3-dev
重启系统
sudo shutdown -r now
检查以确保安装了正确版本的NVIDIA驱动
cat /proc/driver/nvidia/version
安装成功后,输入如下命令查看NVIDIA驱动是否安装成功,出现如下图所示的界面表示安装成功:图片中NVIDIA-SMI 367
[javascript] view plain copy
1. nvidia-smi
6.安装Cuda 8.0
在安装CUDA之前,google了一下,发现在Ubuntu16.04下安装CUDA7.5问题多多,幸好CUDA8已出,支持GTX1080:
New in CUDA 8
Pascal Architecture Support
Out of box performance improvements on Tesla P100, supports GeForce GTX 1080
Simplify programming using Unified memory on Pascal including support for largedatasets, concurrent data access and atomics*
Optimize Unified Memory performance using new data migration APIs*
Faster Deep Learning using optimized cuBLAS routines for native FP16computation
Developer Tools
Quickly identify latent system-level bottlenecks using the new critical pathanalysis feature
Improve productivity with up to 2x faster NVCC compilation speed
Tune OpenACC applications and overall host code using new profiling extensions
Libraries
Accelerate graph analytics algorithms with nvGRAPH
New cuBLAS matrix multiply optimizations for matrices with sizes smaller than512 and for batched operation
不过下载CUDA需要注册和登陆NVIDIA开发者账号,CUDA8下载页面提供了很详细的系统选择和安装说明,
这里选择了Ubuntu16.04系统runfile安装方案,千万不要选择deb方案,前方无数坑:
下载的“cuda_8.0.27_linux.run”有1.4G,按照Nivdia官方给出的方法安装CUDA8:
安装方式一(本机安装时采用的)
sudo shcuda_8.0.27_linux.run --tmpdir=/opt/temp/
这里加了--tmpdir主要是直接运行“sudosh cuda_8.0.27_linux.run”会提示空间不足的错误,其实是全新的电脑主机,硬盘足够大的,google了以下发现加个tmpdir就可以了:
Not enough space on parition mounted at /.
Need 5091561472 bytes.
Disk space check has failed.Installation cannot continue.
执行后会有一系列提示让你确认,非常非常非常非常关键的地方是是否安装361这个低版本的驱动:
Install NVIDIA Accelerated GraphicsDriver for Linux-x86_64 361.62?
答案必须是n,否则之前安装的GTX1080驱动就白费了,而且问题多多。
安装方式二(推荐以后采用)
[javascript] view plain copy
1. sudo sh cuda_8.0.61_375.26_linux.run
然后出现一系列提示,其中如下图红色字体表示缺少某些库文件:
[javascript] view plain copy
1. Do you accept the previously read EULA?
2. accept/decline/quit: accept
3. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?
4. (y)es/(n)o/(q)uit: n(备注:一定要选择n)
5. Install the CUDA 8.0 Toolkit?
6. (y)es/(n)o/(q)uit: y
7. Enter Toolkit Location
8. [ default is /usr/local/cuda-8.0 ]:
9. Do you want to install a symbolic link at /usr/local/cuda?
10. (y)es/(n)o/(q)uit: y
11. Install the CUDA 8.0 Samples?
12. (y)es/(n)o/(q)uit: y
13. Enter CUDA Samples Location
14. [ default is /home/its ]:
15. Installing the CUDA Toolkit in /usr/local/cuda-8.0 …
16. Missing recommended library: libGLU.so
17. Missing recommended library: libX11.so
18. Missing recommended library: libXi.so
19. Missing recommended library: libXmu.so
20. Installing the CUDA Samples in /home/its …
21. Copying samples to /home/its/NVIDIA_CUDA-8.0_Samples now…
22. Finished copying samples.
23. ===========
24. = Summary =
25. ===========
26. Driver: Not Selected
27. Toolkit: Installed in /usr/local/cuda-8.0
28. Samples: Installed in /home/its, but missing recommended libraries
29. Please make sure that
30. - PATH includes /usr/local/cuda-8.0/bin
31. - LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
32. To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
33. Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
34. ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
35. To install the driver using this installer, run the following command, replacing with the name of this run file:
36. sudo .run -silent -driver
37. Logfile is /tmp/cuda_install_2961.log
安装缺少的库
输入如下命令安装缺少的库:
[javascript] view plain copy
1. sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-devlibgl1-mesa-glx libglu1
设置环境变量
(方式一)
在终端输入这两句:
[javascript] view plain copy
1. export PATH=/usr/local/cuda-8.0/bin:$PATH
2. export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
然后输入如下命令是环境变量生效
[javascript] view plain copy
1. sudo gedit /etc/profile
2. sudo ldconfig //环境变量立即生效
(方式二)
echo'exportPATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo'exportLD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
检查以确保安装了正确版本的CUDA
nvcc -V
重启系统
sudo shutdown -r now
检查CUDA安装(可选)
在CUDA安装目录安装样例。编译它们(需要几分钟):
/usr/
local/cuda/bin/cuda
-install-samples-7.5.sh ~/cuda
-samples
cd ~/cuda
-samples/NVIDIA
*Samples
make
-j$(($(nproc)
+1))
注意:(-j$(($(nproc) + 1)))命令使用你机器上的核心数并行执行,所以编译会更快
运行deviceQuery,确保它能检测到显卡并测试通过
bin/x86_64/linux/
release/deviceQuery
7.安装cudnn
首先需要下载cuDNN,直接从Nvidia官方下载链接选择一个版本,不过下载cuDNN前同样需要登录甚至填写一个简单的调查问卷: https://developer.nvidia.com/rdp/cudnn-download,这里选择的是支持CUDA8.0的cuDNNv5版本,而支持CUDA8的5.1版本虽然显示在下载选择项里,但是提示:cuDNN 5.1 RC for CUDA 8RC will beavailable soon - please check back again.
安装cuDNN比较简单,解压后把相应的文件拷贝到对应的CUDA目录下即可:
tar -zxvfcudnn-8.0-linux-x64-v5.0-ga.tgz
cuda/include/cudnn.h
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.5
cuda/lib64/libcudnn.so.5.0.5
cuda/lib64/libcudnn_static.a
sudo cp cuda/include/cudnn.h/usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn*/usr/local/cuda/lib64/
sudo chmod a+r/usr/local/cuda/include/cudnn.h
sudo chmod a+r/usr/local/cuda/lib64/libcudnn*