【问题标题】:conflicts of cblas APIs definition between OpenBLAS and Eigen 3.3.4OpenBLAS 和 Eigen 3.3.4 之间的 cblas API 定义冲突
【发布时间】:2017-12-12 08:24:02
【问题描述】:

我是 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? ^-^

非常感谢您的帮助。

【问题讨论】:

  • 删除#include "cblas.h"怎么样?
  • 感谢@ggael 的快速反馈。
  • Android 工具链抱怨 - 使用未声明的标识符 CblasColMajor、CblasNoTrans、CblasTrans。如果删除 cblas.h,工具链在哪里查找 cblas 定义?我的意思是我在 NDK 目录中找不到类似 cblas.h 的文件。

标签: eigen openblas


【解决方案1】:

似乎有两种界面风格——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 *);

在本征的 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 *);   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2015-02-13
    相关资源
    最近更新 更多