[SOLVED] Android_rpc_test.py failed


#1

When setting
export TVM_NDK_CC=/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-g++
There is an error.

    Traceback (most recent call last):
      File "android_rpc_test.py", line 112, in <module>
        test_rpc_module()
      File "android_rpc_test.py", line 50, in test_rpc_module
        f.export_library(path_dso_cpu, ndk.create_shared)
      File "/Users/hanqiu/Desktop/tvm/python/tvm/module.py", line 121, in export_library
        fcompile(file_name, files, **kwargs)
      File "/Users/hanqiu/Desktop/tvm/python/tvm/contrib/ndk.py", line 49, in create_shared
        raise RuntimeError(msg)
    RuntimeError: Compilation error:
    /Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-g++: line 2: /Users/hanqiu/Desktop/android-toolchain-arm64/bin/../../../../llvm/prebuilt/darwin-x86_64/bin/clang++: No such file or directory
    /Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-g++: line 2: exec: /Users/hanqiu/Desktop/android-toolchain-arm64/bin/../../../../llvm/prebuilt/darwin-x86_64/bin/clang++: cannot execute: No such file or directory

if set
export TVM_NDK_CC=/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-ld

It works fine.
I’m using macOS 10.13.6


#2

Thanks for providing a solution. Can you list the contents of the directory you used instead?

If this is the correct path for macOS systems we should add it to the Android docs.


#3

Do you mean the toolchain content?
It’s generated by using

./make-standalone-toolchain.sh --platform=android-24 --use-llvm --arch=arm64 --install-dir=/Users/hanqiu/Desktop/android-toolchain-arm64

and the content of /Users/hanqiu/Desktop/android-toolchain-arm64 is

AndroidVersion.txt	aarch64-linux-android	lib64			share
MODULE_LICENSE_BSD_LIKE	bin			libexec			sysroot
MODULE_LICENSE_MIT	include			manifest_4751641.xml
NOTICE			lib			repo.prop

Content of bin

2to3				bisect_driver.py		llvm-strip
aarch64-linux-android-addr2line	clang				llvm-symbolizer
aarch64-linux-android-ar	clang++				make
aarch64-linux-android-as	clang-format			ndk-depends
aarch64-linux-android-c++filt	clang-tidy			ndk-gdb
aarch64-linux-android-clang	clang-tidy.real			ndk-gdb.py
aarch64-linux-android-clang++	clang70				ndk-stack
aarch64-linux-android-dwp	clang70++			ndk-which
aarch64-linux-android-elfedit	gdb				pydoc
aarch64-linux-android-g++	gdb-orig			python
aarch64-linux-android-gcc	git-clang-format		python-config
aarch64-linux-android-gprof	idle				python-config.sh
aarch64-linux-android-ld	ld.lld				python2
aarch64-linux-android-ld.bfd	llvm-ar				python2-config
aarch64-linux-android-ld.gold	llvm-as				python2.7
aarch64-linux-android-nm	llvm-cov			python2.7-config
aarch64-linux-android-objcopy	llvm-dis			sancov
aarch64-linux-android-objdump	llvm-link			sanstats
aarch64-linux-android-ranlib	llvm-modextract			scan-build
aarch64-linux-android-readelf	llvm-nm				scan-view
aarch64-linux-android-size	llvm-objcopy			smtpd.py
aarch64-linux-android-strings	llvm-profdata			yasm
aarch64-linux-android-strip	llvm-readobj

I only changed
export TVM_NDK_CC=/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-g++
to
export TVM_NDK_CC=/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-ld.
(only changed the postfix)Anything else I follows the READMD.


(JUST IGNORE THE FOLLOWING)-----------------------------------------------------------------

BTW:
It seems that aarch64-linux-android-g++ wants something like this:

toolchain:
    llvm/prebuilt/darwin-x86_64/bin/clang++
    aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-g++

I found this in /usr/local/Caskroom/android-ndk/18/android-ndk-r18/toolchains
But setting to path to this toolchain still doesn’t work.
There is a error:

python android_rpc_test.py 
Traceback (most recent call last):
  File "android_rpc_test.py", line 112, in <module>
    test_rpc_module()
  File "android_rpc_test.py", line 50, in test_rpc_module
    f.export_library(path_dso_cpu, ndk.create_shared)
  File "/Users/hanqiu/Desktop/tvm/python/tvm/module.py", line 121, in export_library
    fcompile(file_name, files, **kwargs)
  File "/Users/hanqiu/Desktop/tvm/python/tvm/contrib/ndk.py", line 49, in create_shared
    raise RuntimeError(msg)
RuntimeError: Compilation error:
ld: unknown option: --fix-cortex-a53-843419

#4

I am confused here, the original error seems to be complaining that it cannot find clang, which should not be used to build the standalone android executable. Then your fix suppresses this error, which suggests that somehow it manages to now find clang. The new error message suggests makes sense if we assume that clang is now being called and cannot recognize the new command line option (which is an ARM64 A-53 specific errata fix). Can you check which target you are compiling for?

Another sanity check is to see what compiler path in the environment is seen by the ndk script


#5

Sorry about the confusion.
You can just ignore my second BTW part…
(I didn’t know that the clang++ shouldn’t be used. And I happened to find a place where there is a clang++.
But it still didn’t work. The target is a android cellphone with ARM64 A-73/A-53 )

Changing g++ to ld just works fine on my computer.


#6

Can you check what compilation command is actually emitted by ndk.py in this case?


#7

When the compiler path/(TVM_NDK_CC environment variable) is
/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-ld
It works fine
When it’s
/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-g++
There is the error
/Users/hanqiu/Desktop/android-toolchain-arm64/bin/../../../../llvm/prebuilt/darwin-x86_64/bin/clang++: cannot execute: No such file or directory


#8

By works fine, do you mean you are able to run the test?


#9

Yes, output:

Run CPU test ...
2.23437e-05 secs/op

#10

Sorry, It seems that it doesn’t work for the opencl.
The generated command is

['/Users/hanqiu/Desktop/android-toolchain-arm64/bin/aarch64-linux-android-ld', '-o', '/var/folders/66/hxz4h1b578334flx18703rd80000gn/T/tmpwicq8juw/dev_lib_cl.so', '/var/folders/66/hxz4h1b578334flx18703rd80000gn/T/tmp17p3frae/lib.o', '/var/folders/66/hxz4h1b578334flx18703rd80000gn/T/tmp17p3frae/devc.cc', '-shared', '-fPIC']

error is
/var/folders/66/hxz4h1b578334flx18703rd80000gn/T/tmp17p3frae/devc.cc: file not recognized: File format not recognized
And if using g++ instead of ld. It’s still the same error(can’t find clang++) that I stated previously.