转载链接:http://blog.csdn.net/frank_zrh/article/details/52298909
一、需要预先下载的东西
1.GTX1080的Linux驱动(run文件)
2.Install-OpenCV-master(最好先下载好对应的OpenCV版本,修改相应的脚本省时间)
4.Cudnn5.0文件(压缩包)
二、安装caffe之前的准备工作
Step1:禁用nouveau驱动
- sudovim/etc/modprobe.d/blacklist-nouveau.conf
输入
- blacklistnouveau
- optionsnouveaumodset=0
保存退出(:wq)
然后执行
- sudoupdate-initramfs-u
- lspci|grepnouveau
step2:安装显卡驱动(不从CUDA中一起装,因为CUDA8.0中的显卡驱动太旧)
Ctrl+alt+F1进入字符界面,关闭图形界面
- sudoservicelightdmstop
- sudochmod755NVIDIA-Linux-x86_64-367.27.run//获取权限
- sudo./NVIDIA-Linux-x86_64-367.27.run//安装驱动
安装完成之后
- sudoservicelightdmstart
我的方案是,安装完成之后,reboot或者shutdown之后把视频线连接到独显上,避免强制关机
安装完成之后可用一面的命令查看
- nvidia-smi
step3:安装CUDA8.0
进入到CUDA文件所在的目录
- sudoshcuda_8.0.27_linux.run
安装过程显示如下信息
Do you accept the prevIoUsly read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?
(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/zhou ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 …
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so
Installing the CUDA Samples in /home/zhou …
Copying samples to /home/zhou/NVIDIA_CUDA-8.0_Samples now…
Finished copying samples.
===========
=Summary=
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/zhou,but missing recommended libraries
Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- 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
To uninstall the CUDA Toolkit,run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***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.
To install the driver using this installer,run the following command,replacing with the name of this run file:
sudo .run -silent -driver
Logfile is /tmp/cuda_install_2961.log
设置环境变量
- sudovi/etc/profile
- exportPATH=/usr/local/cuda-8.0/bin:$PATH
- exportLD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
- sudoldconfig
这里强势插入一个步骤:安装库,因为接下来安装Samples需要make,所以得先装好一些库和依赖
- sudoapt-getinstallfreeglut3-devbuild-essentiallibx11-devlibxmu-devlibxi-devlibglu1-mesalibglu1-mesa-devlibgl1-mesa-glx
在安装库的过程中也出现一些问题,例如有些安装不了(选择的软件源没有这个库),这种情况可以在ubuntu的网站搜索相应的
库的名字,可以到它给出的链接去下载deb包直接双击安装就可以了。校园网的用户建议连接中科大的源,速度很快。
安装CUDA自带的Samples
- cd/usr/local/cuda/samples
- sudomakeall-j4
编译完之后
- cd./bin/x86_64/linux/release
- ./deviceQuery
若出现显卡信息,则说明安装完成了
step3:安装CUDNN5.0
将cudnn解压后就是一个名为CUDA的文件夹,放在哪都可以,我们还要复制里面的文件到相应的地方,并创建软链接
- cdcuda
- sudocplib64/lib*/usr/local/cuda/lib64/
- sudocpinclude/cudnn.h/usr/local/cuda/include/
- cd/usr/local/cuda/lib64/
- sudochmod+rlibcudnn.so.5.0.5
- sudoln-sflibcudnn.so.5.0.5libcudnn.so.5
- sudoln-sflibcudnn.so.5libcudnn.so
- sudoldconfig
-----------------------------------我把这里作为分界线,是因为多次实验以上的步骤都不会出错,容易出错的地方在分界线下面的部分--------------------------------
step4:安装opencv
这里推荐网友写的一个脚本(百度云下载http://pan.baidu.com/s/1qX1uFHa,密码:wysa)
在Isstall-OpenCV-master的根目录下
- cd./Ubuntu
- sudoshdependencies.sh
- cd./3.0
- sudoshopencv3_0_0.sh
github大神给出了解决方案(https://github.com/opencv/opencv/pull/6510/commits/10896129b39655e19e4e7c529153cb5c2191a1db)
意思就是在下载好的OpenCV3.0的文件夹中
- cd./modules/cudalegacy/src
- sudovimgraphcuts.cpp
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
将他改为
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
这样再编译一下就好了,在这里有一点需要注意,如果又用
- sudoshopencv3_0_0.sh
等待几分钟,就安装好了。
三、编译caffe
安装依赖项和各种库
- sudoapt-getinstalllibprotobuf-devlibleveldb-devlibsnappy-devlibopencv-devlibhdf5-serial-devprotobuf-compilerlibatlas-base-devlibgflags-devlibgoogle-glog-dev
- liblmdb-dev
- sudoapt-getinstall--no-install-recommendslibboost-all-dev
- <spanstyle="font-family:SimSun;font-size:12px;">sudoapt-getinstall-ypython-numpypython-scipypython-matplotlibpython-sklearnpython-skimagepython-h5py
- python-protobufpython-leveldbpython-networkxpython-nosepython-pandaspython-gflagscythonipython
进入caffe的根目录
- <spanstyle="font-family:SimSun;font-size:12px;">cpMakefile.config.exampleMakefile.config</span>
根据自己的需要修改Makefile.config
我自己改了CUDNN项和OPENCV项(用了3.0就要修改这一项)
- makeall-j4
- maketest-j4
- makeruntest-j4
第一次make的时候出现了错误
.build_release/lib/libcaffe.so: undefined reference tocv::imread(cv::String const&,int)'.build_release/lib/libcaffe.so: undefined reference to
cv::imencode(cv::String const&,cv::_InputArray const&,std::vector >&,std::vector > const&)
参考https://github.com/BVLC/caffe/issues/2348的回答
我尝试了在caffe根目录下
- rmbuild(如果有这个文件夹的话)
- mkdirbuild
- cdbuild
- cmake..
- makeall-j4
- cd..
- makeall-j4
接下来我就
- maketest
但是再次出错了
libcudart.so.8.0: cannot open shared object file: No such file or directory
用ln将需要的so文件链接到/usr/lib或者/lib这两个默认的目录下边
- ln-s/where/you/install/lib/*.so/usr/lib
- udoldconfig
- exportLD_LIBRARY_PATH=/where/you/install/lib:$LD_LIBRARY_PATH
- /usr/local/cuda-8.0/lib64
再接下来make test 和make runtest都没有出错了
虽然之前也配置过cuda7.5和gtx970但是,由于gtx1080比较新,安装驱动要单独从官网上先下载,配置过程中opencv与cuda8.0也有兼容问题。
有参考网上的教程,但是还是花了两天时间来配置。特意整理了这样一篇博客,流程是完全按照我成功配置下来的过程而写的 ,希望对大家有帮助。
也感谢在这过程中给我帮助的同学。第一次写博客,还请多多指教!
参考的博客:http://www.2cto.com/os/201607/528798.html
原文链接:https://www.f2er.com/ubuntu/354295.html