Caffe + Ubuntu 15.10 64bit + CUDA 7.5 +Matlab2014a

    入职第三天一直在配置caffe环境,身为装过多次caffe的老人,我深感愧疚(因为之前是看别人给我装的),直到现在,才战战兢兢地快要配置成功。。。

    参考的网页一定要贴上来:

1、欧神的旧版配置说明:http://ouxinyu.github.io/Blogs/20140723001.html

2、欧神的新版配置说明:http://ouxinyu.github.io/Blogs/20140723001.html

3、普兒的文章链接地址:http://www.cnblogs.com/platero/p/3993877.html

4、实验室的集体作战经验(当然没有我):http://blog.csdn.net/u013476464/article/details/46945433

5、Matlab安装主要参考欧神的新版配置说明,但作为linux渣渣我还是翻阅了无数网站,贴几个:

      http://blog.csdn.net/lanbing510/article/details/41698285

     http://www.linuxidc.com/Linux/2011-01/31632.html


    另外,参考欧神的新版配置说明安装好cuda7.5后,又参考普兒的文章完成了环境变量设置与samples编译等,将我的整体流程再贴一遍吧。

环境1:Ubuntu15.10中文版x86_64位(还好有了cuda7.5的智能安装,否则中文系统在字符界面根本无法识别中文字符,也因为这个原因系统被我强制进入字符界面后无法返回图形界面,还好身边一群技术牛,不然我只能不停地重装系统,可更悲哀的是,我根本没装过任何系统!现在真是后悔以前一遇到问题就找男同学帮忙享受被伺候着的感觉,娃哈哈。。。)

环境2:Geforce GT 730 GPU(显存太小,后来证明根本跑不起来caffe,呜呜呜~)

第一部分:nVidia CUDA Toolkit的安装(*.deb方法)

一、CUDA Repository

获取CUDA安装包,安装包请自行去NVidia官网下载。(https://developer.nvidia.com/cuda-downloads)

二、CUDA Toolkit

三、添加环境变量

在/etc/profile中添加环境变量,打开文件添加:

<span style="font-size:14px;">PATH=/usr/local/cuda-7.5/bin:$PATH
export PATH</span>
保存并执行下述命令使环境变量立即生效:

<span style="font-size:14px;">source /etc/profile</span>


四、添加lib库路径
在/etc/ld.so.conf.d/路径下添加cuda.conf文件,内容如下:

<span style="font-size:14px;">/usr/local/cuda-7.5/lib64</span>
执行以下命令使之立即生效:

<span style="font-size:14px;">sudo ldconfig</span>


五、编译Sample文件

<span style="font-size:14px;">cd /usr/local/cuda-7.5/samples
sudo make</span>
完成编译后,执行

<span style="font-size:14px;">cd bin/x86_64/linux/release/
sudo ./deviceQuery</span>

如果出现下列显卡信息,则表示显卡安装成功:

<span style="font-size:14px;">./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GT 730"
  CUDA Driver Version / Runtime Version          7.5 / 7.5
  CUDA Capability Major/Minor version number:    3.5
  Total amount of global memory:                 1023 MBytes (1073020928 bytes)
  ( 2) Multiprocessors, (192) CUDA Cores/MP:     384 CUDA Cores
  GPU Max Clock rate:                            902 MHz (0.90 GHz)
  Memory Clock rate:                             800 Mhz
  Memory Bus Width:                              64-bit
  L2 Cache Size:                                 524288 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 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 1 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 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 7.5, CUDA Runtime Version = 7.5, NumDevs = 1, Device0 = GeForce GT 730
Result = PASS</span>

第二部分 Matlab安装和调试(以Matlab 2014a为例)

下载好Mathworks.Matlab.R2014a.Unix.iso文件及Crack压缩包

一、首先进行挂载:

<span style="font-size:14px;">sudo mkdir /media/matlab
sudo mount -o loop ./Mathworks.Matlab.R2014a.iso /media/matlab</span>

拷贝全部文件至home/Matlab 文件夹

复制Crack/install.jar至 home/Matlab/java/jar/ 并覆盖源文件:

二、授权安装文件夹

三、 安装

选项:不使用Internet安装

序列号: 12345-67890-12345-67890

默认路径:/usr/local/MATLAB/R2014a

勾选从默认启动路径创建符号链接(实现在任意位置运行matlab启动程序)

激活文件:license_405329_R2014a.lic

拷贝 libmwservices.so 至 /usr/local/MATLAB/R2014a/bin/glnxa64:

四、解决编译器gcc/g++版本问题。

因为Ubuntu 15.10的gcc/g++版本较高,而Matlab 2014a(2015a)的版本是4.7.x所以在使用matla调用mex文件的时候,基本上都会报错,根据报错信息,考虑如下两步解决方案。

A. 降级安装gcc/g++版本为4.7.x

(a). 下载gcc/g++ 4.7.x

(b). 链接gcc/g++实现降级

B. 暴力引用新版本GLIBCXX_3.4.20

通过命令“strings /usr/local/MATLAB/R2014a/sys/os/glnxa64/libstdc++.so.6 | grep GLIBCXX_” 可以看一下,是否已经成功包含了GLIBCXX_3.4.21,如果已经存在,基本上就成功了。

五、编译Matlab用到的caffe文件(见第三部分)


第三部分 Caffe-Master的安装和测试

一、安装BLAS

这里可以选择(ATLAS,MKL或者OpenBLAS),我这里使用MKL,首先下载并安装英特尔® 数学内核库 Linux* 版MKL(Intel(R) Parallel Studio XE Cluster Edition for Linux 2016),下载链接是:https://software.intel.com/en-us/intel-education-offerings, 使用学生身份(邮件 + 学校)下载Student版,填好各种信息,可以直接下载,同时会给你一个邮件告知序列号。下载完之后,要把文件解压到home文件夹(或直接把tar.gz文件拷贝到home文件夹,为了节省空间,安装完记得把压缩文件给删除喔~),或者其他的ext4的文件系统中。

先授权,然后安装:

PS: 安装的时候,建议使用root权限安装,过程中会要求输入Linux的root口令。(设置方法:命令行:$ sudo passwd)

二、MKL与CUDA的环境设置

1. 新建intel_mkl.conf, 并编辑之:

/opt/intel/lib/intel64

/opt/intel/mkl/lib/intel64

2. 新建cuda.conf,并编辑之:

/usr/local/cuda/lib64

/lib

3. 完成lib文件的链接操作,执行:

三、安装OpenCV 3.0.0

1. 下载并编译OpenCV(官网原版OpenCV:http://opencv.org/), 或者使用欧神提供的修改版的安装包 Install-OpenCV-master (下面的安装方式使用该包完成,安装包修改了dependencies.sh文件并增加了OpenCV 3.0.0的安装文件)

2. 切换到文件保存的文件夹,然后安装依赖项:

3. 切换目录Ubuntu\3.0\安装OpenCV 3.0.0:

这一步的时候,遇到问题:其中一个文件libatomic.so一直出问题,好吧,原谅我并不知道为什么,后来汤圆就刷刷刷地帮我解决了。。。

四、安装其他依赖项

1. Google Logging Library(glog),下载地址:https://code.google.com/p/google-glog/,然后解压安装:

如果没有权限就chmod a+x glog-0.3.3 -R , 或者索性 chmod 777 glog-0.3.3 -R , 装完之后,这个文件夹就可以kill了。

2. 其他依赖项,确保都成功

五、安装Caffe并测试

1. 安装pycaffe必须的一些依赖项:

2. 安装配置nVidia cuDNN 加速Caffe模型运算

a. 安装前请去先官网下载最新的cuDNN (cudnn-70-linux-x64-v3)。

3. 切换到Caffe-master的文件夹,生成Makefile.config配置文件,执行:

4. 配置Makefile.config文件(仅列出修改部分)

a. 配置一些引用文件(增加部分主要是解决新版本下,HDF5的路径问题)

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

b. 启用Intel Parallel Studio XE 2016

BLAS := mkl

c. 配置路径,实现caffe对Python和Matlab接口的支持

PYTHON_LIB := /usr/local/lib

MATLAB_DIR := /usr/local/MATLAB/R2014a

d. 启用OpenCV 3.0, 去掉"#"

OPENCV_VERSION =3

5. 编译caffe-master!!!"-j4"是使用CPU的多核进行编译,可以极大地加速编译的速度,建议使用。

编译Python和Matlab用到的caffe文件

当然,在 make all -j4编译的时候意料之中地又出现了各种问题,下面是汤圆帮我解决的过程,原谅我并不知道都作了什么,只是新建了caffe进行编译,并不在我原来的文件夹中,简单记录下:

ls
  458  cd /usr/local/cuda
  459  ls
  460  cd samples/
  461  ls
  462  make
  463  sudo make
  464  sudo apt-get -y atlas atlas-dev  lapack lapack-dev  blas blas-dev cblas cblas-dev
  465  sudo apt-get install -y atlas atlas-dev  lapack lapack-dev  blas blas-dev cblas cblas-dev
  466  sudo apt-get install libatlas-base-dev
  467  sudo ldconfig
  468  ls
  469  ./bin/x86_64/linux/release/deviceQuery
  470  ls
  471  cd
  472  cd programs/
  473  ls
  474  cd caffe/
  475  ls
  476  emacs Makefile
  477  emacs Makefile.config
  478  make
  479  sudo apt-get install -y libhdf5-serial-dev
  480  make -j4
  481  sudo ldconfig
  482  ls /usr/include/hdf5/serial/
  483  emacs Makefile.config
  484  make -j4
  485  ls /usr/lib/
  486  locate hdf5.so
  487  emacs Makefile.config
  488  make -j4
  489  locate opencv_imgcodecs.so
  490  cd /home/in66/caffeinstall/Install-OpenCV-master-master/Ubuntu/3.0/OpenCV/opencv-3.0.0-rc1/build
  491  ls
  492  sudo make install
  493  echo '/usr/local/lib' >> /etc/ld.so.conf.d/opencv.conf
  494  sudo echo '/usr/local/lib' >> /etc/ld.so.conf.d/opencv.conf
  495  ls /etc/ld.so.conf.d/opencv.conf 
  496  sudo emacs /etc/ld.so.conf.d/opencv.conf 
  497  sudo ldconfig
  498  sudo echo 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' >> /etc/bash.bashrc
  499  sudo emacs /etc/bash.bashrc 
  500  cd
  501  cd programs/
  502  ls
  503  source /etc/bash.bashrc
  504  ls
  505  cd caffe/
  506  ls
  507  make -j4
  508  sudo apt-get install -y libleveldb-dev liblmdb-dev libboost-all-dev 
  509  sudo ldconfig
  510  emacs Makefile
  511  emacs Makefile.config
  512  make
  513  emacs Makefile.config
  514  make 
  515  cd
  516  cd programs/
  517  git clone https://github.com/google/leveldb.git
  518  cd leveldb/
  519  make
  520  sudo cp -r include/leveldb /usr/local/include
  521  sudo cp libleveldb.so /usr/local/lib
  522  sudo ldconfig
  523  cd ../caffe/
  524  make
  525  ls
  526  cd ../
  527  ls
  528  cd caffe/
  529  ls
  530  make matcaffe
  531  emacs Makefile.config
  532  make 
  533  make matcaffe
  534  cd ../
  535  ls
  536  unzip opencv-2.4.11.zip 
  537  cd opencv-2.4.11/
  538  ls
  539  mkdir build
  540  cd build/
  541  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler  -D BUILD_NEW_PYTHON_SUPPORT=ON ..
  542  make -j4
  543  sudo make install
  544  cd
  545  cd programs/
  546  sudo ldconfig
  547  cd caffe/
  548  emacs Makefile.config
  549  make
  550  make clean
  551  make -j4
  552  sudo apt-get install -y libgflags-dev libgoogle-glog-dev 
  553  make matcaffe
  554  ls
  555  locate gflag.so
  556  sudo updatedb
  557  locate gflag.so
  558  locate gflag 
  559  emacs Makefile.config
  560  make
  561  ldconfig
  562  sudo ldconfig
  563  make clean
  564  make -j4
  565  make matcaffe
  566  cd ../
  567  ls
  568  git clone https://github.com/google/protobuf.git
  569  git clone https://github.com/google/glog.git
  570  git clone https://github.com/gflags/gflags.git
  571  cd gflags/
  572  mkdir -p build && cd build
  573  export CXXFLAGS="-fPIC" && cmake -D CMAKE_INSTALL_PREFIX=/usr/local ..
  574  make -j4
  575  cmake -h
  576  sudo make install
  577  ldconfig
  578  sudo ldconfig
  579  cd ../../caffe/
  580  ls
  581  make clean
  582  make -j4
  583  ls
  584  make matcaffe
  585  sudo apt-get install python-dev python-pip
  586  cd python/
  587  ls
  588  emacs require.sh
  589  sudo bash require.sh 
  590  cd ../
  591  ls
  592  make pycaffe
  593  ls
  594  cd ../
  595  ls
  596  cd ../
  597  ls
  598  cd programs/
  599  ls
  600  sudo reboot
  601  ls
  602  ifconfig
  603  tar zxf protobuf-2.5.0.tar.gz 
  604  cd protobuf-2.5.0/
  605  ls
  606  bash autogen.sh 
  607  sudo apt-get -y automake autoconf
  608  sudo apt-get install -y automake autoconf
  609  bash autogen.sh 
  610  ./configure --prefix=/usr/local
  611  make -j4
  612  sudo make install
  613  locate libprotoc.so
  614  sudo updatedb
  615  locate libprotoc.so
  616  sudo emacs /etc/profile
  617  source /etc/profile
  618  locate cblas
  619  locate cblas.so
  620  ls
  621  mkdir programs
  622  cd programs/
  623  ls
  624  ifconfig
  625  ls
  626  ls ../
  627  cp -r ../caffe-master caffe
  628  ls
  629  cd caffe/
  630  ls
  631  make -j4
  632  make clean
  633  ls
  634  ls -a
  635  make -j4
  636  rm -rf .build_debug
  637  make -j4
  638  cd ../
  639  rm -rf caffe
  640  git clone https://github.com/BVLC/caffe.git
  641  sudo apt-get install -y git cmake
  642  git clone https://github.com/BVLC/caffe.git
  643  cd caffe/
  644  ls
  645  cp Makefile.config.example  Makefile.config
  646  make -j4
  647  emacs Makefile
  648  emacs Makefile.config
  649  make
  650  emacs Makefile.config
  651  emacs Makefile
  652  make
  653  sudo ldconfig
  654  make
  655  ssh [email protected]
  656  cd /usr/local/MATLAB/R2014a/bin/
  657  ./matlab 
  658  cd caffe-master/
  659  sudo make all -j4
  660  sudo make clean
  661  sudo make all -j4
  662  ls /usr/local/include/
  663  whereis protobuf
  664  ls
  665  emacs Makefile.config
  666  make
  667  sudo make
  668  ls /usr/local/include/
  669  cd programs/
  670  ls
  671  grep MHz /proc/cpuinfo
  672  ls
  673  cd ATLAS/
  674  ls
  675  rm -rf build/
  676  ls
  677  mkdir -p build && cd build
  678  ../configure -D c -DPentiumCPS=3200 -b 64 -Fa alg -fPIC --prefix=/usr/local/atlas --with-netlib-lapack-tarfile=$cur/lapack-3.5.0.tgz
  679  cat ../INSTALL.txt 
  680  ../configure  -b 64 -Fa alg -fPIC --prefix=/usr/local/atlas --with-netlib-lapack-tarfile=$cur/lapack-3.5.0.tgz
  681  ../configure  -fPIC --prefix=/usr/local/atlas --with-netlib-lapack-tarfile=$cur/lapack-3.5.0.tgz
  682  ../configure  --prefix=/usr/local/atlas --with-netlib-lapack-tarfile=$cur/lapack-3.5.0.tgz


就酱,入职三天来就配置了这么些东西,真是悲哀啊,真是后悔以前总是偷懒,呜呜呜~



你可能感兴趣的:(ubuntu,CUDA,caffe)