Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android fails to run basic example compiled with openblas (in emulator) #787

Closed
shkyang opened this issue Mar 5, 2016 · 9 comments
Closed
Assignees
Labels

Comments

@shkyang
Copy link
Contributor

shkyang commented Mar 5, 2016

Hi,

I'm running into the following error: arm-linux-androideabi-gcc -mfloat-abi=hard ex.cpp -I/opt/arm-tools/include /opt/arm-tools/lib/libopenblas.a
arm-linux-androideabi/bin/ld: error: uses VFP register arguments, output does not

ex.cpp is a simple example taken from the web:

include <cblas.h>

include <stdio.h>

int main()
{
int i=0;
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);

for(i=0; i<9; i++)
printf("%lf ", C[i]);
printf("\n");
return 0;
}

I compiled the android toolchain following instructions here: http://developer.android.com/ndk/guides/standalone_toolchain.html

make-standalone-toolchain.sh --arch=arm --platform=android-21 --install-dir=/tmp/my-android-toolchain

I compiled OpenBlas following instructions here: https://github.com/xianyi/OpenBLAS/wiki/How-to-build-OpenBLAS-for-Android

make HOSTCC=gcc CC=arm-linux-androideabi-gcc NO_LAPACK=1 TARGET=ARMV7

I have noticed that this error goes away when I edit Makefile.arm, and replace -mfloat-abi=hard with -mfloat-abi=soft (had to do this for building and linking ex.cpp as well).

Reading the ABI compatibility section of the standalone toolchain page:
If you want to target the armeabi-v7a ABI, you must set the following flags:
CFLAGS= -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16

I think that while I've built ex.cpp, the binary will be slower than if it was build to use the FPU. Could someone help me figure out how to build this properly?

Thanks,
Kevin

@brada4
Copy link
Contributor

brada4 commented Mar 6, 2016

Is that ld error complete? There should be some library name + preceding command line at least.

@shkyang
Copy link
Contributor Author

shkyang commented Mar 7, 2016

Here is the full output:

/tmp/my-android-toolchain/bin/arm-linux-androideabi-gcc -mfloat-abi=hard ex.cpp -I/opt/arm-tools/include /opt/arm-tools/lib/libopenblas.a
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /var/folders/5l/kndj2q_1371gmqd_sr703fl40000gn/T//ccKe1jnm.o uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(cblas_dgemm.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_nn.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_nt.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_tn.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_tt.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_thread_nn.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_thread_nt.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_thread_tn.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_thread_tt.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(memory.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(xerbla.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(blas_server.o) uses VFP register arguments, output does not
/private/tmp/my-android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /opt/arm-tools/lib/libopenblas.a(dgemm_beta.o) uses VFP register arguments, output does not
collect2: error: ld returned 1 exit status

@brada4
Copy link
Contributor

brada4 commented Mar 7, 2016

Are you sure these 2 are set?

TARGET_CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1
TARGET_LDFLAGS += -Wl,--no-warn-mismatch -lm_hard

@shkyang
Copy link
Contributor Author

shkyang commented Mar 7, 2016

Looking at the build output, I don't think I've set those properly, how can I set those, besides editing Makefile.arm?

@shkyang
Copy link
Contributor Author

shkyang commented Mar 7, 2016

Ok, I think I've figured it out, those flags are meant for when I compile and link ex.cpp, not for compiling the existing library. I'll go ahead and close the issue.

@shkyang shkyang closed this as completed Mar 7, 2016
@shkyang shkyang reopened this Mar 7, 2016
@shkyang shkyang changed the title Android Hard Soft floating point mismatch Android fails to run basic example compiled with openblas (in emulator) Mar 7, 2016
@shkyang
Copy link
Contributor Author

shkyang commented Mar 7, 2016

Closed it a little too fast. I've edited the OpenBLAS wiki page with new build instructions so I can build ex.cpp.

The problem now is I cannot run the compiled executable, I can get printouts before the call to cblas_dgemm, but not after.

Here's how I'm running it.

  1. I'm using android emulator, with default choices for spinning up a new avd.
  2. adb push ./a.out /
  3. adb shell
  4. ./a.out

Here's I get that the shell exited (no printouts). I don't have a segfault, but I don't get the expected printout of the matrix either.

@martin-frbg
Copy link
Collaborator

So are you building with hardfp or softfp option now ? An emulator may not show the exact same behaviour as the actual hardware, which might explain the exit without an accompanying segfault.
From #777 I understand that the assembler notation used in the optimized kernels would have to be completely different for softfp, hence the current requirement for building everything for the hardfp API as that is what is used in the OpenBLAS routines.

@xianyi xianyi added the Support label Mar 15, 2016
@xianyi xianyi self-assigned this Mar 15, 2016
@shkyang
Copy link
Contributor Author

shkyang commented Apr 11, 2016

I figured this out. I was mixing up hard and soft floating point in the compiles. The issue went away after I cleaned and started from scratch.

@shkyang shkyang closed this as completed Apr 11, 2016
@lygstate
Copy link

lygstate commented Jan 2, 2017

To be clear Android are already removed the armeabi-v7a-hard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants