Android build document in English#5029
Conversation
Xreki
left a comment
There was a problem hiding this comment.
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.
In the Chinese version, the two items are the same as the two sub-titles. Do we need to keep the same here?
|
|
||
| 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.
Need a space before [paddle/scripts/docker/build_android.sh]
|
|
||
| ### 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.
https://developer.android.com/ndk/downloads/index.html?hl=zh-cn -> https://developer.android.com/ndk/downloads/index.html
| 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.
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.
|
|
||
| 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.
Android NDK is the toolchain, so I think it is better to use To build the standalone toolchain here.
|
|
||
| ### 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.
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 。
|
|
||
| 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.
parameters -> arguments?
Some other CMake parameters you might want to know -> Some CMake arguments you have to know
|
|
||
| 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.
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.
|
|
||
| ### Build and Install | ||
|
|
||
| After running `cmake`, we can run `make install` to build and install. |
There was a problem hiding this comment.
make install -> make; make install
There was a problem hiding this comment.
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.
for other ARM architectures -> for other architectures
kavyasrinet
left a comment
There was a problem hiding this comment.
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.
Rephrase: The following steps pack all the tools that we need to build PaddlePaddle, into a Docker image.
|
|
||
| ### 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.
Rephrase: We can run the Docker image we just created to build the inference library for PaddlePaddle for Android using the command below:
|
|
||
| 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.
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.
|
|
||
| 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.
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.
|
|
||
| ## 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.
Rephrase: The Linux-based approach to cross-compile is to run steps in Dockerfile.android manually on a Linux x64 computer.
|
|
||
| ### 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.
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.
|
|
||
| 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.
ANDROID_STANDALONE_TOOLCHAIN => ANDROID_STANDALONE_TOOLCHAIN:
|
|
||
| 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.
USE_EIGEN_FOR_BLAS => USE_EIGEN_FOR_BLAS:
| 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.
HOST_C/CXX_COMPILER => HOST_C/CXX_COMPILER:
|
I merge this PR and will give a PR to rename to file. |
No description provided.