-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 document in English #5029
Conversation
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.
Thanks for your good translation. The English version seems much concise than the Chinese version. Maybe I need to refine and simplify the Chinese document.
There are two approaches to build PaddlePaddle for Android: | ||
|
||
1. Use a Docker container, or | ||
2. cross-compiling on Linux. |
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.
In the Chinese version, the two items are the same as the two sub-titles. Do we need to keep the same here?
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.
Got it. Done
|
||
The ARM-64 architecture (`arm64-v8a`) requires at least level 21 of Android API. | ||
|
||
The default entry-point of the Docker image,[`paddle/scripts/docker/build_android.sh`](/~https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh) generates the [Android cross-compiling standalone toolchain](https://developer.android.com/ndk/guides/standalone_toolchain.html) according to the value of `ANDROID_ABI` and `ANDROID_API`. For information about other configuration parameters, please go on reading. |
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.
Need a space before [paddle/scripts/docker/build_android.sh]
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.
Done
|
||
### Setup the Environment | ||
|
||
To install Android's C/C++ cross-compiling standalone toolchain, we need [Android NDK](https://developer.android.com/ndk/downloads/index.html?hl=zh-cn): |
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.
https://developer.android.com/ndk/downloads/index.html?hl=zh-cn
-> https://developer.android.com/ndk/downloads/index.html
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.
Done
unzip -q android-ndk-r14b-linux-x86_64.zip | ||
``` | ||
|
||
Android NDK includes everything we need to build the cross-compiling toolchain. |
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.
In fact, some codes can directly use Android NDK
to cross-compile, no need to generate the standalone toolchain
. But for Paddle, some external libraries failed in my previous try. So standalone toolchain
is needed for the current version, and I will fix the problem in the future. So I'd like to say:
Android NDK includes everything to cross-compile for Android, but standalone toolchain is needed for PaddlePaddle.
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.
OK
|
||
Android NDK includes everything we need to build the cross-compiling toolchain. | ||
|
||
- To build the toolchain for `armeabi-v7a` and Android API level 21: |
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.
Android NDK
is the toolchain, so I think it is better to use To build the standalone toolchain
here.
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.
Got it. Done.
|
||
### Cross-Compiling Arguments | ||
|
||
CMake supports to [choose the toolchain](https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling). PaddlePaddle provides [`android.cmake`](/~https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake), which configures the Android cross-compiling toolchain for CMake. `android.cmake` is not required for CMake >= 3.7, which starts supporting Android cross-compiling. 。PaddlePaddle detects CMake version, for those newer than 3.7, it uses [the official version](https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling). |
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 am a little confused about the meaning of choose the toolchain
. I'd like to change it to CMake supports to cross-compile
.
There is a extra 。
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.
Done.
|
||
CMake supports to [choose the toolchain](https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling). PaddlePaddle provides [`android.cmake`](/~https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake), which configures the Android cross-compiling toolchain for CMake. `android.cmake` is not required for CMake >= 3.7, which starts supporting Android cross-compiling. 。PaddlePaddle detects CMake version, for those newer than 3.7, it uses [the official version](https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling). | ||
|
||
Some other CMake parameters you might want to know: |
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.
parameters -> arguments?
Some other CMake parameters you might want to know -> Some CMake arguments you have to know
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.
Done
|
||
Some other CMake parameters you might want to know: | ||
|
||
- `CMAKE_SYSTEM_NAME` must be `Android`. This tells PaddlePaddle's CMake system to cross-compile dependencies including protobuf library and the protoc executable, and ARM-enabled OpenBLAS. This also changes some other CMake parameters like `WITH_GPU=OFF`, `WITH_AVX=OFF`, `WITH_PYTHON=OFF`, and `WITH_RDMA=OFF`. |
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.
protobuf library and the protoc executable, and ARM-enabled OpenBLAS
, maybe detail is not needed here. Most people don't need to know the compiling process.
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.
Done
|
||
### Build and Install | ||
|
||
After running `cmake`, we can run `make install` to build and install. |
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.
make install
-> make; make install
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.
Done. But usually, projects can be built using a single command make install
.
|
||
After running `cmake`, we can run `make install` to build and install. | ||
|
||
Before building, you might want to remove the `third_party` and `build` directories including pre-built libraries for other ARM architectures. |
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.
for other ARM architectures -> for other architectures
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.
Done
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.
Thanks so much for doing this. I have added a bunch of Nits.
|
||
### Build the Docker Image | ||
|
||
The following steps pack tools we need to build PaddlePaddle into a Docker image. |
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.
Rephrase: The following steps pack all the tools that we need to build PaddlePaddle, into a Docker image.
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.
Done
|
||
### Build the Inference Library | ||
|
||
We can run this Docker image to build PaddlePaddle's inference library for 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.
Rephrase: We can run the Docker image we just created to build the inference library for PaddlePaddle for Android using the command below:
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.
Done
|
||
The ARM-64 architecture (`arm64-v8a`) requires at least level 21 of Android API. | ||
|
||
The default entry-point of the Docker image,[`paddle/scripts/docker/build_android.sh`](/~https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh) generates the [Android cross-compiling standalone toolchain](https://developer.android.com/ndk/guides/standalone_toolchain.html) according to the value of `ANDROID_ABI` and `ANDROID_API`. For information about other configuration parameters, please go on reading. |
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.
Rephrase : The default entry-point of the Docker image paddle/scripts/docker/build_android.sh
generates the Android cross-compiling standalone toolchain based on the argument : ANDROID_ABI
or ANDROID_API
. For more information about other configuration parameters, please continue reading.
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.
Done
|
||
The default entry-point of the Docker image,[`paddle/scripts/docker/build_android.sh`](/~https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh) generates the [Android cross-compiling standalone toolchain](https://developer.android.com/ndk/guides/standalone_toolchain.html) according to the value of `ANDROID_ABI` and `ANDROID_API`. For information about other configuration parameters, please go on reading. | ||
|
||
Above command line generates and outputs the inference library in `$PWD/install_android` and puts third-party libraries in `$PWD/install_android/third_party`. |
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.
Rephrase: The above command generates and outputs the inference library in $PWD/install_android
and puts third-party libraries in $PWD/install_android/third_party
.
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.
Done
|
||
## Linux-based Cross-Compiling | ||
|
||
The Linux-base approach is to run steps in `Dockerfile.android` manually on a Linux x64 computer. |
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.
Rephrase: The Linux-based approach to cross-compile is to run steps in Dockerfile.android
manually on a Linux x64 computer.
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.
Done
|
||
### Cross-Compiling Arguments | ||
|
||
CMake supports to [choose the toolchain](https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling). PaddlePaddle provides [`android.cmake`](/~https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake), which configures the Android cross-compiling toolchain for CMake. `android.cmake` is not required for CMake >= 3.7, which starts supporting Android cross-compiling. 。PaddlePaddle detects CMake version, for those newer than 3.7, it uses [the official version](https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling). |
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.
Rephrase: CMake supports choosing the toolchain. PaddlePaddle provides android.cmake
, which configures the Android cross-compiling toolchain for CMake. android.cmake
is not required for CMake versions >= 3.7, which support Android cross-compiling. PaddlePaddle detects the CMake version, for those newer than 3.7, it uses the official version.
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.
Done
|
||
Some Android-specific parameters: | ||
|
||
- `ANDROID_STANDALONE_TOOLCHAIN` the absolute path of the Android standalone toolchain, or the path relative to the CMake build directory. PaddlePaddle's CMake extensions would derive the cross-compiler, sysroot and Android API level from this parameter. |
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.
ANDROID_STANDALONE_TOOLCHAIN
=> ANDROID_STANDALONE_TOOLCHAIN
:
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.
Done
|
||
Other useful parameters: | ||
|
||
- `USE_EIGEN_FOR_BLAS` indicates if using Eigen. Could be `ON` or `OFF`, defaults to `OFF`. |
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.
USE_EIGEN_FOR_BLAS
=> USE_EIGEN_FOR_BLAS
:
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.
Done
Other useful parameters: | ||
|
||
- `USE_EIGEN_FOR_BLAS` indicates if using Eigen. Could be `ON` or `OFF`, defaults to `OFF`. | ||
- `HOST_C/CXX_COMPILER` specifies the host compiler, which is used to build the host-specific protoc and target-specific OpenBLAS. It defaults to the value of the environment variable `CC`, or `cc`. |
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.
HOST_C/CXX_COMPILER
=> HOST_C/CXX_COMPILER
:
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.
Done
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.
LGTM. Thanks for updating.
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.
LGTM, except that we need to name the English documentation file to cross_compiling_for_android_en.md
. We will add the documentation to index.rst
, and it cannot be correctly generated if not with _cn
or _en
suffix.
I merge this PR and will give a PR to rename to file. |
No description provided.