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

Cannot find crtbegin_dynamic.o #8

Closed
huyn opened this issue Feb 24, 2017 · 16 comments
Closed

Cannot find crtbegin_dynamic.o #8

huyn opened this issue Feb 24, 2017 · 16 comments

Comments

@huyn
Copy link

huyn commented Feb 24, 2017

I compile OpenBLAS with fortran on virtual machine of Ubuntu 14.04.4. Main OS is OS X 10.11.6. NDK version is r13b.
I download gcc-arm64-linux-x86_64.tar.bz2 from release 760fb01 and release it under $NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/ to replace linux-x86-64.

This is my make command:

make TARGET=ARMV8 BINARY=64 CFLAGS=--sysroot=/home/huyaonan/android-ndk-r13b//platforms/android-21/arch-arm64 HOSTCC=gcc CC=aarch64-linux-android-gcc FC=aarch64-linux-android-gfortran USE_THREAD=1 USE_OPENMP=1 USE_LAPACK=1 PREFIX=/home/huyaonan/torch-project/torch-android/install

But I get errors:

aarch64-linux-android-ar  -ru ../../libopenblas_armv8p-r0.2.20.dev.a strtri_UU_single.o strtri_UN_single.o strtri_LU_single.o strtri_LN_single.o strtri_UU_parallel.o strtri_UN_parallel.o strtri_LU_parallel.o strtri_LN_parallel.o dtrtri_UU_single.o dtrtri_UN_single.o dtrtri_LU_single.o dtrtri_LN_single.o dtrtri_UU_parallel.o dtrtri_UN_parallel.o dtrtri_LU_parallel.o dtrtri_LN_parallel.o ctrtri_UU_single.o ctrtri_UN_single.o ctrtri_LU_single.o ctrtri_LN_single.o ctrtri_UU_parallel.o ctrtri_UN_parallel.o ctrtri_LU_parallel.o ctrtri_LN_parallel.o ztrtri_UU_single.o ztrtri_UN_single.o ztrtri_LU_single.o ztrtri_LN_single.o ztrtri_UU_parallel.o ztrtri_UN_parallel.o ztrtri_LU_parallel.o ztrtri_LN_parallel.o
make[2]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack/trtri'
make[1]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack'
make[1]: Entering directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack-netlib'
( cd INSTALL; make -j 2 )
make[2]: Entering directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack-netlib/INSTALL'
make[2]: warning: -jN forced in submake: disabling jobserver mode.
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o lsame.o lsame.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o lsametst.o lsametst.f
aarch64-linux-android-gfortran -O0 -Wall -fPIC -march=armv8-a -c -o slamch.o slamch.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o slamchtst.o slamchtst.f
aarch64-linux-android-gfortran -O0 -Wall -fPIC -march=armv8-a -c -o dlamch.o dlamch.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o dlamchtst.o dlamchtst.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o second_NONE.o second_NONE.f
second_NONE.f:38.6:

      REAL FUNCTION SECOND( )                                           
      1
Warning: 'second' declared at (1) is also the name of an intrinsic.  It can only be called via an explicit interface or if declared EXTERNAL.
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o secondtst.o secondtst.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o dsecnd_NONE.o dsecnd_NONE.f
secondtst.f:116.26:

      SUBROUTINE MYSUB(N,X,Y)                                           
                          1
Warning: Unused dummy argument 'x' at (1)
secondtst.f:116.28:

      SUBROUTINE MYSUB(N,X,Y)                                           
                            1
Warning: Unused dummy argument 'y' at (1)
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o dsecndtst.o dsecndtst.f
dsecndtst.f:120.26:

      SUBROUTINE MYSUB(N,X,Y)                                           
                          1
Warning: Unused dummy argument 'x' at (1)
dsecndtst.f:120.28:

      SUBROUTINE MYSUB(N,X,Y)                                           
                            1
Warning: Unused dummy argument 'y' at (1)
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o tstiee.o tstiee.f
tstiee.f:81.69:

      INTEGER          FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3,  
                                                                     1
Warning: Unused dummy argument 'n3' at (1)
tstiee.f:81.57:

      INTEGER          FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3,  
                                                         1
Warning: Unused dummy argument 'opts' at (1)
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o ilaver.o ilaver.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a -c -o LAPACK_version.o LAPACK_version.f
aarch64-linux-android-gfortran -O2 -Wall -fPIC -march=armv8-a  -o testlsame lsame.o lsametst.o
/home/huyaonan/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtbegin_dynamic.o: No such file or directory
/home/huyaonan/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lm
/home/huyaonan/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lm
/home/huyaonan/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lc
/home/huyaonan/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -ldl
/home/huyaonan/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtend_android.o: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [testlsame] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack-netlib/INSTALL'
make[1]: *** [lapack_install] Error 2
make[1]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack-netlib'
make: *** [netlib] Error 2

I have checked crtbegin_dynamic.o did exist under dir /home/huyaonan/android-ndk-r13b//platforms/android-21/arch-arm64

Thanks for any suggestion :)

@buffer51
Copy link
Owner

buffer51 commented Feb 24, 2017

Hi @huyn,

You have is not specified what recipes to build from the Makefile, thus it is doing all of them.
The errors arise from OpenBLAS's netlib and tests recipe, which will try linking & running tests.
This won't work since you're cross-compiling.

You should make libs, then install:

make TARGET=ARMV8 BINARY=64 CFLAGS=--sysroot=/home/huyaonan/android-ndk-r13b/platforms/android-21/arch-arm64 HOSTCC=gcc CC=aarch64-linux-android-gcc FC=aarch64-linux-android-gfortran USE_THREAD=1 USE_OPENMP=1 USE_LAPACK=1 libs
make PREFIX=/home/huyaonan/torch-project/torch-android/install install

I've updated the OpenBLAS for Android instructions accordingly.

Sidenotes:

  • This won't build the netlib recipe. If you need it, you will need to go inside lapack-netlib/INSTALL/Makefile to comment test recipes. After that, it should also work.
  • Since you are not using ndk-build, there is no need to put the toolchain inside the NDK. Moreover, instead of specifying yourself the sysroot, you should consider making a standalone toolchain (see the last section of my README), which will take care of that and more.

@buffer51
Copy link
Owner

Actually, I was mistaken. The tests in netlib are only linking tests.

If you make a standalone toolchain as suggested, this will solve this problem and allow you to build both libs and netlib.

@huyn
Copy link
Author

huyn commented Feb 27, 2017

Thanks! @buffer51
With your infomation, openblas is compiled successfully with LAPACK.

make[2]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack/trtri'
make[1]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS/lapack'
make -j 2 -f Makefile.install install
make[1]: Entering directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS'
Generating openblas_config.h in /home/huyaonan/torch-project/torch-android/install/include
Generating f77blas.h in /home/huyaonan/torch-project/torch-android/install/include
Generating cblas.h in /home/huyaonan/torch-project/torch-android/install/include
Copying LAPACKE header files to /home/huyaonan/torch-project/torch-android/install/include
Copying the static library to /home/huyaonan/torch-project/torch-android/install/lib
Copying the shared library to /home/huyaonan/torch-project/torch-android/install/lib
Generating openblas.pc in /home/huyaonan/torch-project/torch-android/install/lib/pkgconfig
Generating OpenBLASConfig.cmake in /home/huyaonan/torch-project/torch-android/install/lib/cmake/openblas
Generating OpenBLASConfigVersion.cmake in /home/huyaonan/torch-project/torch-android/install/lib/cmake/openblas
Install OK!
make[1]: Leaving directory `/home/huyaonan/torch-project/torch-android/external/OpenBLAS'

But when going to checking procedure, I got

-- Checking for [openblas]
--   Library openblas: /home/huyaonan/torch-project/torch-android/install/lib/libopenblas.a
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Performing Test BLAS_F2C_DOUBLE_WORKS
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
   BLAS_F2C_DOUBLE_WORKS_EXITCODE (advanced)
For details see /home/huyaonan/torch-project/torch-android/build/TryRunResults.cmake
-- Performing Test BLAS_F2C_DOUBLE_WORKS - Failed
-- Performing Test BLAS_F2C_FLOAT_WORKS
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
   BLAS_F2C_FLOAT_WORKS_EXITCODE (advanced)
For details see /home/huyaonan/torch-project/torch-android/build/TryRunResults.cmake
-- Performing Test BLAS_F2C_FLOAT_WORKS - Failed
-- Found a library with BLAS API (open).
-- Looking for cheev_
-- Looking for cheev_ - not found
-- It seems OpenBlas has not been compiled with Lapack support
-- Cannot find a library with LAPACK API. Not using LAPACK.

So, did the complie fail eventually?

@buffer51
Copy link
Owner

buffer51 commented Feb 27, 2017

Hi @huyn,

I think you only built libs. You should build netlib as well.
In summary:

  • Use the toolchain from releases
  • Make it a standalone toolchain
  • Export it in your path:
    export PATH=$PATH:/path/to/standalone-toolchain/bin
  • Build OpenBLAS
    make TARGET=ARMV8 BINARY=64 HOSTCC=gcc CC=aarch64-linux-android-gcc FC=aarch64-linux-android-gfortran USE_THREAD=1 USE_OPENMP=1 USE_LAPACK=1 libs netlib
  • Install it
    make PREFIX=/home/huyaonan/torch-project/torch-android/install install

You should then have LAPACK as well (I've confirmed on my machine that cheev_ is present).

@huyn
Copy link
Author

huyn commented Feb 28, 2017

Hi @buffer51 , glad to receive your reply.
I did every step according to your reply include making a standalone toolchain like creating_the_toolchain.
Lib(libopenblas.a, libopenblas_armv8p-r0.2.20.dev.a) and other head files had been generated successfully. But LAPACK API could not be detected as before.
Actually what I am doing now is building torch-android with OpenBLAS and LAPACK. I don't know whether you have some experience on it. This is my build.sh, I have no idea what is going wrong. Thank you for your help.

#!/bin/bash
# have ndk-build in your $PATH and the script figures out where your ANDROID_NDK is at.

# optionally, modify the variables below as needed.
NDKABI=21

# Default architecture is V8
ARCH=${ARCH:-"v8"}

# Default is to build with CUDA.
# Make sure you installed https://developer.nvidia.com/codeworks-android.
# Otherwise, set WITH_CUDA to OFF.
WITH_CUDA=${WITH_CUDA:-"OFF"}

if [[ "$ARCH" == "v8" ]]; then
    APP_ABI=arm64-v8a
    M_ARCH=-march=armv8-a
    ABI_NAME=aarch64-linux-androideabi
    COMPUTE_NAME="Maxwell+Tegra"
elif [[ "$ARCH" == "v7n" ]]; then
    APP_ABI="armeabi-v7a with NEON"
    M_ARCH="-march=armv7-a"
    ABI_NAME=armv7-linux-androideabi
    COMPUTE_NAME="Kepler+Tegra Maxwell+Tegra"
    LOCAL_ARM_NEON=true
    ARCH_ARM_HAVE_NEON=true
else
    echo "Unsupported Architecture: $ARCH"
    exit 1
fi

NVCC=`which nvcc`
export MAKE=make
export MAKEARGS=-j$(getconf _NPROCESSORS_ONLN)

####################################################
# You do not need to modify anything below this line
####################################################
# find system torch, if not found, install it
command -v th >/dev/null 2>&1
TORCHINSTALLCHECK=$?
if [ $TORCHINSTALLCHECK -ne 0 ]; then
    echo "Torch-7 not found on system. Please install it using instructions from http://torch.ch"
    exit -1
fi
# have ndk-build in your PATH and the script figures out where your ANDROID_NDK is at
unamestr=`uname`
ndkbuildloc=`which ndk-build`
if [[ "$?" == 1 ]]; then
    echo "Error: Cannot find ndk-build in PATH. Please add it to PATH environment variable"
    exit 1
fi
if [[ "$unamestr" == 'Linux' ]]; then
    export ANDROID_NDK=`readlink -f $ndkbuildloc|sed 's/ndk-exec.sh//'|sed 's/ndk-build//'`
elif [[ "$unamestr" == 'Darwin' ]]; then
    which greadlink >/dev/null 2>&1
    if [[ "$?" == 1 ]]; then
	brew install coreutils
    fi
    export ANDROID_NDK=`greadlink -f $ndkbuildloc|sed 's/ndk-exec.sh//'|sed 's/ndk-build//'`
fi
echo "Android NDK found at: $ANDROID_NDK"
cd "$(dirname "$0")" # switch to script directory
SCRIPT_ROOT_DIR=`pwd`
export INSTALL_DIR=$SCRIPT_ROOT_DIR/install
mkdir -p ${INSTALL_DIR}/man

echo "INSTALL_DIR=${INSTALL_DIR}"
set +e # hard errors
export CMAKE_INSTALL_SUBDIR="share/cmake/torch"
NDK=$ANDROID_NDK
TOOLCHAIN_VERSION=4.9

if [[ "$ARCH" == "v8" ]]; then
NDK_SYSROOT=$NDK/platforms/android-$NDKABI/arch-arm64
export HOST=aarch64-linux-android
HOST_CC="gcc"
else
export HOST=arm-linux-androideabi
NDK_SYSROOT=$NDK/platforms/android-$NDKABI/arch-arm
ANDROID_CFLAGS="-mfloat-abi=softfp  -fprefetch-loop-arrays"
HOST_CC="gcc -m32"
fi

ANDROID_CFLAGS="${M_ARCH} --sysroot ${NDK_SYSROOT} ${ANDROID_CFLAGS}"

if [[ "$unamestr" == 'Linux' ]]; then
    BUILD_PLATFORM=linux-x86_64
elif [[ "$unamestr" == 'Darwin' ]]; then
    BUILD_PLATFORM=darwin-x86_64
fi

export TOOLCHAIN="$NDK/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}"

export TORCH_CUDA_ARCH_LIST="${COMPUTE_NAME}"
#-DANDROID_STANDALONE_TOOLCHAIN="${SCRIPT_ROOT_DIR}/standalone-toochains" \
do_cmake_config() {
cmake $1 -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_TOOLCHAIN_FILE="$SCRIPT_ROOT_DIR/cmake/android.toolchain.cmake" \
    -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="${APP_ABI}" \
    -DWITH_CUDA=${WITH_CUDA} -DWITH_LUAROCKS=OFF -DWITH_LUAJIT21=ON\
    -DCUDA_USE_STATIC_CUDA_RUNTIME=OFF -DANDROID_STL_FORCE_FEATURES=OFF\
    -DANDROID_NATIVE_API_LEVEL="${NDKABI}" -DANDROID_STL=gnustl_shared\
    -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DCMAKE_INSTALL_SUBDIR="${CMAKE_INSTALL_SUBDIR}" \
    -DLIBRARY_OUTPUT_PATH_ROOT="${INSTALL_DIR}" \
    -DLUAJIT_SYSTEM_MINILUA="$SCRIPT_ROOT_DIR/distro/exe/luajit-rocks/luajit-2.1/src/host/minilua" \
    -DLUAJIT_SYSTEM_BUILDVM="$SCRIPT_ROOT_DIR/distro/exe/luajit-rocks/luajit-2.1/src/host/buildvm" \
    -DCMAKE_C_FLAGS="-DDISABLE_POSIX_MEMALIGN"
echo " -------------- Configuring DONE ---------------"
}


if [[ "$WITH_CUDA" == "ON" ]]; then
    echo "Found CUDA on your machine. Installing CMake 3.6 modules to get up-to-date FindCUDA"
    cd ${SCRIPT_ROOT_DIR}/distro/cmake/3.6 && \
(cmake -E make_directory build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
        && make install) && echo "FindCuda bits of CMake 3.6 installed" || exit 1
fi

cd $SCRIPT_ROOT_DIR

cd external/libpng && \
    (cmake -E make_directory build && cd build && do_cmake_config .. && make install) \
    && echo "libpng installed" || exit 1
cd $SCRIPT_ROOT_DIR

#cd external/libjpeg-turbo && \
#    (cmake -E make_directory build && cd build && . ../../build-libjpeg.sh) \
#    && echo "libjpeg installed" || exit 1
#cd $SCRIPT_ROOT_DIR

# Build host luajit for minilua and buildvm
cd distro/exe/luajit-rocks/luajit-2.1

# make clean
$MAKE $MAKEARGS HOST_CC="$HOST_CC" CC="gcc" HOST_SYS=$unamestr TARGET_SYS=Linux CROSS="${TOOLCHAIN}/bin/${HOST}-" TARGET_FLAGS="$ANDROID_CFLAGS"

echo "Done installing Lua"

if [[ "$ARCH" == "v8" ]]; then
	cd $SCRIPT_ROOT_DIR
	(cmake -E make_directory build && cd build && do_cmake_config ..) || exit 1

	echo "Start to compile OpenBLAS"
	cd external/OpenBLAS

	NDK_ROOT=$ANDROID_NDK
	echo "NDK_ROOT=$NDK_ROOT, APP_ABI=$APP_ABI"
	PATHI=$PATH
	target="ARMV8 BINARY=64"
	CC="aarch64-linux-android-gcc FC=aarch64-linux-android-gfortran" 

	export PATH=${PATHI}:/home/huyaonan/arm64-toolchain/bin
	command="make TARGET=${target} HOSTCC=gcc CC=${CC} USE_THREAD=1 USE_OPENMP=1 USE_LAPACK=1 libs netlib"

	echo $command
	$command
	    
	command="make PREFIX=${INSTALL_DIR} install"
	$command

	echo "End compile OpenBLAS"
fi

cd $SCRIPT_ROOT_DIR
(cmake -E make_directory build && cd build && do_cmake_config ..) || exit 1

cd build

(cd distro/exe && $MAKE $MAKEARGS install) || exit 1
# cwrap needs to be there first
(cd distro/pkg/cwrap && $MAKE $MAKEARGS install) || exit 1
(cd distro/pkg && $MAKE $MAKEARGS install) || exit 1

# Cutorch installs some headers/libs used by other modules in extra
if [[ "$WITH_CUDA" == "ON" ]]; then
    (cd distro/extra/cutorch && $MAKE $MAKEARGS install) || exit 1
fi

(cd distro/extra && $MAKE  $MAKEARGS install) || exit 1
(cd src && $MAKE $MAKEARGS install) || exit 1

cd ..

echo "done"

@buffer51
Copy link
Owner

The build commands seem fine. Can I try it from your fork of torch-android? I want to see what it produces, and how LAPACK is detected (or not).

@huyn
Copy link
Author

huyn commented Feb 28, 2017

@buffer51 you can use it , but you need to clone OpenBLAS under dir external and replace build.sh with content in my last comment. Thank you.

@buffer51
Copy link
Owner

@huyn I just tried it and it worked wonderfully. I'm not sure what could have happened, did you try cleaning everything and rebuilding from scratch?

After that, if it still fails, check for the outputted install/libopenblas.a. If it's there, run nm libopenblas.a | grep cheev_, which should mimic checking for LAPACK by the existance of that routine.

In my case, I get:

0000000000000000 T cheev_
                 U cheev_
cheev_2stage.o:
0000000000000000 T cheev_2stage_
                 U cheev_2stage_
                 U LAPACKE_cheev_work
lapacke_cheev_work.o:
                 U cheev_
0000000000000000 T LAPACKE_cheev_work
lapacke_cheev_2stage.o:
0000000000000000 T LAPACKE_cheev_2stage
                 U LAPACKE_cheev_2stage_work
lapacke_cheev_2stage_work.o:
                 U cheev_2stage_
0000000000000000 T LAPACKE_cheev_2stage_work

@buffer51
Copy link
Owner

Also, I've confirmed that the generated luajit works on my Nexus 5X. Basic operations worked, although I couldn't require Torch since I only put the executable and not the libraries that go along.

@huyn
Copy link
Author

huyn commented Mar 1, 2017

Hi @buffer51 Thank you sincerly.
I start a new project and I have confirmed that libopenblas.a contians function cheev_.

huyaonan@ubuntu:~/torch-project/torch-fork/install/lib$ nm libopenblas.a | grep cheev_
0000000000000000 T cheev_
                 U cheev_
cheev_2stage.o:
0000000000000000 T cheev_2stage_
                 U cheev_2stage_
                 U LAPACKE_cheev_work
lapacke_cheev_work.o:
                 U cheev_
0000000000000000 T LAPACKE_cheev_work
lapacke_cheev_2stage.o:
0000000000000000 T LAPACKE_cheev_2stage
                 U LAPACKE_cheev_2stage_work
lapacke_cheev_2stage_work.o:
                 U cheev_2stage_
0000000000000000 T LAPACKE_cheev_2stage_work

But I find that check_function_exists("cheev_" OPEN_LAPACK_WORKS) may not work even though BLAS_LIBRARIES has been set as /home/huyaonan/torch-project/torch-fork/install/lib/libopenblas.a in FindLAPACK.cmake under dir /distro/pkg/torch/lib/TH/cmake. Maybe there is something wrong with libopenblas.a which makes cmake link unsuccessful.

@buffer51
Copy link
Owner

buffer51 commented Mar 1, 2017

And when does the error occur? For me, the build process finished successfully. Is there another step you take after that, which is the one that fails?

@huyn
Copy link
Author

huyn commented Mar 1, 2017

Hi @buffer51.
The build did finish successfully for me too and I can use the libs on my aarch64 devices. The point is LAPACK api is not found in libopenblas.a, the libs generated later would not contain LAPACK capacity because it would be ignored during next steps.

@buffer51
Copy link
Owner

buffer51 commented Mar 1, 2017

@huyn I was able to find the part you mentionned (cheev_ not found). The error log build/CMakeFiles/CMakeError.log reads:

Determining if the function cheev_ exists failed with the following output:
Change Dir: /home/paul/code/openblas/torch-android/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_61c3c/fast"
make -f CMakeFiles/cmTC_61c3c.dir/build.make CMakeFiles/cmTC_61c3c.dir/build
make[1] : on entre dans le répertoire « /home/paul/code/openblas/torch-android/build/CMakeFiles/CMakeTmp »
Building C object CMakeFiles/cmTC_61c3c.dir/CheckFunctionExists.c.o
/home/paul/code/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc  -DANDROID -isystem /home/paul/code/android-ndk-r13b/platforms/android-21/arch-arm64/usr/include -isystem /home/paul/code/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/paul/code/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/include -isystem /home/paul/code/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward  -Wno-psabi --sysroot=/home/paul/code/android-ndk-r13b/platforms/android-21/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack -DDISABLE_POSIX_MEMALIGN -Werror=implicit-function-declaration -Werror=format -fopenmp -fopenmp -DCHECK_FUNCTION_EXISTS=cheev_ -fPIE   -o CMakeFiles/cmTC_61c3c.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.5/Modules/CheckFunctionExists.c
Linking C executable cmTC_61c3c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_61c3c.dir/link.txt --verbose=1
/home/paul/code/android-ndk-r13b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc  -Wno-psabi --sysroot=/home/paul/code/android-ndk-r13b/platforms/android-21/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack -DDISABLE_POSIX_MEMALIGN -Werror=implicit-function-declaration -Werror=format -fopenmp -fopenmp -DCHECK_FUNCTION_EXISTS=cheev_   -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,-z,nocopyreloc -fPIE -pie  CMakeFiles/cmTC_61c3c.dir/CheckFunctionExists.c.o -o cmTC_61c3c  -L/libs/arm64-v8a  /home/paul/code/openblas/torch-android/install/lib/libopenblas.a  "/home/paul/code/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libsupc++.a"
/home/paul/code/openblas/torch-android/install/lib/libopenblas.a(cheev.o): In function `cheev_':
cheev.f:(.text+0x470): undefined reference to `sqrtf'
cheev.f:(.text+0x480): undefined reference to `sqrtf'

and some more... I'll try to investigate.

@buffer51
Copy link
Owner

buffer51 commented Mar 1, 2017

So the issue I've found is that the linking step misses -lgfortran and -lm. I've checked cmake/android.toolchain.cmake, and for some reason -lm is only added to C++ linking steps.

Replacing the section around line 1292 by the following fixes it for me.

 if( ANDROID_STL MATCHES "gnustl" )
  if( NOT EXISTS "${ANDROID_LIBM_PATH}" )
   set( ANDROID_LIBM_PATH -lm )
  endif()
  set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" )
  set( CMAKE_CXX_CREATE_SHARED_MODULE  "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" )
  set( CMAKE_CXX_LINK_EXECUTABLE       "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" )
  # C objects:
  set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" )
  set( CMAKE_C_CREATE_SHARED_MODULE  "${CMAKE_C_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" )
  set( CMAKE_C_LINK_EXECUTABLE       "${CMAKE_C_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" )
 endif()
endif()

# Add Fortran support
set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} -lgfortran" )
set( CMAKE_CXX_CREATE_SHARED_MODULE  "${CMAKE_CXX_CREATE_SHARED_MODULE} -lgfortran" )
set( CMAKE_CXX_LINK_EXECUTABLE       "${CMAKE_CXX_LINK_EXECUTABLE} -lgfortran" )
# C objects:
set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} -lgfortran" )
set( CMAKE_C_CREATE_SHARED_MODULE  "${CMAKE_C_CREATE_SHARED_MODULE} -lgfortran" )
set( CMAKE_C_LINK_EXECUTABLE       "${CMAKE_C_LINK_EXECUTABLE} -lgfortran" )

(This might not be the clean way to add them though.)

@huyn
Copy link
Author

huyn commented Mar 2, 2017

Hi @buffer51. It works. Thank you for your help and I appreciate it very much 👍
Wish you a good day :)

@huyn huyn closed this as completed Mar 2, 2017
@buffer51
Copy link
Owner

buffer51 commented Mar 2, 2017 via email

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

No branches or pull requests

2 participants