在训练网络时发现CPU使用率低,为了提高其使用率,进而实现加速,本文参考了两篇博客,最终采用OpenBLAS实现。
参考的两篇博客地址如下,在此表示感谢:
https://www.cnblogs.com/llxrl/p/5292119.html
http://blog.csdn.net/quhediegooo/article/details/53082809
在实验过程中的具体实现步骤如下:
- apt-get install libopenblas-dev (没有这一步会报错)
- git clone https://github.com/xianyi/OpenBLAS.git (由于是在云服务器上实现,网络带宽较小,速度很慢,所以是先下载在本地主机上后再上传的服务器的)
- cd OpenBLAS
- make -jn (n为使用的核数)
- make PREFIX=/root/OpenBLAS install (由于是在云服务器,最好是先查一下当前所在路径pwd命令,我的是/root/OpenBLAS)
- 修改caffe中Makefile.config配置文件中的参数:
# 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 := /root/OpenBLAS/include
BLAS_LIB := /root/OpenBLAS/lib
7.添加环境变量:
export OPENBLAS_NUM_THREADS=n (n为使用的核数)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/OpenBLAS/lib/
8.重新编译caffe:
make clean
make all -jn (n为使用的核数)
make test
make runtest
9.修改成功,测试发现CPU使用率提升