此博客,部分过程有错误,但是,总体而言,思路是对的,稍加修改便可成功编译OpenBLAS的动态库和静态库
OpenBLAS(Open Basic Linear Algebra Subprograms)是开源的基本线性代数子程序库,是一个优化的高性能多核BLAS库,主要包括矩阵与矩阵、矩阵与向量、向量与向量等操作。它的License是BSD-3-Clause,可以商用,目前最新的发布版本是0.2.19。它的源码放在了GitHub上,由张先轶老师等持续维护。
OpenBLAS是由中科院软件所并行软件与计算科学实验室发起的基于GotoBLAS2 1.13 BSD版的开源BLAS库高性能实现。
BLAS是一个应用程序接口(API)标准,用以规范发布基础线性代数操作的数值库(如矢量或矩阵乘法)。该程序集最初发布于1979年,并用于建立更大的数值程序包(如LAPACK)。在高性能计算领域,BLAS被广泛使用。
OpenBLAS支持的操作系统包括:Windows、Linux、Mac OS X、FreeBSD、Android.
OpenBLAS支持CPU类型包括:Intel、AMD、MIPS64、ARM/ARM64、IBM Z13.
在Windows7上安装Perl操作步骤:
1. 从https://www.perl.org/get.html下载Windows ActiveState Perl 5.22.3.2204 windows 64-bit;
2. 点击安装,一直选择默认设置即可;
3. 打开命令提示符cmd,输入: $ perl -v 如果提示This is perl5,version 22等信息,说明安装正确,如下图:
OpenBLAS在VS2013上的编译过程:(注:直接用VS2013编译不如用MinGW编译好,因为VS2013仅编译C语言,没有编译AT&T汇编语言。在性能上用MinGW编译的库要快于直接用VS2013编译的库。要通过CMake和VS2013编译OpenBLAS源码,Windows操作系统上还需要安装Perl)
1. 从 https://github.com/xianyi/OpenBLAS/releases下载OpenBLAS 0.2.19源码,并解压缩;
2. 打开CMake GUI:source code: D:/Download/OpenBLAS-0.2.19/OpenBLAS-0.2.19; build thebinaries: D:/Download/OpenBLAS-0.2.19/build;
3. 点击Configure;Specify the generator for this project: Visual Studio 12 2013 Win64,Finish;
4. 修改CMAKE_INSTALL_PREFIX路径为:D:/Download/OpenBLAS-0.2.19/install;默认BUILD_WITHOUT_LAPACK是被勾选的,即不会产生Lapack库;
5. 再次点击Configure,点击Generate,生成OpenBLAS.sln,如下图;
6. 打开OpenBLAS.sln:分别在Debug和Release下,重新生成解决方案,便会生成libopenblas.dll和libopenblas.lib(注:Debug和Release下,默认生成的库的名字一样,并且在同一个目录下);
7. 新建一个控制台工程,验证其openblas库的正确性,测试代码如下:
-
-
-
-
-
int test_openblas()
-
{
-
int th_model = openblas_get_parallel();
-
switch (th_model) {
-
case OPENBLAS_SEQUENTIAL:
-
printf( "OpenBLAS is compiled sequentially.\n");
-
break;
-
case OPENBLAS_THREAD:
-
printf( "OpenBLAS is compiled using the normal threading model\n");
-
break;
-
case OPENBLAS_OPENMP:
-
printf( "OpenBLAS is compiled using OpenMP\n");
-
break;
-
}
-
-
int n = 2;
-
double* x = ( double*) malloc(n* sizeof( double));
-
double* upperTriangleResult = ( double*) malloc(n*(n + 1)* sizeof( double) / 2);
-
-
for ( int j = 0; j<n*(n + 1) / 2; j++)
-
upperTriangleResult[j] = 0;
-
-
x[ 0] = 1; x[ 1] = 3;
-
-
cblas_dspr(CblasRowMajor, CblasUpper, n, 1, x, 1, upperTriangleResult);
-
double*& A = upperTriangleResult;
-
std:: cout << A[ 0] << "\t" << A[ 1] << std:: endl << "*\t" << A[ 2] << std:: endl;
-
-
free(upperTriangleResult);
-
free(x);
-
-
return 0;
-
}
Note: 也可以用命令提示符定位到openblas根目录下,执行:$ cmake -G "Visual Studio 12 Win64" 会直接生成OpenBLAS.sln工程
GitHub:https://github.com/fengbingchun/Caffe_Test