[Caffe] ubuntu14.04下使用OpenBLAS加速Caffe


一、apt安裝

 

sudo apt-get install libopenblas-dev

 

 

二、手動從source安裝

 

1. 下載OpenBLAS並編譯

1 git clone https://github.com/xianyi/OpenBLAS.git
2 cd OpenBLAS
3 make -j8
4 sudo make PREFIX=/usr/local/OpenBLAS install

 

2. 修改Caffe配置文件以下幾行

# open for OpenBlas
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
BLAS_INCLUDE := /usr/local/OpenBLAS/include
BLAS_LIB := /usr/local/OpenBLAS/lib

 

3. 添加環境變量

在 /etc/profile 末尾加上 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/OpenBLAS/lib/ 然后 sudo source /etc/profile 

注:直接安裝在/usr/local 下應該就不需要添加環境變量

 

4. 編譯Caffe

 

5. 可在環境變量中設置OpenBLAS所使用的CPU線程數

export OPENBLAS_NUM_THREADS=4

 

參考自:wxyblog.com/2015/08/27/openblas-with-caffe-on-ubuntu/

 

三、測試

用theano測試

1. 安裝theano

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano

 

2. 測試腳本

python `python -c "import os, theano; print os.path.dirname(theano.__file__)"`/misc/check_blas.py


在8核i7上的測試結果:

cpu信息:8  Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

測試結果:Total execution time: 2.58s on CPU (with direct Theano binding to blas).

 

在intel雙核上:

cpu信息:2  Intel(R) Pentium(R) CPU G3240 @ 3.10GHz

測試結果:Total execution time: 25.77s on CPU (with direct Theano binding to blas).

 

GPU上:

 THEANO_FLAGS=floatX=float32,device=gpu python /usr/local/lib/python2.7/dist-packages/theano/misc/check_blas.py 

GPU信息:一顆TitanX

測試結果:Total execution time: 0.05s on GPU.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM