-
Notifications
You must be signed in to change notification settings - Fork 535
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 build with Cross Compilation for BLAS and OpenCL back-ends #848
Conversation
I'm starting to look at this PR as a proof of concept. I realize the real solution here is to use static versions of the libraries and ultimately to create a statically-linked executable, possibly with a separate meson file for cross-compiling with NDK. That's the only way if we want to distribute binaries. Some links: http://dev-smart.com/cross-compiling-with-android/ OpenBLAS for Androidhttps://github.com/xianyi/OpenBLAS/wiki/How-to-build-OpenBLAS-for-Android OpenCL for Mali & Adrenohttps://arrayfire.com/getting-started-with-opencl-on-android/ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Back to the real problem. I made some good progress today, achieving a successful cross-compilation with meson from my Linux workstation. For now the build was carried out without the back-ends. The final executable was created with its proper architecture. The cross compilation file,
the commands:
|
If the Tensorflow backend was brought up to date, would that mean that we could use the NN accelerators on modern Android devices? |
Mobile devices use tensorflow-lite, not tensorflow. I think it's totally incompatible API-wise, but still pretty easy to write a backend for tensorflow-lite.. |
For now the GNU's toolchain is able to build the project without the back-ends, but the resulting executable is for a generic linux system (different linker, libs, etc.) . I'd prefer to use the NDK toolchain as it produces binaries for an Android platform. So I'm trying really hard to make the cross-compilation work with the NDK toolchain @borg323 was helping me fix a problem with exe_wrapper in the meson cross-file. Apparently the protobuf build could not continue without an exe_wrapper. It seemed strange to me. Then I stumbled upon this: From https://mesonbuild.com/Cross-compilation.html
Now the previous meson error seems clearer:
Meson has no protoc to call, only its source. Now I just need to tell it to use the local protoc. Right? |
Cross compilation finally achieved with the NDK toolchain! After a real struggle and some magic tricks from @borg323 we could make protobuf pass the build. Here's the output of the first cross-compiled binary running on my phone through adb:
The random back-end is blazing fast! :D Here's the meson cross-file:
Now the proper back-ends need to be tackled. Expect a good fight! |
Guys, @borg323 is making this look easy. Now his new branch opencl_sub, passed the cross-compilation on my android gnu toolchain. This means that apparently we've got the first back-end working on ARM! Look at this:
Now I just gotta massage the NDK toolchain so that it follows suit... Some notes:
|
Lc0 cross-built for android with NDK, opencl loader statically linked. adb output:
Now, on to investigate why opencl is not being detected... https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_ICD_Installation.html#_android_sdkndk |
dynamically linked opencl on android:
|
Now we've got a beautiful 8 MB binary engine that should work with regular Android chess GUIs! With OpenCL back-end. This is bliss!!! |
Attached meson detection when cross compiling |
Some comments about the most recent commit:
opencl meson.zip
|
meson_options.txt
Outdated
@@ -118,11 +118,6 @@ option('pext', | |||
value: false, | |||
description: 'Use the pext instruction') | |||
|
|||
option('android', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed as one can detect android on meson cross build with host_machine.system() == 'android'
meson_options.txt
Outdated
@@ -15,7 +15,7 @@ option('openblas_include', | |||
|
|||
option('opencl_include', | |||
type: 'array', | |||
value: ['/usr/include/'], | |||
# value: ['/usr/include/'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to comment this path as it seems to confuse the Android NDK, it mixes the headers and fail compilation. The GNU toolchain doesn't have that problem. Any idea on how to solve this?
This comment has been minimized.
This comment has been minimized.
lealgo sir you can make a small movie for see how install weithgs good my phone is a huawei p smart but doesnt work lc0 help me please , thansa for your time :) regards |
Not working on my side (Xiaomi Mi 6, Android 9, opencl 2.0, Snapdragon 835). |
This comment has been minimized.
This comment has been minimized.
Works perfectly on my one plus 6 (Snapdragon 845). With a recent T40 network:
|
Hi, I compared openblas with opencl engines on samsungS8+. I set the uci depth to 2 moves. Openblas needeed 10 seconds against 7 for opencl. I am quite deceived by opencl. It need 3 minutes to start and then it is just a bit quicker than blas. The engine is stronger than stockfish for a given depth but because it is slow stockfish beats it because it can go deeper thanks to its fast evaluation speed. I thank you a lot to allow me to play chess against an IA. It is more human like. Better evaluation of position and less depth in move calculation. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
New builds for 0.22 release:
lc0-0.22-eigen-aarch64.zip with Little Demon 2 embedded:
lc0-0.22-eigen-armv7a.zip with Little Demon 2 embedded: |
This comment has been minimized.
This comment has been minimized.
Hey there lealgo! Great to see that you're still active and working on this
project.
…On Fri, 22 Nov 2019, 10:31 Leandro Álvarez González, < ***@***.***> wrote:
New builds for 0.23-rc1:
-
aarch64 build for Android 5.0 and up:
lc0-eigen-opencl-aarch64.zip
<https://github.com/LeelaChessZero/lc0/files/3878016/lc0-eigen-opencl-aarch64.zip>
-
armv7a build for Android 4.1 and up:
lc0-eigen-opencl-armv7a.zip
<https://github.com/LeelaChessZero/lc0/files/3878018/lc0-eigen-opencl-armv7a.zip>
Notice they differ from previous builds in that they now have both the
EIgen and OpenCL back-ends compiled into the same binary, defaulting to the
Eigen one.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#848?email_source=notifications&email_token=AI4GAHTM7GB6K4ALP6AOMUDQU5RRDA5CNFSM4HMCTILKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE4RQUQ#issuecomment-557389906>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI4GAHUT7U4U4BC36ANGMDTQU5RRDANCNFSM4HMCTILA>
.
|
Hi, @UA2425 Thanks. Best regards, |
Builds for the new release 0.23: aarch64 for Android 5.0 and up: armv7a for Android 4.1 and up: |
After the change to There's an (old) issue though when targeting https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md Previously I was using an older NDK as a workaround, but such toolchains don't support TLDR From now on the |
Big news! First appveyor TEST build successful, by @borg323 : https://ci.appveyor.com/project/borg323/lc0/builds/30998575
Note a small linker warning on the first line, it's produced because of the fairly old NDK r17 toolchain. Newer NDK's produce clean binaries. |
The Android builds are official now, I think I can close this PR. Thank you. |
Test builds for comparing OpenBLAS 0.3.9 vs 0.3.8 |
Provides the files and tweaks to meson that enable the cross-compilation to Android, and also to other platforms like ARM Linux. This PR depends on the work done by @borg323's on the subprojects: protobuf and opencl, allowing the build to be performed from source instead of using the build machine's shared libraries.
You could test this PR as it is right now, but the file
subprojects/protobuf-3.5.1/meson.build
should be replaced with this one: meson.build . The problem with cross-compiling protobuf is better explained here: #848 (comment)Note: This PR started as a method for compiling lc0 on Termux, but then it evolved into cross-compilation. I kept the previous comments for reference. If you want instructions on Termux then follow the wiki