Failed to complete amalgamation for Android
I followed the readme for the amalgamation for android, but failed to build it correctly.
I built the standalone toolchain:
export SYSROOT=$NDK/platforms/android-19/arch-arm
$NDK/build/tools/make-standalone-toolchain.sh --arch=arm --platform=android-19 --install-dir=$USERSPACE/NDK_standaloneToolchain/arm_android19 --toolchain=arm-linux-androideabi-4.9
Then built OpenBLAS for Android according to the instructions the readme refers to:
export PATH=$PATH:$USERSPACE/NDK_standaloneToolchain/arm_android19/bin
make HOSTCC=gcc CC=arm-linux-androideabi-gcc NO_LAPACK=1 TARGET=ARMV7
(Note that I used the stanadalone toolchain I built before as CC, assuming this is why I built it.. not very clear in the instructions)
Then I tried building MxNet amalgamation.
I edited the make file so it would compile using the standalone toolchain:
export CXX=/home/ubuntu/NDK_standaloneToolchain/arm_android19/bin/arm-linux-androideabi-g++
export SYS_ROOT=/home/ubuntu/NDK_standaloneToolchain/arm_android19/sysroot
export INCLUDE=/home/ubuntu/NDK_standaloneToolchain/arm_android19/include/c++/4.9
and edtted line 44:
${CXX} ${CFLAGS} -fPIC -o $@ -c jni/predictor.cc --sysroot=${SYS_ROOT} -I ${INCLUDE}
The additional --sysroot and -I are so it find certain includes in the cc files.
Then I had to comment out line 32 in mxnet_predict-all.cc because I couldn't find emmintrin.h anywhere...
I didn't see any of the includes the readme says to remove.
after finally passing all the compiler errors, the command make ANDROID=1 fails with:
warning: skipping incompatible <path..>/mxnet/3rdparty/OpenBLAS/libopenblas.so while searching for openblas
error: cannot find -lopenblas
I assumed this meant OpenBLAS wasn't build how the make expects it to, so I tried several time to build the standalone toolchain in various forms, and the build OpenBLAS again, to no avail.
I find this quite confusing, as I'm using the same toolchain to build OpenBLAS and the mxnet .so..
Any help much appreciated.
@tqchen Is there any android guy in our team could help on this?
I just managed to get past this incompatible lib issue. It was due to to much garbage in my OpenBLAS playground.. It compiles now, thanks to Leliana (Android example authour). I have more issues, but this was my bad. My apologies.
I'll close this, but if anyone would like to tell me if its OK that OpenBLAS only generates libopenblas.a file and no libopenblas.so? Amalgamation builds, but when I try to use the result .so I get linking errors..
Hi, I'm encountering the same problem, what do you mean by "too much garbage in my OpenBLAS playground"?
BTW, I'm confused too about OpenBLAS generating only a .a file (is this however the file that needs to be pased to the Amalgamation?)
-
What I meant was that after trying various builds, and changing some files, it was full of build garbage. try
make clean, or delete OpenBLAS, and clone it again. -
yes, the
.afile is what you want.
Thanks for your quick answer. I rebuilt OpenBLAS and the standalone toolchain but I get the same error (skipping incompatible...)
Any ideas?
Did you make sure to set the CC and CXX as shown in the standalone toolchain instruction? (it's near the bottom of the page).
also, be sure to pass your custom android-gcc as the parameter to to OpenBLAS make.
My make command looked like this:
export PATH=$PATH:/home/ubuntu/NDK_standaloneToolchain/arm_android19/bin
make HOSTCC=gcc CC=arm-linux-androideabi-gcc NO_LAPACK=1 TARGET=ARMV7
Quite sure, I wasn't actually specifying the CXX variable, but it doesn't works even in this case. Could this depend on which android API I choose creating the standalone toolchain? (I'm doing this with android-21).
BTW, more in general, the amalgamation section seems quite outdated w.r.t. the rest of mxnet in the last releases (i.e. the includes that the readme says to remove)
AFAIK the amalgamation readme is a contribution by someone who went through all you are going through now, and posted a guide. I guess this is why it isn't updated. I assume you mean NDK API 21, and not Android API 21, those a re 2 separate things.. Any way, I don't think there should be a problem with using API 21, as that's how the WhatIsIt demo was built.
It's been a while since I messed with this, so all I can recommend now is make sure you set the system path var to include your toolchain/bin, and to use the make command as I wrote earlier..
Seems I solved the compilation problem, but not sure why at some point the OpenBLAS library was fine w.r.t. the previous attempts. My guess is that since I started over from the very beginning (standalone toolchain creation, oblas compilation etc...) using always the same terminal instance, all the environment variables were correctly set. I'm available to write what I did step-by-step if someone is interested. Also, remember to check if the C++ standard library is correctly configured in the creation of the standalone toolchain, and try to link it in the amalgamation process (I added -lstdc++ in the Makefile)
Also, it seems that the jni_libmxnet_predict.so is needed in your Android Project to make it work, and not only the libmxnet_predict.so file.
Just to correct the last statement: ONLY the jni_libmxnet_predict.so is needed in the android project.
Precisely, and I spent a lot of time figuring it out since the WhatsThis example was somehow misleading (was it renamed to libmxnet_predict.so?), but maybe this is because I have zero experience with android / ndk.
Also, this should be the solution for https://github.com/dmlc/mxnet/issues/1747 (my problem raised trying to substitute the models in WhatsThis)
@iluvatar593 did you build ndk standalone toolchain with gfortran support? can you please share the steps you followed for building mxnet for android?