原文鏈接: 點擊打開鏈接
參考自: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 顯卡來計算。具體步驟如下:
- 首先在BIOS設置裏選擇用Intel顯卡來顯示或作爲主要顯示設備
-
進入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 python
和which
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吧~