0

I am newbie to Eigen and hope to use OpenBLAS as a backend of Eigen 3.3.4 on Android/ARMv7. From the following site I tried a test to use them in one application (Compiling environment is ubuntu 16.04 + Android NDK r15c.),

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

gemm.cpp has code as follow,

#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;
}

My Android.mk looks like this,

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)

When trying to compile the project, I encountered errors as follow(I picked one to paste here),

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 *);

There are different return types for the same blas functions in openblas and eigen.

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

thanks so much for your help.

yang0773
  • 1
  • 1
  • what about removing `#include "cblas.h"`? – ggael Dec 12 '17 at 10:28
  • Thanks @ggael for quick feedback. – yang0773 Dec 12 '17 at 12:14
  • Android toolchain complains - use of undeclared identifier CblasColMajor, CblasNoTrans, CblasTrans. If removing cblas.h, where does the toolchain look for the cblas definitions? I mean I can't find cblas.h-like files in NDK dir. – yang0773 Dec 12 '17 at 12:22

1 Answers1

0

It seems to have two interface styles - fortran blas hand cblas. Eigen only supports fortran blas calls and developers need not provide a header file. I should remove Eigen/Dense if only using cblas functions. But I still am puzzled at the issue. Why do Eigen and openblas define different return types for fortran-style functions?

in common_interface.h of OpenBLAS,

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

in misc/blas.h of Eigen,

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 *);   
yang0773
  • 1
  • 1