前两个礼拜一直在折腾深度学习环境配置,现做如下笔记。这里对Ubuntu16.04配置gtx1060深度学习环境: cuda8.0+cudnn5.1+tensorflow0.11+theano0.8
装系统本身很简单,不管是单系统还是双系统。重点是我们得先明白,硬盘分区分为MBR和GPT两种格式,这两种硬盘格式对相应系统是不兼容的。
早期的硬盘分区格式为MBR格式,即一个主分区,几个逻辑分区(拓展分区)。经典的win硬盘分区方式。而GPT格式则不同,GTP允许多个主分区,系统可以装在任意一个主分区里。
如果需要在MBR格式的硬盘里装系统,则需要把系统文件里的EFI文件删除。EFI文件为系统启动文件。
安装显卡驱动可以选择在线安装和离线安装,网速好的优先在线安装,因为通过命令行安装可以安装最新的显卡驱动而且Ubuntu会把相应的配置文件之类的也帮你安装好。
在线安装方法:sudo add-apt-repository -qy ppa:graphics-drivers/ppa
sudo add-apt-repository -qy ppa:graphics-drivers/ppa
sudo apt-get -qy update
sudo apt-get -qy install nvidia-370
sudo apt-get -qy install mesa-common-dev
sudo apt-get -qy install freeglut3-dev
sudo reboot
需要离线安装的先下载对应版本的NVIDIA显卡驱动。
离线安装方法:sudo chmod 755 NVIDIA-Linux-x86_64-367.27.run
sudo ./NVIDIA-Linux-x86_64-367.27.run
或者直接使用命令:sudo sh /home//.run #/home// 为你nvidia驱动文件所在的路径
如果无法安装的话建议:ctrl+alt+f1进入tty模式.
在运行命令:sudo /etc/init.d/lightdm stop
然后在进行安装:sudo /home/**/.run
安装完后记得:sudo reboot
如果安装出现问题可以使用:sudo apt-get autoremove –purge nvidia-* sudo apt-get remove –purge nvidia-*对显卡驱动进行卸载,然后重新安装。出现循环登录时也可先卸载显卡驱动,然后重新安装。
这里使用离线安装方式。安装之前同样得先进入tty模式
在运行命令:sudo /etc/init.d/lightdm stop
然后在进行安装:sudo sh /home//.run #/home// 为你cuda8文件所在的路径
执行后会有一系列提示让你确认,第一个就是问你是否安装显卡驱动,由于前一步已经安装了显卡驱动,所以这里就不需要了,况且 runfile 自带的驱动版本不是最新的。 因此 Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.77? 这里选择 no。
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.77?
(y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/programmer ]:
除了第一个安装显卡驱动的按n,其余的一路y,和默认安装完。最后把以下两行加入到 .bashrc,添加环境变量,直接在命令行中运行这两行就行:
export PATH=/usr/local/cuda-8.0/bin PATH:+:$PATHexportLDLIBRARYPATH=/usr/local/cuda−8.0/lib64 {LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
测试是否安装成功,运行:nvidia-smi。结果如下所示:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 370.23 Driver Version: 370.23 |
|-------------------------------+----------------------+----------------------+
| 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 1080 Off | 0000:05:00.0 On | N/A |
| 27% 29C P8 9W / 180W | 515MiB / 8110MiB | 4% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 4761 G /usr/lib/xorg/Xorg 259MiB |
| 0 5224 G compiz 253MiB |
+-----------------------------------------------------------------------------+
我们设置为每 10s 显示一次显存的情况,-n后面的数字表示多少秒来执行一次命令
watch -n 10 nvidia-smi
结果如下图所示
cd ~/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery
make
执行 ./deviceQuery,得到:
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 1080"
CUDA Driver Version / Runtime Version 8.0 / 8.0
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 8110 MBytes (8504279040 bytes)
(20) Multiprocessors, (128) CUDA Cores/MP: 2560 CUDA Cores
GPU Max Clock rate: 1734 MHz (1.73 GHz)
Memory Clock rate: 5005 Mhz
Memory Bus Width: 256-bit
L2 Cache Size: 2097152 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
Device PCI Domain ID / Bus ID / location ID: 0 / 5 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1080
Result = PASS
至此,说明 CUDA 8.x 安装成功了。
安装cuDNN比较简单,解压后把相应的文件拷贝到对应的CUDA目录下即可。在官网https://developer.nvidia.com/cudnn下载对应的cuDNN,我在安装的时候选择的是5.1
tar -xzvf cudnn-8.0-linux-x64-v5.1-tgz
cd cudnn
sudo cp lib* /usr/local/cuda/lib64/
sudo cp cudnn.h /usr/local/cuda/include/
监视显卡利用率:watch -n 10 nvidia-smi。设置为每 10s 显示一次显存的情况
nvcc -V 显示驱动版本信息
至此深度学习环境就配置好了,可以开始安装tensorflow和theano深度学习框架了。