1 测试环境&软件准备
硬件:
- Dell T430
- Nvidia GTX 1080
软件:
- Ubuntu 16.04 x86_64
- cuda8.0
- cuDNN(5.1)
2 安装cuda
点击上述链接,下载cuda(注意与显卡兼容的版本)。最好下载.run文件,因为在安装cuda的时候,会自动给系统安装显卡驱动,而我们先前在装显卡的时候,已经安装好了最新的驱动,因此不需要再装一次显卡驱动。
(1)~$ sudo sh cuda_8.0.27_linux.run
接下来,会出现提示“Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.77?”,问你是否安装显卡驱动,当然要选择n了。其他默认选择即可。
(2)配置环境变量:(编辑.bashrc文件)
在末尾添加:
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
添加完毕后记得source一下,使其生效。
3 安装cuDNN
为了达到更高的性能,可以借助专业加速库cnDNN。下载完成后(注意:cuDNN库与cuda版本兼容性),解压tgz文件,将相关文件复制到/usr/local/cuda,输入命令:
~$ tar xvzf cudnn-8.0-linux-x64-v5.1.tgz
~$ 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 /usr/local/cuda/lib64/libcudnn*
(4)测试cuda样例nbody
首先,看看显卡信息,输入命令:
~$ nvidia-smi +-----------------------------------------------------------------------------+ | NVIDIA-SMI 367.27 Driver Version: 367.27 | |-------------------------------+----------------------+----------------------+ | 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:03:00.0 On | Off | | 27% 33C P8 N/A / N/A | 376MiB / 81133MiB | 6% Default | +-------------------------------+----------------------+----------------------+ | 1 GeForce GTX 1080 Off | 0000:04:00.0 Off | N/A | | 27% 38C P8 6W / 180W | 1MiB / 8113MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
然后,建立并测试样例:
$ cd NVIDIA_CUDA-8.0/5_Simulations/nbody
$ make
$ ./nbody -benchmark -numbodies=256000 -device=0
> Windowed mode > Simulation data stored in video memory
> Single precision floating point simulation
> 1 Devices used for simulation gpuDeviceInit() CUDA Device [0]: "GeForce GTX 1080
"
> Compute 6.1 CUDA device: [GeForce GTX 1080
]
number of bodies = 256000
256000 bodies,total time for 10 iterations: 2385.759 ms
= 274.697 billion interactions per second
= 5495.992 single-precision GFLOP/s at 20 flops per interaction
如果能够正常显示上面信息,则表示安装成功!Caffe cuDNN模式相比cpu模式加速15.46倍,相比GPU模式加速7.7倍。
4 安装caffe
这里就直接转到前面介绍的cpu版的安装法,基本依赖包都给安装了。在编译安装caffe时,只需要修改Makefile.config中的选项USE_CUDNN := 1。注意:因为本篇是GPU版,因此不能将Makefile.config文件中“# cpu_ONLY := 1”,前面的#号去掉,其他步骤都一样。其实安装caffe还算比较轻松的,步骤也就这么一点,依赖包都是命令搞定,祝好运!!!
原文链接:https://www.f2er.com/ubuntu/355539.html