2016.06.10 update cuda 7.5 and cudnn v5
2015.10.23更新:修改了一些地方,身边很多人按这个流程安装,完全可以安装
折腾了两个星期的caffe,windows和ubuntu下都安装成功了。其中windows的安装配置参考官网推荐的那个blog,后来发现那个版本的caffe太老,和现在的不兼容,一些关键字都不一样,果断回到Linux下。这里记录一下我的安装配置流程。
电脑配置:
ubuntu 14.0464bit
8G 内存
GTX650显卡
软件版本:
CUDA 7.0
caffe 当天从github下载的版本
安装ubuntu的过程省略,建议安装后关闭自动更新,上一次安装caffe后用的很好,结果有一天晚上没关电脑,自己半夜更新了显卡驱动,然后...
caffe的安装流程主要参考这个blog,稍有改动:Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明
Caffe 安装配置步骤:
1, 安装开发所需的依赖包
- sudoapt-getinstallbuild-essential#basicrequirement
- sudoapt-getinstalllibprotobuf-devlibleveldb-devlibsnappy-devlibopencv-devlibboost-all-devlibhdf5-serial-devlibgflags-devlibgoogle-glog-devliblmdb-devprotobuf-compiler#requiredbycaffe
Before install CUDA 7.5,you need update gcc 4.8+ to gcc 4.9+
reference:update gcc/g++
2,安装CUDA 7.5
验证过程省略,按照官方文档自己操作吧(遇到问题首先要看官方文档啊,血泪教训)
安装CUDA有两种方法,
离线.run安装:从官网下载对应版本的.run安装包安装,安装过程挺复杂,尝试过几次没成功,遂放弃。
在离线.deb安装:deb安装分离线和在线,我都尝试过都安装成功了,官网下载地址
安装之前请先进行md5校验,确保下载的安装包完整
切换到下载的deb所在目录,执行下边的命令
- sudodpkg-icuda-repo-<distro>_<version>_<architecture>.deb
- sudoapt-getupdate
- sudoapt-getinstallcuda
然后重启电脑:sudo reboot
NOTE:装不成功卸了多来几遍,总会成的
3,安装cuDNN
下载cudnn-7.5-linux-x64-v5.0-ga.tgz,官网申请不到,网上自己找的,就不给地址了。
- tar-zxvfcudnn-7.5-linux-x64-v5.0-ga.tgz
- cdcuda
- sudocplib/lib*/usr/local/cuda/lib64/
- sudocpinclude/cudnn.h/usr/local/cuda/include/
更新软连接
cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.5.0.5
sudo ln -sf libcudnn.so.5.0.5 libcudnn.so.5
sudo ln -sf libcudnn.so.5 libcudnn.so
sudo ldconfig
sudo chmod +r libcudnn.so.5.0.5
sudo ln -sf libcudnn.so.5.0.5 libcudnn.so.5
sudo ln -sf libcudnn.so.5 libcudnn.so
sudo ldconfig
4,设置环境变量
在/etc/profile中添加CUDA环境变量
sudo gedit /etc/profile
- PATH=/usr/local/cuda/bin:$PATH
- exportPATH
保存后,执行下列命令,使环境变量立即生效
- source/etc/profile
- /usr/local/cuda/lib64
保存后,执行下列命令使之立刻生效
- sudoldconfig
5,安装CUDA SAMPLE
进入/usr/local/cuda/samples,执行下列命令来build samples
- sudomakeall-j4
整个过程大概10分钟左右,全部编译完成后, 进入 samples/bin/x86_64/linux/release,运行deviceQuery
- ./deviceQuery
如果出现显卡信息, 则驱动及显卡安装成功:
- ./deviceQueryStarting...
- CUDADeviceQuery(RuntimeAPI)version(CUDARTstaticlinking)
- Detected1CUDACapabledevice(s)
- Device0:"GeForceGTX670"
- CUDADriverVersion/RuntimeVersion6.5/6.5
- CUDACapabilityMajor/Minorversionnumber:3.0
- Totalamountofglobalmemory:4095MBytes(4294246400bytes)
- (7)Multiprocessors,(192)CUDACores/MP:1344CUDACores
- GPUClockrate:1098MHz(1.10GHz)
- MemoryClockrate:3105Mhz
- MemoryBusWidth:256-bit
- L2CacheSize:524288bytes
- MaximumTextureDimensionSize(x,y,z)1D=(65536),2D=(65536,65536),3D=(4096,4096,4096)
- MaximumLayered1DTextureSize,(num)layers1D=(16384),2048layers
- MaximumLayered2DTextureSize,(num)layers2D=(16384,16384),2048layers
- Totalamountofconstantmemory:65536bytes
- Totalamountofsharedmemoryperblock:49152bytes
- Totalnumberofregistersavailableperblock:65536
- Warpsize:32
- Maximumnumberofthreadspermultiprocessor:2048
- Maximumnumberofthreadsperblock:1024
- Maxdimensionsizeofathreadblock(x,z):(1024,1024,64)
- Maxdimensionsizeofagridsize(x,z):(2147483647,65535,65535)
- Maximummemorypitch:2147483647bytes
- Texturealignment:512bytes
- Concurrentcopyandkernelexecution:Yeswith1copyengine(s)
- Runtimelimitonkernels:Yes
- IntegratedGPUsharingHostMemory:No
- Supporthostpage-lockedmemorymapping:Yes
- AlignmentrequirementforSurfaces:Yes
- DevicehasECCsupport:Disabled
- DevicesupportsUnifiedAddressing(UVA):Yes
- DevicePCIBusID/PCIlocationID:1/0
- ComputeMode:
- <Default(multiplehostthreadscanuse::cudaSetDevice()withdevicesimultaneously)>
- deviceQuery,CUDADriver=CUDART,CUDADriverVersion=6.5,CUDARuntimeVersion=6.5,NumDevs=1,Device0=GeForceGTX670
- Result=PASS
NOTE:上边的显卡信息是从别的地方拷过来的,我的GTX650显卡不是这些信息,如果没有这些信息,那肯定是安装不成功,找原因吧!
6,安装Intel MKL 或Atlas
我没有MKL,装的Atlas
安装命令:
- sudoapt-getinstalllibatlas-base-dev
7,安装OpenCV
我安装的是2.4.10
1)下载
安装脚本
2)进入目录 Install-OpenCV/Ubuntu/2.4
3)执行脚本
- sudosh./opencv2_4_10.sh
8,安装Caffe所需要的Python环境
按caffe官网的推荐使用Anaconda
- bashAnaconda-2.3.0-Linux-x86_64.s<em>h</em>
NOTE:后边的文件名按自己下的版本号更改,整个安装过程请选择默认
8.1,添加Anaconda Library Path
在/etc/ld.so.conf最后加入以下路径,并没有出现重启不能进入界面的问题(
NOTE:下边的username要替换)
- /home/username/anaconda/lib
在~/.bashrc最后添加下边路径
- exportLD_LIBRARY_PATH="/home/username/anaconda/lib:$LD_LIBRARY_PATH"
执行如下命令
- forreqin$(catrequirements.txt);dopipinstall$req;done
10,编译Caffe
终于来到这里了
进入caffe-master目录,复制一份Makefile.config.examples
- cpMakefile.config.exampleMakefile.config
- ##Refertohttp://caffe.berkeleyvision.org/installation.html
- #Contributionssimplifyingandimprovingourbuildsystemarewelcome!
- #cuDNNaccelerationswitch(uncommenttobuildwithcuDNN).
- USE_CUDNN:=1
- #cpu-onlyswitch(uncommenttobuildwithoutGPUsupport).
- #cpu_ONLY:=1
- #Tocustomizeyourchoiceofcompiler,uncommentandsetthefollowing.
- #N.B.thedefaultforLinuxisg++andthedefaultforOSXisclang++
- #CUSTOM_CXX:=g++
- #CUDAdirectorycontainsbin/andlib/directoriesthatweneed.
- CUDA_DIR:=/usr/local/cuda
- #OnUbuntu14.04,ifcudatoolsareinstalledvia
- #"sudoapt-getinstallnvidia-cuda-toolkit"thenusethisinstead:
- #CUDA_DIR:=/usr
- #CUDAarchitecturesetting:goingwithallofthem.
- #ForCUDA<6.0,commentthe*_50linesforcompatibility.
- CUDA_ARCH:=-gencodearch=compute_20,code=sm_20\
- -gencodearch=compute_20,code=sm_21\
- -gencodearch=compute_30,code=sm_30\
- -gencodearch=compute_35,code=sm_35\
- -gencodearch=compute_50,code=sm_50\
- -gencodearch=compute_50,code=compute_50
- #BLASchoice:
- #atlasforATLAS(default)
- #mklforMKL
- #openforOpenBlas
- BLAS:=atlas
- #Custom(MKL/ATLAS/OpenBLAS)includeandlibdirectories.
- #LeavecommentedtoacceptthedefaultsforyourchoiceofBLAS
- #(whichshouldwork)!
- #BLAS_INCLUDE:=/path/to/your/blas
- #BLAS_LIB:=/path/to/your/blas
- #Homebrewputsopenblasinadirectorythatisnotonthestandardsearchpath
- #BLAS_INCLUDE:=$(shellbrew--prefixopenblas)/include
- #BLAS_LIB:=$(shellbrew--prefixopenblas)/lib
- #Thisisrequiredonlyifyouwillcompilethematlabinterface.
- #MATLABdirectoryshouldcontainthemexbinaryin/bin.
- #MATLAB_DIR:=/usr/local
- #MATLAB_DIR:=/Applications/MATLAB_R2012b.app
- #NOTE:thisisrequiredonlyifyouwillcompilethepythoninterface.
- #WeneedtobeabletofindPython.handnumpy/arrayobject.h.
- #PYTHON_INCLUDE:=/usr/include/python2.7\
- /usr/lib/python2.7/dist-packages/numpy/core/include
- #AnacondaPythondistributionisquitepopular.Includepath:
- #Verifyanacondalocation,sometimesit'sinroot.
- ANACONDA_HOME:=$(HOME)/anaconda
- PYTHON_INCLUDE:=$(ANACONDA_HOME)/include\
- $(ANACONDA_HOME)/include/python2.7\
- $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include\
- #WeneedtobeabletofindlibpythonX.X.soor.dylib.
- #PYTHON_LIB:=/usr/lib
- PYTHON_LIB:=$(ANACONDA_HOME)/lib
- #Homebrewinstallsnumpyinanonstandardpath(kegonly)
- #PYTHON_INCLUDE+=$(dir$(shellpython-c'importnumpy.core;print(numpy.core.__file__)'))/include
- #PYTHON_LIB+=$(shellbrew--prefixnumpy)/lib
- #UncommenttosupportlayerswritteninPython(willlinkagainstPythonlibs)
- #WITH_PYTHON_LAYER:=1
- #Whateverelseyoufindyouneedgoeshere.
- INCLUDE_DIRS:=$(PYTHON_INCLUDE)/usr/local/include
- LIBRARY_DIRS:=$(PYTHON_LIB)/usr/local/lib/usr/lib
- #IfHomebrewisinstalledatanonstandardlocation(forexampleyourhomedirectory)andyouuseitforgeneraldependencies
- #INCLUDE_DIRS+=$(shellbrew--prefix)/include
- #LIBRARY_DIRS+=$(shellbrew--prefix)/lib
- #Uncommenttouse`pkg-config`tospecifyOpenCVlibrarypaths.
- #(Usuallynotnecessary--OpenCVlibrariesarenormallyinstalledinoneoftheabove$LIBRARY_DIRS.)
- #USE_PKG_CONFIG:=1
- BUILD_DIR:=build
- DISTRIBUTE_DIR:=distribute
- #Uncommentfordebugging.DoesnotworkonOSXduetohttps://github.com/BVLC/caffe/issues/171
- #DEBUG:=1
- #TheIDoftheGPUthat'makeruntest'willusetorununittests.
- TEST_GPUID:=0
- #enableprettybuild(commenttoseefullcommands)
- Q?=@
保存退出
编译
- makeall-j4
- maketest
- makeruntest
11,编译Python wrapper
- makepycaffe