Ubuntu14.04 +caffe+cuda 7.0

原文链接: 点击打开链接

参考自:https://gist.github.com/bearpaw/c38ef18ec45ba6548ec0


若需要cuDNN加速的童鞋,可以参考上面的网址安装CUDA6.5


本步骤能实现用Intel核芯显卡来进行显示, 用NVIDIA GPU进行计算。

1. 安装开发所需的依赖包

安装开发所需要的一些基本包

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> apt-get install build-essential  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># basic requirement</span>
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#required by caffe</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

2. 安装CUDA及驱动

2.1 准备工作

在关闭桌面管理 lightdm 的情况下安装驱动似乎可以实现Intel 核芯显卡 来显示 + NVIDIA 显卡来计算。具体步骤如下:

  1. 首先在BIOS设置里选择用Intel显卡来显示或作为主要显示设备
  2. 进入Ubuntu, 按 ctrl+alt+F1 进入tty, 登录tty后输入如下命令

    <code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> service lightdm stop</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

    该命令会关闭lightdm。如果你使用 gdm或者其他的desktop manager, 请在安装NVIDIA驱动前关闭他。

2.2 (貌似可以略过)安装NVIDIA显卡驱动

输入下列命令添加驱动源

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo add<span class="hljs-attribute" style="box-sizing: border-box;">-apt</span><span class="hljs-attribute" style="box-sizing: border-box;">-repository</span> ppa:xorg<span class="hljs-attribute" style="box-sizing: border-box;">-edgers</span>/ppa
sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> update</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

安装346版驱动

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> install nvidia<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">346</span> nvidia<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">346</span><span class="hljs-attribute" style="box-sizing: border-box;">-uvm</span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

安装完成后, 最好把下列包也一并安装上 (否则以后可能会缺少文件)

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> install nvidia<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">346</span><span class="hljs-attribute" style="box-sizing: border-box;">-dev</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

安装完成后 reboot.

2.3 下载deb包及安装CUDA

使用deb包安装CUDA及驱动能省去很多麻烦(参见CUDA Starting Guide)。下载对应于你系统的CUDA deb包
我下载的是7.0版的,需要先注册才能获得RC版下载权限。 
我下载的是deb包, 
先双击后在Ubuntu Software Center里点install。 
或用下列命令添加软件源

<code class="language-sh hljs xml has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> sudo dpkg -i cuda-repo-<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">distro</span>></span>_<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">version</span>></span>_<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">architecture</span>></span>.deb
 sudo apt-get update</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

然后在终端中用下列命令安装CUDA

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> apt-get install cuda</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

安装完成后重启电脑.

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> reboot</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

2.4 安装cuDNN

由于还没有出配合CUDA7.0的cuDNN下载,所以暂时不安装cuDNN,以免发生不知名错误。

2.5 设置环境变量

安装完成后需要在/etc/profile中添加环境变量, 在文件最后添加:

<code class="language-sh hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-constant" style="box-sizing: border-box;">PATH</span>=<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/usr/local</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/cuda/bin</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$PATH</span>
export <span class="hljs-constant" style="box-sizing: border-box;">PATH</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

保存后, 执行下列命令, 使环境变量立即生效

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">source</span> /etc/profile</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

同时需要添加lib库路径: 在 /etc/ld.so.conf.d/加入文件 cuda.conf, 内容如下

<code class="language-sh hljs lua has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">/usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/cuda/lib64</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

保存后,执行下列命令使之立刻生效

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> ldconfig</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

3. 安装CUDA SAMPLE

进入/usr/local/cuda/samples, 执行下列命令来build samples

<code class="language-sh hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo make <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">all</span> <span class="hljs-attribute" style="box-sizing: border-box;">-j8</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

整个过程大概10分钟左右, 全部编译完成后, 进入 samples/bin/x86_64/linux/release, 运行deviceQuery

<code class="language-sh hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">./deviceQuery</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

如果出现显卡信息, 则驱动及显卡安装成功:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">./deviceQuery Starting...

 CUDA Device Query (Runtime API) <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">version</span> (CUDART static linking)

Detected <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> CUDA Capable device(s)

Device <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"GeForce GTX 980"</span>
  CUDA Driver Version / Runtime Version          <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7.0</span> / <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7.0</span>
  CUDA Capability Major/Minor <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">version</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">number</span>:    <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5.2</span>
  Total amount <span class="hljs-operator" style="box-sizing: border-box;">of</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">global</span> memory:                 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> MBytes (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4294770688</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>)
  (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span>) Multiprocessors, (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span>) CUDA Cores/MP:     <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2048</span> CUDA Cores
  GPU Clock rate:                                <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1329</span> MHz (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.33</span> GHz)
  Memory Clock rate:                             <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3505</span> Mhz
  Memory Bus Width:                              <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">256</span>-bit
  L2 Cache Size:                                 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2097152</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>
  Maximum Texture Dimension Size (x,y,z)         <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>D=(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>D=(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>D=(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span>)
  Maximum Layered <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>D Texture Size, (<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">num</span>) layers  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>D=(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16384</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2048</span> layers
  Maximum Layered <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>D Texture Size, (<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">num</span>) layers  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>D=(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16384</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16384</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2048</span> layers
  Total amount <span class="hljs-operator" style="box-sizing: border-box;">of</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">constant</span> memory:               <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>
  Total amount <span class="hljs-operator" style="box-sizing: border-box;">of</span> shared memory per block:       <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">49152</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>
  Total <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">number</span> <span class="hljs-operator" style="box-sizing: border-box;">of</span> registers available per block: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>
  Warp size:                                     <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">32</span>
  Maximum <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">number</span> <span class="hljs-operator" style="box-sizing: border-box;">of</span> threads per multiprocessor:  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2048</span>
  Maximum <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">number</span> <span class="hljs-operator" style="box-sizing: border-box;">of</span> threads per block:           <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1024</span>
  Max dimension size <span class="hljs-operator" style="box-sizing: border-box;">of</span> <span class="hljs-operator" style="box-sizing: border-box;">a</span> thread block (x,y,z): (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1024</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1024</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span>)
  Max dimension size <span class="hljs-operator" style="box-sizing: border-box;">of</span> <span class="hljs-operator" style="box-sizing: border-box;">a</span> grid size    (x,y,z): (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2147483647</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65535</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65535</span>)
  Maximum memory pitch:                          <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2147483647</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>
  Texture alignment:                             <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">512</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span>
  Concurrent copy <span class="hljs-operator" style="box-sizing: border-box;">and</span> kernel execution:          Yes <span class="hljs-operator" style="box-sizing: border-box;">with</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> copy engine(s)
  Run <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">time</span> limit <span class="hljs-command" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">on</span> <span class="hljs-title" style="box-sizing: border-box;">kernels</span>:                     <span class="hljs-title" style="box-sizing: border-box;">Yes</span></span>
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> / <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> / <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() <span class="hljs-operator" style="box-sizing: border-box;">with</span> device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7.0</span>, CUDA Runtime Version = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7.0</span>, NumDevs = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, Device0 = GeForce GTX <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">980</span>
Result = PASS
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li></ul>

4. 安装openBLAS 或 Intel MKL 或 Atlas

A.如果图省事儿,可以用下列命令安装免费的atlas

<code class="language-sh hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> install libatlas<span class="hljs-attribute" style="box-sizing: border-box;">-base</span><span class="hljs-attribute" style="box-sizing: border-box;">-dev</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

B.(不推荐。。caffe总是找不到include和lib)我安装的是openBLAS,首先下载openBLAS 
网址:http://www.openblas.net/ 
网页右上角或最下面下载tar文件,如:

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">xianyi<span class="hljs-attribute" style="box-sizing: border-box;">-OpenBLAS</span><span class="hljs-attribute" style="box-sizing: border-box;">-v0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.2</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.13</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span><span class="hljs-attribute" style="box-sizing: border-box;">-g51ce5ef</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>tar<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>gz</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

随后解压缩,在终端中输入:

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">tar <span class="hljs-attribute" style="box-sizing: border-box;">-xzvf</span> xianyi<span class="hljs-attribute" style="box-sizing: border-box;">-OpenBLAS</span><span class="hljs-attribute" style="box-sizing: border-box;">-v0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.2</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.13</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span><span class="hljs-attribute" style="box-sizing: border-box;">-g51ce5ef</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>tar<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>gz</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

编译

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">cd xianyi<span class="hljs-attribute" style="box-sizing: border-box;">-OpenBLAS</span><span class="hljs-attribute" style="box-sizing: border-box;">-v0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.2</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.13</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span><span class="hljs-attribute" style="box-sizing: border-box;">-g51ce5ef</span>
make <span class="hljs-attribute" style="box-sizing: border-box;">-j8</span>
sudo make PREFIX<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span>/opt/OpenBLAS install</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

openBLAS就安装到/opt/OpenBLAS了。

C.如果有mkl安装包,首先解压安装包,下面有一个install_GUI.sh文件, 执行该文件,会出现图形安装界面,根据说明一步一步执行即可。

注意: 安装完成后需要添加library路径, 创建/etc/ld.so.conf.d/intel_mkl.conf文件, 在文件中添加内容

<code class="hljs vbnet has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">/opt/intel/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>
/opt/intel/mkl/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>/intel64</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

注意把路径替换成自己的安装路径。 编辑完后执行

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> ldconfig</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

5. 安装OpenCV

虽然我们已经安装了libopencv-dev, 但该库似乎会导致libtiff的相关问题, 所以我们需要从源代码build 自己的版本。这个尽量不要手动安装, Github上有人已经写好了完整的安装脚本, 能自动安装所有dependencies.

下载该脚本,进入Ubuntu/2.4 目录, 给所有shell脚本加上可执行权限

<code class="language-sh hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">chmod</span> +<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">x</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">*.</span>sh</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

修改脚本opencv2_4_X.sh, 在cmake中加入参数

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-attribute" style="box-sizing: border-box;">-D</span> BUILD_TIFF<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">=</span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">ON</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

然后安装(当前为2.4.9)

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> ./opencv2_4_9.sh</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

脚本会自动安装依赖项,下载安装包,编译并安装OpenCV。整个过程大概半小时左右。

注意,安装2.4.9时中途可能会报错

<code class="hljs vbnet has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">opencv-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.4</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.9</span>/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">51</span>): <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">error</span>: a storage <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">class</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> allowed <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> an <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">explicit</span> specialization</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

解决方法在此 下载 NCVPixelOperations.hpp, 替换掉opencv2.4.9内的文件, *并注释掉opencv2_4_9.sh中下载opencv包的代码, 重新执行sudo ./opencv2_4_9.sh`.

还有可能报另外一个错

<code class="hljs profile has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-filename" style="box-sizing: border-box;">_compile_generated_gpu_mat.cu.obj
nvcc fatal </span>: Unsupported gpu architecture <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'compute_11'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

解决方法为 
在上面cuda测试的时候显示的CUDA Capability Major/Minor version number: 5.2或者到nvidia官网https://developer.nvidia.com/cuda-gpus#collapse2 找到自己显卡的Compute Capability, 
修改脚本opencv2_4_X.sh, 在cmake中加入参数

<code class="hljs haml has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> -<span class="ruby" style="box-sizing: border-box;"><span class="hljs-constant" style="box-sizing: border-box;">D</span> <span class="hljs-constant" style="box-sizing: border-box;">CUDA_ARCH_BIN</span>=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"5.2"</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

(我显卡的Compute Capability是5.2) 
听说提前设定好CUDA_ARCH_BIN还会给编译过程加速。


6. 安装Caffe所需要的Python环境

6.1 安装anaconda包

在此下载最新的安装包, 用默认设置安装在用户目录下。

6.2 安装python依赖库

打开新的终端, 用which pythonwhich pip确定使用的是anaconda提供的python环境,然后进入caffe_root/python, 执行下列命令

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> req <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> $(cat requirements.txt); <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">do</span> pip install <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$req</span>; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">done</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

6.3 修正Anaconda存在的bug

加入在编译或者运行caffe时遇到这样的错误

<code class="hljs vbnet has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">/usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>/x86_64-linux-gnu/libx264.so<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.142</span>:undefined reference <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">' </span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

那么请删除掉anaconda/lib中的libm.*. 参考this issue

6.4 添加Anaconda Library Path

这里需要注意,在运行Caffe时,可能会报一些找不到libxxx.so的错误,而用 locate libxxx.so命令发现已经安装在anaconda中,这时首先想到的是在/etc/ld.so.conf.d/ 下面将 your_anaconda_path/lib 加入 LD_LIBRARY_PATH中。 但是这样做可能导致登出后无法再进入桌面!!!原因(猜测)可能是anaconda的lib中有些内容于系统自带的lib产生冲突。

正确的做法是:为了不让系统在启动时就将anaconda/lib加入系统库目录,可以在用户自己的~/.bashrc 中添加library path, 比如我就在最后添加了两行

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># add library path</span>
LD_LIBRARY_PATH=your_anaconda_path/lib:<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$LD_LIBRARY_PATH</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> LD_LIBRARY_PATH</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

开启另一个终端后即生效,并且重启后能够顺利加载lightdm, 进入桌面环境。

7. 安装MATLAB

Caffe提供了MATLAB接口, 有需要用MATLAB的同学可以额外安装MATLAB。 安装教程请自行搜索。

安装完成后添加图标

<code class="language-sh hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> vi /usr/share/applications/Matlab.desktop</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

输入以下内容

<code class="hljs ini has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 102, 102);">[Desktop Entry]</span>
<span class="hljs-setting" style="box-sizing: border-box;">Type=<span class="hljs-value" style="box-sizing: border-box;">Application</span></span>
<span class="hljs-setting" style="box-sizing: border-box;">Name=<span class="hljs-value" style="box-sizing: border-box;">Matlab</span></span>
<span class="hljs-setting" style="box-sizing: border-box;">GenericName=<span class="hljs-value" style="box-sizing: border-box;">Matlab R2014b</span></span>
<span class="hljs-setting" style="box-sizing: border-box;">Comment=<span class="hljs-value" style="box-sizing: border-box;">Matlab:The Language of Technical Computing</span></span>
<span class="hljs-setting" style="box-sizing: border-box;">Exec=<span class="hljs-value" style="box-sizing: border-box;">sh /usr/local/MATLAB/R2014b/bin/matlab -desktop</span></span>
<span class="hljs-setting" style="box-sizing: border-box;">Icon=<span class="hljs-value" style="box-sizing: border-box;">/usr/local/MATLAB/Matlab.png</span></span>
<span class="hljs-setting" style="box-sizing: border-box;">Terminal=<span class="hljs-value" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span></span></span>
<span class="hljs-setting" style="box-sizing: border-box;">Categories=<span class="hljs-value" style="box-sizing: border-box;">Development;Matlab;</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>

(I use the R2013b patched package. First you should uncompress the .iso file. Then use sudo cp to copy the patch file)

8. 编译Caffe

8.1 编译主程序

终于完成了所有环境的配置,可以愉快的编译Caffe了! 进入caffe根目录, 首先复制一份Makefile.config, 然后修改里面的内容,主要需要修改的参数包括

我的Makefile.config内容如下

<code class="hljs makefile has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-constant" style="box-sizing: border-box;">CUDA_DIR</span> := /usr/local/cuda
<span class="hljs-constant" style="box-sizing: border-box;">CUDA_ARCH</span> := -gencode arch=compute_20,code=sm_20 \
        -gencode arch=compute_20,code=sm_21 \
        -gencode arch=compute_30,code=sm_30 \
        -gencode arch=compute_35,code=sm_35 \
        -gencode arch=compute_50,code=sm_50 \
        -gencode arch=compute_50,code=compute_50


<span class="hljs-constant" style="box-sizing: border-box;">BLAS</span> := open
<span class="hljs-constant" style="box-sizing: border-box;">BLAS_INCLUDE</span> := /opt/OpenBLAS/include
<span class="hljs-constant" style="box-sizing: border-box;">BLAS_LIB</span> := /opt/OpenBLAS/lib

<span class="hljs-constant" style="box-sizing: border-box;">MATLAB_DIR</span> := /usr/local/MATLAB/R2014b/

<span class="hljs-constant" style="box-sizing: border-box;">PYTHON_INCLUDE</span> := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
<span class="hljs-constant" style="box-sizing: border-box;">PYTHON_LIB</span> := /usr/lib
<span class="hljs-constant" style="box-sizing: border-box;">INCLUDE_DIRS</span> := <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(PYTHON_INCLUDE)</span> /usr/local/include
<span class="hljs-constant" style="box-sizing: border-box;">LIBRARY_DIRS</span> := <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(PYTHON_LIB)</span> /usr/local/lib /usr/lib

<span class="hljs-constant" style="box-sizing: border-box;">BUILD_DIR</span> := build
<span class="hljs-constant" style="box-sizing: border-box;">DISTRIBUTE_DIR</span> := distribute

<span class="hljs-constant" style="box-sizing: border-box;">TEST_GPUID</span> := 0
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li></ul>
  • CPU_ONLY 是否只使用CPU模式,没有GPU没安装CUDA的同学可以打开这个选项
  • BLAS (使用intel mkl还是atlas)
  • MATLAB_DIR 如果需要使用MATLAB wrapper的同学需要指定matlab的安装路径, 如我的路径为 /usr/local/MATLAB/R2013b (注意该目录下需要包含bin文件夹,bin文件夹里应该包含mex二进制程序)
  • DEBUG 是否使用debug模式,打开此选项则可以在eclipse或者NSight中debug程序 
    具体设置可以参考Caffe根目录下原有的Makefile.config

完成设置后, 开始编译

<code class="language-sh hljs go has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> all -j4
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> test
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> runtest</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

注意 -j4 是指使用几个线程来同时编译, 可以加快速度, j后面的数字可以根据CPU core的个数来决定, 我的CPU使4核, 所以-j4.

8.2 编译Matlab wrapper

执行如下命令

<code class="hljs go has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> matcaffe</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

然后就可以跑官方的matlab demo啦。

8.3 编译Python wrapper

<code class="hljs go has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> pycaffe </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

然后基本就全部安装完拉.

接下来大家尽情地跑demo吧~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章