OpenBLAS和Eigen 3.3.4之间的cblas API定义冲突

时间:2017-12-12 08:24:03

标签: eigen openblas

我是Eigen的新手,希望在Android / ARMv7上使用OpenBLAS作为Eigen 3.3.4的后端。从以下站点我尝试了一个测试,在一个应用程序中使用它们(编译环境是ubuntu 16.04 + Android NDK r15c。),

http://eigen.tuxfamily.org/dox-devel/TopicUsingBlasLapack.html

gemm.cpp的代码如下,

#include <iostream>
#include <Eigen/Dense>

#include "cblas.h"

using namespace Eigen;

int main()
{
    double A[6] = {1.0, 2.0, 1.0,-3.0, 4.0,-1.0};
    double B[6] = {1.0, 2.0, 1.0,-3.0, 4.0,-1.0};
    double C[9] = {.5 , .5 , .5 , .5 , .5 , .5 , .5 , .5 , .5};
    cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, 3, 3, 2, 1, A, 3, B, 3, 2, C, 3);

    return 0;
}

我的Android.mk看起来像这样,

LOCAL_PATH := $(call my-dir)
#build a test executable
include $(CLEAR_VARS)

LOCAL_MODULE := gemm 
LOCAL_C_INCLUDES := /home/yangfan/workspace/study/eigen-3.3.4
LOCAL_C_INCLUDES += /home/yangfan/workspace/study/openBLAS
LOCAL_SRC_FILES := $(LOCAL_PATH)/gemm.cpp
LOCAL_CFLAGS += -DEIGEN_USE_BLAS

LOCAL_CFLAGS += -fPIC -frtti -fexceptions -lz -O3
LOCAL_LDLIBS += -lm -llog -lz
LOCAL_LDLIBS += $(LOCAL_PATH)/openblas-libs/libopenblas.a

include $(BUILD_EXECUTABLE)

在尝试编译项目时,我遇到了如下错误(我选择了一个粘贴在这里),

In file included from ././gemm.cpp:4:    
In file included from /home/yangfan/workspace/study/openBLAS/cblas.h:5:    
In file included from /home/yangfan/workspace/study/openBLAS/common.h:751:    
/home/yangfan/workspace/study/openBLAS/common_interface.h:105:9: error: functions that differ only in their return type cannot be overloaded    
void BLASFUNC(dcopy) (blasint *, double *, blasint *, double *, blasint *);

/home/yangfan/workspace/study/eigen-3.3.4/Eigen/src/Core/util/../../misc/blas.h:44:8: note: previous declaration is here
int    BLASFUNC(dcopy) (int *, double *, int *, double *, int *);

openblas和eigen中相同的blas函数有不同的返回类型。

Q1. Why are there different return types for the same blas APIs in OpenBLAS and Eigen?

Q2. Is there something missing? Hope some guides to use OpenBLAS as a backend of Eigen.

Q3. Which version is higher, 3.3.4 or 3.3.90? ^-^

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

它似乎有两种界面风格 - fortran blas hand cblas。 Eigen仅支持fortran blas调用,开发人员无需提供头文件。如果只使用cblas函数,我应该删除Eigen / Dense。 但我仍然对这个问题感到困惑。为什么Eigen和openblas为fortran风格的函数定义了不同的返回类型?

在OpenBLAS的common_interface.h中,

void BLASFUNC(dgemm)(char *, char *, blasint *, blasint *, blasint *, double *,
       double *, blasint *, double *, blasint *, double *, double *, blasint *);

在Eigen的misc / blas.h中,

int BLASFUNC(dgemm)(const char *, const char *, const int *, const int *, const int *, const double *, 
       const double *, const int *, const double *, const int *, const double *, double *, const int *);