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

Android build document in English #5029

Merged
merged 4 commits into from
Nov 3, 2017

Conversation

wangkuiyi
Copy link
Collaborator

No description provided.

Copy link
Contributor

@Xreki Xreki left a 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.
Copy link
Contributor

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?

Copy link
Collaborator Author

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.
Copy link
Contributor

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]

Copy link
Collaborator Author

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):
Copy link
Contributor

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

Copy link
Collaborator Author

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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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:
Copy link
Contributor

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.

Copy link
Collaborator Author

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).
Copy link
Contributor

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

Copy link
Collaborator Author

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:
Copy link
Contributor

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

Copy link
Collaborator Author

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`.
Copy link
Contributor

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.

Copy link
Collaborator Author

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.
Copy link
Contributor

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

Copy link
Collaborator Author

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.
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@kavyasrinet kavyasrinet left a 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.

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.

Copy link
Collaborator Author

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:

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:

Copy link
Collaborator Author

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.

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.

Copy link
Collaborator Author

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`.

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.

Copy link
Collaborator Author

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.

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.

Copy link
Collaborator Author

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).

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.

Copy link
Collaborator Author

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.

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:

Copy link
Collaborator Author

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`.

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:

Copy link
Collaborator Author

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`.

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:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@kavyasrinet kavyasrinet left a 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.

Copy link
Contributor

@Xreki Xreki left a 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.

@Xreki Xreki added the Android label Oct 30, 2017
@Xreki Xreki added this to Design & Doc in Embedded and Mobile Deployment Oct 30, 2017
@Xreki
Copy link
Contributor

Xreki commented Nov 3, 2017

I merge this PR and will give a PR to rename to file.

@Xreki Xreki merged commit 1796a2a into PaddlePaddle:develop Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants