提交 49c12077 编写于 作者: T Travis CI

Deploy to GitHub Pages: 1796a2ab

上级 7ef764b3
# Build PaddlePaddle for Android
There are two approaches to build PaddlePaddle for Android: using Docker and on Linux without Docker.
## Cross-Compiling Using Docker
Docker-based cross-compiling is the recommended approach because Docker runs on all major operating systems, including Linux, Mac OS X, and Windows.
### Build the Docker Image
The following steps pack all the tools that we need to build PaddlePaddle into a Docker image.
```bash
$ git clone https://github.com/PaddlePaddle/Paddle.git
$ cd Paddle
$ docker build -t paddle:dev-android . -f Dockerfile.android
```
### Build the Inference Library
We can run the Docker image we just created to build the inference library of PaddlePaddle for Android using the command below:
```bash
$ docker run -it --rm -v $PWD:/paddle -e "ANDROID_ABI=armeabi-v7a" -e "ANDROID_API=21" paddle:dev-android
```
The Docker image accepts two arguments `ANDROID_ABI` and `ANDROID_API`:
| Argument | Optional Values | Default |
|-----------------|-------------------------|---------|
|`ANDROID_ABI` |`armeabi-v7a, arm64-v8a` | `armeabi-v7a` |
|`ANDROID_API` |`>= 21` | `21` |
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) based on the argument: `ANDROID_ABI` or `ANDROID_API`. For information about other configuration arguments, please continue reading.
The above command generates and outputs the inference library in `$PWD/install_android` and puts third-party libraries in `$PWD/install_android/third_party`.
## Cross-Compiling on Linux
The Linux-base approach to cross-compile is to run steps in `Dockerfile.android` manually on a Linux x64 computer.
### Setup the Environment
To build for Android's, we need [Android NDK](
https://developer.android.com/ndk/downloads/index.html):
```bash
wget -q https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip
unzip -q android-ndk-r14b-linux-x86_64.zip
```
Android NDK includes everything we need to build the [*standalone toolchain*](https://developer.android.com/ndk/guides/standalone_toolchain.html), which in then used to build PaddlePaddle for Android. (We plan to remove the intermediate stage of building the standalone toolchain in the near future.)
- To build the standalone toolchain for `armeabi-v7a` and Android API level 21:
```bash
your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh \
--arch=arm --platform=android-21 --install-dir=your/path/to/arm_standalone_toolchain
```
The generated standalone toolchain will be in `your/path/to/arm_standalone_toolchain`.
- To build the standalone toolchain for `arm64-v8a` and Android API level 21:
```bash
your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh \
--arch=arm64 --platform=android-21 --install-dir=your/path/to/arm64_standalone_toolchain
```
The generated standalone toolchain will be in `your/path/to/arm64_standalone_toolchain`.
**Please be aware that the minimum level of Android API required by PaddlePaddle is 21.**
### Cross-Compiling Arguments
CMake supports [choosing 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 support Android cross-compiling. PaddlePaddle detects the 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 arguments you need to know:
- `CMAKE_SYSTEM_NAME` must be `Android`. This tells PaddlePaddle's CMake system to cross-compile third-party dependencies. This also changes some other CMake arguments like `WITH_GPU=OFF`, `WITH_AVX=OFF`, `WITH_PYTHON=OFF`, and `WITH_RDMA=OFF`.
- `WITH_C_API` must be `ON`, to build the C-based inference library for Android.
- `WITH_SWIG_PY` must be `OFF` because the Android platform doesn't support SWIG-based API.
Some Android-specific arguments:
- `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 argument.
- `ANDROID_TOOLCHAIN`: could be `gcc` or `clang`. The default value is `clang`.
- For CMake >= 3.7, it should anyway be `clang`. For older versions, it could be `gcc`.
- Android's official `clang` requires `glibc` >= 2.15.
- `ANDROID_ABI`: could be `armeabi-v7a` or `arm64-v8a`. The default value is `armeabi-v7a`.
- `ANDROID_NATIVE_API_LEVEL`: could be derived from the value of `ANDROID_STANDALONE_TOOLCHAIN`.
- `ANROID_ARM_MODE`:
- could be `ON` or `OFF`, and defaults to `ON`, when `ANDROID_ABI=armeabi-v7a`;
- no need to specify when `ANDROID_ABI=arm64-v8a`.
- `ANDROID_ARM_NEON`: indicates if to use NEON instructions.
- could be `ON` or `OFF`, and defaults to `ON`, when `ANDROID_ABI=armeabi-v7a`;
- no need to specify when `ANDROID_ABI=arm64-v8a`.
Other useful arguments:
- `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`.
Some frequent configurations for your reference:
```bash
cmake -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_STANDALONE_TOOLCHAIN=your/path/to/arm_standalone_toolchain \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_ARM_NEON=ON \
-DANDROID_ARM_MODE=ON \
-DUSE_EIGEN_FOR_BLAS=ON \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_SWIG_PY=OFF \
..
```
```
cmake -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_STANDALONE_TOOLCHAIN=your/path/to/arm64_standalone_toolchain \
-DANDROID_ABI=arm64-v8a \
-DUSE_EIGEN_FOR_BLAS=OFF \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_SWIG_PY=OFF \
..
```
There are some other arguments you might want to configure.
- `CMAKE_BUILD_TYPE=MinSizeRel` minimizes the size of library.
- `CMAKE_BUILD_TYPE-Release` optimizes the runtime performance.
Our own tip for performance optimization to use clang and Eigen or OpenBLAS:
- `CMAKE_BUILD_TYPE=Release`
- `ANDROID_TOOLCHAIN=clang`
- `USE_EIGEN_BLAS=ON` for `armeabi-v7a`, or `USE_EIGEN_FOR_BLAS=OFF` for `arm64-v8a`.
### Build and Install
After running `cmake`, we can run `make; 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 architectures.
After building,in the directory `CMAKE_INSTALL_PREFIX`, you will find three sub-directories:
- `include`: the header file of the inference library,
- `lib`: the inference library built for various Android ABIs,
- `third_party`: dependent third-party libraries built for Android.
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Build PaddlePaddle for Android &mdash; PaddlePaddle documentation</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="../../genindex.html"/>
<link rel="search" title="Search" href="../../search.html"/>
<link rel="top" title="PaddlePaddle documentation" href="../../index.html"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/override.css" type="text/css" />
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?b9a314ab40d04d805655aab1deee08ba";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<script src="../../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<header class="site-header">
<div class="site-logo">
<a href="/"><img src="../../_static/images/PP_w.png"></a>
</div>
<div class="site-nav-links">
<div class="site-menu">
<a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Fork me on Github</a>
<div class="language-switcher dropdown">
<a type="button" data-toggle="dropdown">
<span>English</span>
<i class="fa fa-angle-up"></i>
<i class="fa fa-angle-down"></i>
</a>
<ul class="dropdown-menu">
<li><a href="/doc_cn">中文</a></li>
<li><a href="/doc">English</a></li>
</ul>
</div>
<ul class="site-page-links">
<li><a href="/">Home</a></li>
</ul>
</div>
<div class="doc-module">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_en.html">GET STARTED</a></li>
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">HOW TO</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_en.html">API</a></li>
</ul>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
</header>
<div class="main-content-wrap">
<nav class="doc-menu-vertical" role="navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_en.html">GET STARTED</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../getstarted/build_and_install/index_en.html">Install and Build</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/docker_install_en.html">PaddlePaddle in Docker Containers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/build_from_source_en.html">Installing from Sources</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../index_en.html">HOW TO</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../usage/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/use_case_en.html">Use Case</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/arguments_en.html">Argument Outline</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/detail_introduction_en.html">Detail Description</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_en.html">PaddlePaddle Distributed Training</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_en.html">Paddle On Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_aws_en.html">Distributed PaddlePaddle Training on AWS with Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev/build_en.html">Build PaddlePaddle from Source Code and Run Unit Test</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev/new_layer_en.html">Write New Layers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev/contribute_to_paddle_en.html">Contribute Code</a></li>
<li class="toctree-l2"><a class="reference internal" href="../deep_model/rnn/index_en.html">RNN Models</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../deep_model/rnn/rnn_config_en.html">RNN Configuration</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_en.html">API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/model_configs.html">Model Configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/activation.html">Activation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/layer.html">Layers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/evaluators.html">Evaluators</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/pooling.html">Pooling</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/networks.html">Networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/attr.html">Parameter Attribute</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/data.html">Data Reader Interface and DataSets</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/run_logic.html">Training and Inference</a></li>
</ul>
</li>
</ul>
</nav>
<section class="doc-content-wrap">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li>Build PaddlePaddle for Android</li>
</ul>
</div>
<div class="wy-nav-content" id="doc-content">
<div class="rst-content">
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="build-paddlepaddle-for-android">
<span id="build-paddlepaddle-for-android"></span><h1>Build PaddlePaddle for Android<a class="headerlink" href="#build-paddlepaddle-for-android" title="Permalink to this headline"></a></h1>
<p>There are two approaches to build PaddlePaddle for Android: using Docker and on Linux without Docker.</p>
<div class="section" id="cross-compiling-using-docker">
<span id="cross-compiling-using-docker"></span><h2>Cross-Compiling Using Docker<a class="headerlink" href="#cross-compiling-using-docker" title="Permalink to this headline"></a></h2>
<p>Docker-based cross-compiling is the recommended approach because Docker runs on all major operating systems, including Linux, Mac OS X, and Windows.</p>
<div class="section" id="build-the-docker-image">
<span id="build-the-docker-image"></span><h3>Build the Docker Image<a class="headerlink" href="#build-the-docker-image" title="Permalink to this headline"></a></h3>
<p>The following steps pack all the tools that we need to build PaddlePaddle into a Docker image.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ git clone https://github.com/PaddlePaddle/Paddle.git
$ <span class="nb">cd</span> Paddle
$ docker build -t paddle:dev-android . -f Dockerfile.android
</pre></div>
</div>
</div>
<div class="section" id="build-the-inference-library">
<span id="build-the-inference-library"></span><h3>Build the Inference Library<a class="headerlink" href="#build-the-inference-library" title="Permalink to this headline"></a></h3>
<p>We can run the Docker image we just created to build the inference library of PaddlePaddle for Android using the command below:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ docker run -it --rm -v <span class="nv">$PWD</span>:/paddle -e <span class="s2">&quot;ANDROID_ABI=armeabi-v7a&quot;</span> -e <span class="s2">&quot;ANDROID_API=21&quot;</span> paddle:dev-android
</pre></div>
</div>
<p>The Docker image accepts two arguments <code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> and <code class="docutils literal"><span class="pre">ANDROID_API</span></code>:</p>
<p>| Argument | Optional Values | Default |
|&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;|
|<code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> |<code class="docutils literal"><span class="pre">armeabi-v7a,</span> <span class="pre">arm64-v8a</span></code> | <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> |
|<code class="docutils literal"><span class="pre">ANDROID_API</span></code> |<code class="docutils literal"><span class="pre">&gt;=</span> <span class="pre">21</span></code> | <code class="docutils literal"><span class="pre">21</span></code> |</p>
<p>The ARM-64 architecture (<code class="docutils literal"><span class="pre">arm64-v8a</span></code>) requires at least level 21 of Android API.</p>
<p>The default entry-point of the Docker image, <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh"><code class="docutils literal"><span class="pre">paddle/scripts/docker/build_android.sh</span></code></a> generates the <a class="reference external" href="https://developer.android.com/ndk/guides/standalone_toolchain.html">Android cross-compiling standalone toolchain</a> based on the argument: <code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> or <code class="docutils literal"><span class="pre">ANDROID_API</span></code>. For information about other configuration arguments, please continue reading.</p>
<p>The above command generates and outputs the inference library in <code class="docutils literal"><span class="pre">$PWD/install_android</span></code> and puts third-party libraries in <code class="docutils literal"><span class="pre">$PWD/install_android/third_party</span></code>.</p>
</div>
</div>
<div class="section" id="cross-compiling-on-linux">
<span id="cross-compiling-on-linux"></span><h2>Cross-Compiling on Linux<a class="headerlink" href="#cross-compiling-on-linux" title="Permalink to this headline"></a></h2>
<p>The Linux-base approach to cross-compile is to run steps in <code class="docutils literal"><span class="pre">Dockerfile.android</span></code> manually on a Linux x64 computer.</p>
<div class="section" id="setup-the-environment">
<span id="setup-the-environment"></span><h3>Setup the Environment<a class="headerlink" href="#setup-the-environment" title="Permalink to this headline"></a></h3>
<p>To build for Android&#8217;s, we need <a class="reference external" href="https://developer.android.com/ndk/downloads/index.html">Android NDK</a>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget -q https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip
unzip -q android-ndk-r14b-linux-x86_64.zip
</pre></div>
</div>
<p>Android NDK includes everything we need to build the <a class="reference external" href="https://developer.android.com/ndk/guides/standalone_toolchain.html"><em>standalone toolchain</em></a>, which in then used to build PaddlePaddle for Android. (We plan to remove the intermediate stage of building the standalone toolchain in the near future.)</p>
<ul>
<li><p class="first">To build the standalone toolchain for <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> and Android API level 21:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh <span class="se">\</span>
--arch<span class="o">=</span>arm --platform<span class="o">=</span>android-21 --install-dir<span class="o">=</span>your/path/to/arm_standalone_toolchain
</pre></div>
</div>
<p>The generated standalone toolchain will be in <code class="docutils literal"><span class="pre">your/path/to/arm_standalone_toolchain</span></code>.</p>
</li>
<li><p class="first">To build the standalone toolchain for <code class="docutils literal"><span class="pre">arm64-v8a</span></code> and Android API level 21:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh <span class="se">\</span>
--arch<span class="o">=</span>arm64 --platform<span class="o">=</span>android-21 --install-dir<span class="o">=</span>your/path/to/arm64_standalone_toolchain
</pre></div>
</div>
<p>The generated standalone toolchain will be in <code class="docutils literal"><span class="pre">your/path/to/arm64_standalone_toolchain</span></code>.</p>
</li>
</ul>
<p><strong>Please be aware that the minimum level of Android API required by PaddlePaddle is 21.</strong></p>
</div>
<div class="section" id="cross-compiling-arguments">
<span id="cross-compiling-arguments"></span><h3>Cross-Compiling Arguments<a class="headerlink" href="#cross-compiling-arguments" title="Permalink to this headline"></a></h3>
<p>CMake supports <a class="reference external" href="https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling">choosing the toolchain</a>. PaddlePaddle provides <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake"><code class="docutils literal"><span class="pre">android.cmake</span></code></a>, which configures the Android cross-compiling toolchain for CMake. <code class="docutils literal"><span class="pre">android.cmake</span></code> is not required for CMake &gt;= 3.7, which support Android cross-compiling. PaddlePaddle detects the CMake version, for those newer than 3.7, it uses <a class="reference external" href="https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling">the official version</a>.</p>
<p>Some other CMake arguments you need to know:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_SYSTEM_NAME</span></code> must be <code class="docutils literal"><span class="pre">Android</span></code>. This tells PaddlePaddle&#8217;s CMake system to cross-compile third-party dependencies. This also changes some other CMake arguments like <code class="docutils literal"><span class="pre">WITH_GPU=OFF</span></code>, <code class="docutils literal"><span class="pre">WITH_AVX=OFF</span></code>, <code class="docutils literal"><span class="pre">WITH_PYTHON=OFF</span></code>, and <code class="docutils literal"><span class="pre">WITH_RDMA=OFF</span></code>.</li>
<li><code class="docutils literal"><span class="pre">WITH_C_API</span></code> must be <code class="docutils literal"><span class="pre">ON</span></code>, to build the C-based inference library for Android.</li>
<li><code class="docutils literal"><span class="pre">WITH_SWIG_PY</span></code> must be <code class="docutils literal"><span class="pre">OFF</span></code> because the Android platform doesn&#8217;t support SWIG-based API.</li>
</ul>
<p>Some Android-specific arguments:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">ANDROID_STANDALONE_TOOLCHAIN</span></code>: the absolute path of the Android standalone toolchain, or the path relative to the CMake build directory. PaddlePaddle&#8217;s CMake extensions would derive the cross-compiler, sysroot and Android API level from this argument.</li>
<li><code class="docutils literal"><span class="pre">ANDROID_TOOLCHAIN</span></code>: could be <code class="docutils literal"><span class="pre">gcc</span></code> or <code class="docutils literal"><span class="pre">clang</span></code>. The default value is <code class="docutils literal"><span class="pre">clang</span></code>.<ul>
<li>For CMake &gt;= 3.7, it should anyway be <code class="docutils literal"><span class="pre">clang</span></code>. For older versions, it could be <code class="docutils literal"><span class="pre">gcc</span></code>.</li>
<li>Android&#8217;s official <code class="docutils literal"><span class="pre">clang</span></code> requires <code class="docutils literal"><span class="pre">glibc</span></code> &gt;= 2.15.</li>
</ul>
</li>
<li><code class="docutils literal"><span class="pre">ANDROID_ABI</span></code>: could be <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> or <code class="docutils literal"><span class="pre">arm64-v8a</span></code>. The default value is <code class="docutils literal"><span class="pre">armeabi-v7a</span></code>.</li>
<li><code class="docutils literal"><span class="pre">ANDROID_NATIVE_API_LEVEL</span></code>: could be derived from the value of <code class="docutils literal"><span class="pre">ANDROID_STANDALONE_TOOLCHAIN</span></code>.</li>
<li><code class="docutils literal"><span class="pre">ANROID_ARM_MODE</span></code>:<ul>
<li>could be <code class="docutils literal"><span class="pre">ON</span></code> or <code class="docutils literal"><span class="pre">OFF</span></code>, and defaults to <code class="docutils literal"><span class="pre">ON</span></code>, when <code class="docutils literal"><span class="pre">ANDROID_ABI=armeabi-v7a</span></code>;</li>
<li>no need to specify when <code class="docutils literal"><span class="pre">ANDROID_ABI=arm64-v8a</span></code>.</li>
</ul>
</li>
<li><code class="docutils literal"><span class="pre">ANDROID_ARM_NEON</span></code>: indicates if to use NEON instructions.<ul>
<li>could be <code class="docutils literal"><span class="pre">ON</span></code> or <code class="docutils literal"><span class="pre">OFF</span></code>, and defaults to <code class="docutils literal"><span class="pre">ON</span></code>, when <code class="docutils literal"><span class="pre">ANDROID_ABI=armeabi-v7a</span></code>;</li>
<li>no need to specify when <code class="docutils literal"><span class="pre">ANDROID_ABI=arm64-v8a</span></code>.</li>
</ul>
</li>
</ul>
<p>Other useful arguments:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">USE_EIGEN_FOR_BLAS</span></code>: indicates if using Eigen. Could be <code class="docutils literal"><span class="pre">ON</span></code> or <code class="docutils literal"><span class="pre">OFF</span></code>, defaults to <code class="docutils literal"><span class="pre">OFF</span></code>.</li>
<li><code class="docutils literal"><span class="pre">HOST_C/CXX_COMPILER</span></code>: 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 <code class="docutils literal"><span class="pre">CC</span></code>, or <code class="docutils literal"><span class="pre">cc</span></code>.</li>
</ul>
<p>Some frequent configurations for your reference:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>cmake -DCMAKE_SYSTEM_NAME<span class="o">=</span>Android <span class="se">\</span>
-DANDROID_STANDALONE_TOOLCHAIN<span class="o">=</span>your/path/to/arm_standalone_toolchain <span class="se">\</span>
-DANDROID_ABI<span class="o">=</span>armeabi-v7a <span class="se">\</span>
-DANDROID_ARM_NEON<span class="o">=</span>ON <span class="se">\</span>
-DANDROID_ARM_MODE<span class="o">=</span>ON <span class="se">\</span>
-DUSE_EIGEN_FOR_BLAS<span class="o">=</span>ON <span class="se">\</span>
-DCMAKE_INSTALL_PREFIX<span class="o">=</span>your/path/to/install <span class="se">\</span>
-DWITH_C_API<span class="o">=</span>ON <span class="se">\</span>
-DWITH_SWIG_PY<span class="o">=</span>OFF <span class="se">\</span>
..
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cmake</span> <span class="o">-</span><span class="n">DCMAKE_SYSTEM_NAME</span><span class="o">=</span><span class="n">Android</span> \
<span class="o">-</span><span class="n">DANDROID_STANDALONE_TOOLCHAIN</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">arm64_standalone_toolchain</span> \
<span class="o">-</span><span class="n">DANDROID_ABI</span><span class="o">=</span><span class="n">arm64</span><span class="o">-</span><span class="n">v8a</span> \
<span class="o">-</span><span class="n">DUSE_EIGEN_FOR_BLAS</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">-</span><span class="n">DCMAKE_INSTALL_PREFIX</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">install</span> \
<span class="o">-</span><span class="n">DWITH_C_API</span><span class="o">=</span><span class="n">ON</span> \
<span class="o">-</span><span class="n">DWITH_SWIG_PY</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">..</span>
</pre></div>
</div>
<p>There are some other arguments you might want to configure.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE=MinSizeRel</span></code> minimizes the size of library.</li>
<li><code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE-Release</span></code> optimizes the runtime performance.</li>
</ul>
<p>Our own tip for performance optimization to use clang and Eigen or OpenBLAS:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE=Release</span></code></li>
<li><code class="docutils literal"><span class="pre">ANDROID_TOOLCHAIN=clang</span></code></li>
<li><code class="docutils literal"><span class="pre">USE_EIGEN_BLAS=ON</span></code> for <code class="docutils literal"><span class="pre">armeabi-v7a</span></code>, or <code class="docutils literal"><span class="pre">USE_EIGEN_FOR_BLAS=OFF</span></code> for <code class="docutils literal"><span class="pre">arm64-v8a</span></code>.</li>
</ul>
</div>
<div class="section" id="build-and-install">
<span id="build-and-install"></span><h3>Build and Install<a class="headerlink" href="#build-and-install" title="Permalink to this headline"></a></h3>
<p>After running <code class="docutils literal"><span class="pre">cmake</span></code>, we can run <code class="docutils literal"><span class="pre">make;</span> <span class="pre">make</span> <span class="pre">install</span></code> to build and install.</p>
<p>Before building, you might want to remove the <code class="docutils literal"><span class="pre">third_party</span></code> and <code class="docutils literal"><span class="pre">build</span></code> directories including pre-built libraries for other architectures.</p>
<p>After building,in the directory <code class="docutils literal"><span class="pre">CMAKE_INSTALL_PREFIX</span></code>, you will find three sub-directories:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">include</span></code>: the header file of the inference library,</li>
<li><code class="docutils literal"><span class="pre">lib</span></code>: the inference library built for various Android ABIs,</li>
<li><code class="docutils literal"><span class="pre">third_party</span></code>: dependent third-party libraries built for Android.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2016, PaddlePaddle developers.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: ".txt",
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/js/perfect-scrollbar.jquery.min.js"></script>
<script src="../../_static/js/paddle_doc_init.js"></script>
</body>
</html>
\ No newline at end of file
因为 它太大了无法显示 source diff 。你可以改为 查看blob
# Build PaddlePaddle for Android
There are two approaches to build PaddlePaddle for Android: using Docker and on Linux without Docker.
## Cross-Compiling Using Docker
Docker-based cross-compiling is the recommended approach because Docker runs on all major operating systems, including Linux, Mac OS X, and Windows.
### Build the Docker Image
The following steps pack all the tools that we need to build PaddlePaddle into a Docker image.
```bash
$ git clone https://github.com/PaddlePaddle/Paddle.git
$ cd Paddle
$ docker build -t paddle:dev-android . -f Dockerfile.android
```
### Build the Inference Library
We can run the Docker image we just created to build the inference library of PaddlePaddle for Android using the command below:
```bash
$ docker run -it --rm -v $PWD:/paddle -e "ANDROID_ABI=armeabi-v7a" -e "ANDROID_API=21" paddle:dev-android
```
The Docker image accepts two arguments `ANDROID_ABI` and `ANDROID_API`:
| Argument | Optional Values | Default |
|-----------------|-------------------------|---------|
|`ANDROID_ABI` |`armeabi-v7a, arm64-v8a` | `armeabi-v7a` |
|`ANDROID_API` |`>= 21` | `21` |
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) based on the argument: `ANDROID_ABI` or `ANDROID_API`. For information about other configuration arguments, please continue reading.
The above command generates and outputs the inference library in `$PWD/install_android` and puts third-party libraries in `$PWD/install_android/third_party`.
## Cross-Compiling on Linux
The Linux-base approach to cross-compile is to run steps in `Dockerfile.android` manually on a Linux x64 computer.
### Setup the Environment
To build for Android's, we need [Android NDK](
https://developer.android.com/ndk/downloads/index.html):
```bash
wget -q https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip
unzip -q android-ndk-r14b-linux-x86_64.zip
```
Android NDK includes everything we need to build the [*standalone toolchain*](https://developer.android.com/ndk/guides/standalone_toolchain.html), which in then used to build PaddlePaddle for Android. (We plan to remove the intermediate stage of building the standalone toolchain in the near future.)
- To build the standalone toolchain for `armeabi-v7a` and Android API level 21:
```bash
your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh \
--arch=arm --platform=android-21 --install-dir=your/path/to/arm_standalone_toolchain
```
The generated standalone toolchain will be in `your/path/to/arm_standalone_toolchain`.
- To build the standalone toolchain for `arm64-v8a` and Android API level 21:
```bash
your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh \
--arch=arm64 --platform=android-21 --install-dir=your/path/to/arm64_standalone_toolchain
```
The generated standalone toolchain will be in `your/path/to/arm64_standalone_toolchain`.
**Please be aware that the minimum level of Android API required by PaddlePaddle is 21.**
### Cross-Compiling Arguments
CMake supports [choosing 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 support Android cross-compiling. PaddlePaddle detects the 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 arguments you need to know:
- `CMAKE_SYSTEM_NAME` must be `Android`. This tells PaddlePaddle's CMake system to cross-compile third-party dependencies. This also changes some other CMake arguments like `WITH_GPU=OFF`, `WITH_AVX=OFF`, `WITH_PYTHON=OFF`, and `WITH_RDMA=OFF`.
- `WITH_C_API` must be `ON`, to build the C-based inference library for Android.
- `WITH_SWIG_PY` must be `OFF` because the Android platform doesn't support SWIG-based API.
Some Android-specific arguments:
- `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 argument.
- `ANDROID_TOOLCHAIN`: could be `gcc` or `clang`. The default value is `clang`.
- For CMake >= 3.7, it should anyway be `clang`. For older versions, it could be `gcc`.
- Android's official `clang` requires `glibc` >= 2.15.
- `ANDROID_ABI`: could be `armeabi-v7a` or `arm64-v8a`. The default value is `armeabi-v7a`.
- `ANDROID_NATIVE_API_LEVEL`: could be derived from the value of `ANDROID_STANDALONE_TOOLCHAIN`.
- `ANROID_ARM_MODE`:
- could be `ON` or `OFF`, and defaults to `ON`, when `ANDROID_ABI=armeabi-v7a`;
- no need to specify when `ANDROID_ABI=arm64-v8a`.
- `ANDROID_ARM_NEON`: indicates if to use NEON instructions.
- could be `ON` or `OFF`, and defaults to `ON`, when `ANDROID_ABI=armeabi-v7a`;
- no need to specify when `ANDROID_ABI=arm64-v8a`.
Other useful arguments:
- `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`.
Some frequent configurations for your reference:
```bash
cmake -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_STANDALONE_TOOLCHAIN=your/path/to/arm_standalone_toolchain \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_ARM_NEON=ON \
-DANDROID_ARM_MODE=ON \
-DUSE_EIGEN_FOR_BLAS=ON \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_SWIG_PY=OFF \
..
```
```
cmake -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_STANDALONE_TOOLCHAIN=your/path/to/arm64_standalone_toolchain \
-DANDROID_ABI=arm64-v8a \
-DUSE_EIGEN_FOR_BLAS=OFF \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_SWIG_PY=OFF \
..
```
There are some other arguments you might want to configure.
- `CMAKE_BUILD_TYPE=MinSizeRel` minimizes the size of library.
- `CMAKE_BUILD_TYPE-Release` optimizes the runtime performance.
Our own tip for performance optimization to use clang and Eigen or OpenBLAS:
- `CMAKE_BUILD_TYPE=Release`
- `ANDROID_TOOLCHAIN=clang`
- `USE_EIGEN_BLAS=ON` for `armeabi-v7a`, or `USE_EIGEN_FOR_BLAS=OFF` for `arm64-v8a`.
### Build and Install
After running `cmake`, we can run `make; 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 architectures.
After building,in the directory `CMAKE_INSTALL_PREFIX`, you will find three sub-directories:
- `include`: the header file of the inference library,
- `lib`: the inference library built for various Android ABIs,
- `third_party`: dependent third-party libraries built for Android.
# 构建Android平台上的PaddlePaddle库
用户可通过如下两种方式,交叉编译Android平台上适用的PaddlePaddle库:
- 基于Docker容器的编译方式
- 基于Docker容器的编译方式
- 基于Linux交叉编译环境的编译方式
## 基于Docker容器的编译方式
......@@ -26,14 +26,14 @@ Android的Docker开发镜像向用户提供两个可配置的参数:
|`ANDROID_API` |`>= 21` | `21` |
- 编译`armeabi-v7a`,`Android API 21`的PaddlePaddle库
```bash
$ docker run -it --rm -v $PWD:/paddle -e "ANDROID_ABI=armeabi-v7a" -e "ANDROID_API=21" username/paddle-android:dev
```
```bash
$ docker run -it --rm -v $PWD:/paddle -e "ANDROID_ABI=armeabi-v7a" -e "ANDROID_API=21" username/paddle-android:dev
```
- 编译`arm64-v8a`,`Android API 21`的PaddlePaddle库
```bash
$ docker run -it --rm -v $PWD:/paddle -e "ANDROID_ABI=arm64-v8a" -e "ANDROID_API=21" username/paddle-android:dev
```
- 编译`arm64-v8a`,`Android API 21`的PaddlePaddle库
```bash
$ docker run -it --rm -v $PWD:/paddle -e "ANDROID_ABI=arm64-v8a" -e "ANDROID_API=21" username/paddle-android:dev
```
执行上述`docker run`命令时,容器默认执行[paddle/scripts/docker/build_android.sh](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh)脚本。该脚本中记录了交叉编译Android版PaddlePaddle库常用的CMake配置,并且会根据`ANDROID_ABI`和`ANDROID_API`自动构建独立工具链、进行编译和安装。由于arm64架构要求Android API不小于21。因此当`ANDROID_ABI=arm64-v8a`,`ANDROID_API<21`时,Docker容器中将默认使用`Android API 21`的编译工具链。用户可以参考下文**配置交叉编译参数**章节,根据个人的需求修改定制Docker容器所执行的脚本。编译安装结束之后,PaddlePaddle的C-API库将被安装到`$PWD/install_android`目录,所依赖的第三方库同时也被安装到`$PWD/install_android/third_party`目录。
......@@ -82,16 +82,16 @@ CMake系统对交叉编译提供了支持[cmake-toolchains](https://cmake.org/cm
Android平台可选配置参数:
- `ANDROID_STANDALONE_TOOLCHAIN`,独立工具链所在的绝对路径,或者相对于构建目录的相对路径。PaddlePaddle的CMake系统将根据该值自动推导和设置需要使用的交叉编译器、sysroot、以及Android API级别;否则,用户需要在cmake时手动设置这些值。无默认值。
- `ANDROID_TOOLCHAIN`,目标工具链。可设置`gcc/clang`,默认值为`clang`。
- CMake 3.7以上,将会始终使用`clang`工具链;CMake 3.7以下,可设置`ANDROID_TOOLCHAIN=gcc`以使用`gcc`工具链。
- `ANDROID_TOOLCHAIN`,目标工具链。可设置`gcc/clang`,默认值为`clang`。
- CMake 3.7以上,将会始终使用`clang`工具链;CMake 3.7以下,可设置`ANDROID_TOOLCHAIN=gcc`以使用`gcc`工具链。
- Android官方提供的`clang`编译器要求系统支持`GLIBC 2.15`以上。
- `ANDROID_ABI`,目标架构ABI。目前支持`armeabi-v7a`和`arm64-v8a`,默认值为`armeabi-v7a`。
- `ANDROID_NATIVE_API_LEVEL`,工具链的Android API级别。若没有显式设置,PaddlePaddle将根据`ANDROID_STANDALONE_TOOLCHAIN`的值自动推导得到。
- `ANROID_ARM_MODE`,是否使用ARM模式。
- `ANDROID_ABI=armeabi-v7a`时,可设置`ON/OFF`,默认值为`ON`;
- `ANROID_ARM_MODE`,是否使用ARM模式。
- `ANDROID_ABI=armeabi-v7a`时,可设置`ON/OFF`,默认值为`ON`;
- `ANDROID_ABI=arm64-v8a`时,不需要设置。
- `ANDROID_ARM_NEON`,是否使用NEON指令。
- `ANDROID_ABI=armeabi-v7a`时,可设置`ON/OFF`,默认值为`ON`;
- `ANDROID_ARM_NEON`,是否使用NEON指令。
- `ANDROID_ABI=armeabi-v7a`时,可设置`ON/OFF`,默认值为`ON`;
- `ANDROID_ABI=arm64-v8a`时,不需要设置。
其他配置参数:
......@@ -119,7 +119,7 @@ cmake -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_STANDALONE_TOOLCHAIN=your/path/to/arm64_standalone_toolchain \
-DANDROID_ABI=arm64-v8a \
-DUSE_EIGEN_FOR_BLAS=OFF \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_SWIG_PY=OFF \
..
......@@ -128,8 +128,8 @@ cmake -DCMAKE_SYSTEM_NAME=Android \
用户还可根据自己的需求设置其他编译参数。比如希望最小化生成的库的大小,可以设置`CMAKE_BUILD_TYPE`为`MinSizeRel`;若希望最快的执行速度,则可设置`CMAKE_BUILD_TYPE`为`Release`。亦可以通过手动设置`CMAKE_C/CXX_FLAGS_MINSIZEREL/RELEASE`来影响PaddlePaddle的编译过程。
**性能TIPS**,为了达到最快的计算速度,在CMake参数配置上,有以下建议:
- 设置`CMAKE_BUILD_TYPE`为`Release`
- 使用`clang`编译工具链
- 设置`CMAKE_BUILD_TYPE`为`Release`
- 使用`clang`编译工具链
- `armeabi-v7a`时,设置`USE_EIGEN_BLAS=ON`,使用Eigen进行矩阵计算;`arm64-v8a`时,设置`USE_EIGEN_FOR_BLAS=OFF`,使用OpenBLAS进行矩阵计算
### 编译和安装
......
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Build PaddlePaddle for Android &mdash; PaddlePaddle 文档</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="index" title="索引"
href="../../genindex.html"/>
<link rel="search" title="搜索" href="../../search.html"/>
<link rel="top" title="PaddlePaddle 文档" href="../../index.html"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/override.css" type="text/css" />
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?b9a314ab40d04d805655aab1deee08ba";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<script src="../../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<header class="site-header">
<div class="site-logo">
<a href="/"><img src="../../_static/images/PP_w.png"></a>
</div>
<div class="site-nav-links">
<div class="site-menu">
<a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Fork me on Github</a>
<div class="language-switcher dropdown">
<a type="button" data-toggle="dropdown">
<span>English</span>
<i class="fa fa-angle-up"></i>
<i class="fa fa-angle-down"></i>
</a>
<ul class="dropdown-menu">
<li><a href="/doc_cn">中文</a></li>
<li><a href="/doc">English</a></li>
</ul>
</div>
<ul class="site-page-links">
<li><a href="/">Home</a></li>
</ul>
</div>
<div class="doc-module">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_cn.html">新手入门</a></li>
<li class="toctree-l1"><a class="reference internal" href="../index_cn.html">进阶指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_cn.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index_cn.html">FAQ</a></li>
</ul>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
</header>
<div class="main-content-wrap">
<nav class="doc-menu-vertical" role="navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_cn.html">新手入门</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../getstarted/build_and_install/index_cn.html">安装与编译</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/docker_install_cn.html">PaddlePaddle的Docker容器使用方式</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/cmake/build_from_source_cn.html">PaddlePaddle的编译选项</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../getstarted/concepts/use_concepts_cn.html">基本使用概念</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../index_cn.html">进阶指南</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../usage/cmd_parameter/index_cn.html">设置命令行参数</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/use_case_cn.html">使用案例</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/arguments_cn.html">参数概述</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/detail_introduction_cn.html">细节描述</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_cn.html">PaddlePaddle分布式训练</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_basis_cn.html">Kubernetes 简介</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_cn.html">Kubernetes单机训练</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_distributed_cn.html">Kubernetes分布式训练</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev/build_cn.html">编译PaddlePaddle和运行单元测试</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev/write_docs_cn.html">如何贡献/修改文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../deep_model/rnn/index_cn.html">RNN相关模型</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../deep_model/rnn/rnn_config_cn.html">RNN配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../deep_model/rnn/recurrent_group_cn.html">Recurrent Group教程</a></li>
<li class="toctree-l3"><a class="reference internal" href="../deep_model/rnn/hierarchical_layer_cn.html">支持双层序列作为输入的Layer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../deep_model/rnn/hrnn_rnn_api_compare_cn.html">单双层RNN API对比介绍</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../optimization/gpu_profiling_cn.html">GPU性能分析与调优</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_cn.html">API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/model_configs.html">模型配置</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/activation.html">Activation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/layer.html">Layers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/evaluators.html">Evaluators</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/pooling.html">Pooling</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/networks.html">Networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/attr.html">Parameter Attribute</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/data.html">数据访问</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/run_logic.html">训练与应用</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index_cn.html">FAQ</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../faq/build_and_install/index_cn.html">编译安装与单元测试</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../faq/model/index_cn.html">模型配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../faq/parameter/index_cn.html">参数设置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../faq/local/index_cn.html">本地训练与预测</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../faq/cluster/index_cn.html">集群训练与预测</a></li>
</ul>
</li>
</ul>
</nav>
<section class="doc-content-wrap">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li>Build PaddlePaddle for Android</li>
</ul>
</div>
<div class="wy-nav-content" id="doc-content">
<div class="rst-content">
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="build-paddlepaddle-for-android">
<span id="build-paddlepaddle-for-android"></span><h1>Build PaddlePaddle for Android<a class="headerlink" href="#build-paddlepaddle-for-android" title="永久链接至标题"></a></h1>
<p>There are two approaches to build PaddlePaddle for Android: using Docker and on Linux without Docker.</p>
<div class="section" id="cross-compiling-using-docker">
<span id="cross-compiling-using-docker"></span><h2>Cross-Compiling Using Docker<a class="headerlink" href="#cross-compiling-using-docker" title="永久链接至标题"></a></h2>
<p>Docker-based cross-compiling is the recommended approach because Docker runs on all major operating systems, including Linux, Mac OS X, and Windows.</p>
<div class="section" id="build-the-docker-image">
<span id="build-the-docker-image"></span><h3>Build the Docker Image<a class="headerlink" href="#build-the-docker-image" title="永久链接至标题"></a></h3>
<p>The following steps pack all the tools that we need to build PaddlePaddle into a Docker image.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ git clone https://github.com/PaddlePaddle/Paddle.git
$ <span class="nb">cd</span> Paddle
$ docker build -t paddle:dev-android . -f Dockerfile.android
</pre></div>
</div>
</div>
<div class="section" id="build-the-inference-library">
<span id="build-the-inference-library"></span><h3>Build the Inference Library<a class="headerlink" href="#build-the-inference-library" title="永久链接至标题"></a></h3>
<p>We can run the Docker image we just created to build the inference library of PaddlePaddle for Android using the command below:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ docker run -it --rm -v <span class="nv">$PWD</span>:/paddle -e <span class="s2">&quot;ANDROID_ABI=armeabi-v7a&quot;</span> -e <span class="s2">&quot;ANDROID_API=21&quot;</span> paddle:dev-android
</pre></div>
</div>
<p>The Docker image accepts two arguments <code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> and <code class="docutils literal"><span class="pre">ANDROID_API</span></code>:</p>
<p>| Argument | Optional Values | Default |
|&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;|
|<code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> |<code class="docutils literal"><span class="pre">armeabi-v7a,</span> <span class="pre">arm64-v8a</span></code> | <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> |
|<code class="docutils literal"><span class="pre">ANDROID_API</span></code> |<code class="docutils literal"><span class="pre">&gt;=</span> <span class="pre">21</span></code> | <code class="docutils literal"><span class="pre">21</span></code> |</p>
<p>The ARM-64 architecture (<code class="docutils literal"><span class="pre">arm64-v8a</span></code>) requires at least level 21 of Android API.</p>
<p>The default entry-point of the Docker image, <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh"><code class="docutils literal"><span class="pre">paddle/scripts/docker/build_android.sh</span></code></a> generates the <a class="reference external" href="https://developer.android.com/ndk/guides/standalone_toolchain.html">Android cross-compiling standalone toolchain</a> based on the argument: <code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> or <code class="docutils literal"><span class="pre">ANDROID_API</span></code>. For information about other configuration arguments, please continue reading.</p>
<p>The above command generates and outputs the inference library in <code class="docutils literal"><span class="pre">$PWD/install_android</span></code> and puts third-party libraries in <code class="docutils literal"><span class="pre">$PWD/install_android/third_party</span></code>.</p>
</div>
</div>
<div class="section" id="cross-compiling-on-linux">
<span id="cross-compiling-on-linux"></span><h2>Cross-Compiling on Linux<a class="headerlink" href="#cross-compiling-on-linux" title="永久链接至标题"></a></h2>
<p>The Linux-base approach to cross-compile is to run steps in <code class="docutils literal"><span class="pre">Dockerfile.android</span></code> manually on a Linux x64 computer.</p>
<div class="section" id="setup-the-environment">
<span id="setup-the-environment"></span><h3>Setup the Environment<a class="headerlink" href="#setup-the-environment" title="永久链接至标题"></a></h3>
<p>To build for Android&#8217;s, we need <a class="reference external" href="https://developer.android.com/ndk/downloads/index.html">Android NDK</a>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget -q https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip
unzip -q android-ndk-r14b-linux-x86_64.zip
</pre></div>
</div>
<p>Android NDK includes everything we need to build the <a class="reference external" href="https://developer.android.com/ndk/guides/standalone_toolchain.html"><em>standalone toolchain</em></a>, which in then used to build PaddlePaddle for Android. (We plan to remove the intermediate stage of building the standalone toolchain in the near future.)</p>
<ul>
<li><p class="first">To build the standalone toolchain for <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> and Android API level 21:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh <span class="se">\</span>
--arch<span class="o">=</span>arm --platform<span class="o">=</span>android-21 --install-dir<span class="o">=</span>your/path/to/arm_standalone_toolchain
</pre></div>
</div>
<p>The generated standalone toolchain will be in <code class="docutils literal"><span class="pre">your/path/to/arm_standalone_toolchain</span></code>.</p>
</li>
<li><p class="first">To build the standalone toolchain for <code class="docutils literal"><span class="pre">arm64-v8a</span></code> and Android API level 21:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>your/path/to/android-ndk-r14b-linux-x86_64/build/tools/make-standalone-toolchain.sh <span class="se">\</span>
--arch<span class="o">=</span>arm64 --platform<span class="o">=</span>android-21 --install-dir<span class="o">=</span>your/path/to/arm64_standalone_toolchain
</pre></div>
</div>
<p>The generated standalone toolchain will be in <code class="docutils literal"><span class="pre">your/path/to/arm64_standalone_toolchain</span></code>.</p>
</li>
</ul>
<p><strong>Please be aware that the minimum level of Android API required by PaddlePaddle is 21.</strong></p>
</div>
<div class="section" id="cross-compiling-arguments">
<span id="cross-compiling-arguments"></span><h3>Cross-Compiling Arguments<a class="headerlink" href="#cross-compiling-arguments" title="永久链接至标题"></a></h3>
<p>CMake supports <a class="reference external" href="https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling">choosing the toolchain</a>. PaddlePaddle provides <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake"><code class="docutils literal"><span class="pre">android.cmake</span></code></a>, which configures the Android cross-compiling toolchain for CMake. <code class="docutils literal"><span class="pre">android.cmake</span></code> is not required for CMake &gt;= 3.7, which support Android cross-compiling. PaddlePaddle detects the CMake version, for those newer than 3.7, it uses <a class="reference external" href="https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling">the official version</a>.</p>
<p>Some other CMake arguments you need to know:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_SYSTEM_NAME</span></code> must be <code class="docutils literal"><span class="pre">Android</span></code>. This tells PaddlePaddle&#8217;s CMake system to cross-compile third-party dependencies. This also changes some other CMake arguments like <code class="docutils literal"><span class="pre">WITH_GPU=OFF</span></code>, <code class="docutils literal"><span class="pre">WITH_AVX=OFF</span></code>, <code class="docutils literal"><span class="pre">WITH_PYTHON=OFF</span></code>, and <code class="docutils literal"><span class="pre">WITH_RDMA=OFF</span></code>.</li>
<li><code class="docutils literal"><span class="pre">WITH_C_API</span></code> must be <code class="docutils literal"><span class="pre">ON</span></code>, to build the C-based inference library for Android.</li>
<li><code class="docutils literal"><span class="pre">WITH_SWIG_PY</span></code> must be <code class="docutils literal"><span class="pre">OFF</span></code> because the Android platform doesn&#8217;t support SWIG-based API.</li>
</ul>
<p>Some Android-specific arguments:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">ANDROID_STANDALONE_TOOLCHAIN</span></code>: the absolute path of the Android standalone toolchain, or the path relative to the CMake build directory. PaddlePaddle&#8217;s CMake extensions would derive the cross-compiler, sysroot and Android API level from this argument.</li>
<li><code class="docutils literal"><span class="pre">ANDROID_TOOLCHAIN</span></code>: could be <code class="docutils literal"><span class="pre">gcc</span></code> or <code class="docutils literal"><span class="pre">clang</span></code>. The default value is <code class="docutils literal"><span class="pre">clang</span></code>.<ul>
<li>For CMake &gt;= 3.7, it should anyway be <code class="docutils literal"><span class="pre">clang</span></code>. For older versions, it could be <code class="docutils literal"><span class="pre">gcc</span></code>.</li>
<li>Android&#8217;s official <code class="docutils literal"><span class="pre">clang</span></code> requires <code class="docutils literal"><span class="pre">glibc</span></code> &gt;= 2.15.</li>
</ul>
</li>
<li><code class="docutils literal"><span class="pre">ANDROID_ABI</span></code>: could be <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> or <code class="docutils literal"><span class="pre">arm64-v8a</span></code>. The default value is <code class="docutils literal"><span class="pre">armeabi-v7a</span></code>.</li>
<li><code class="docutils literal"><span class="pre">ANDROID_NATIVE_API_LEVEL</span></code>: could be derived from the value of <code class="docutils literal"><span class="pre">ANDROID_STANDALONE_TOOLCHAIN</span></code>.</li>
<li><code class="docutils literal"><span class="pre">ANROID_ARM_MODE</span></code>:<ul>
<li>could be <code class="docutils literal"><span class="pre">ON</span></code> or <code class="docutils literal"><span class="pre">OFF</span></code>, and defaults to <code class="docutils literal"><span class="pre">ON</span></code>, when <code class="docutils literal"><span class="pre">ANDROID_ABI=armeabi-v7a</span></code>;</li>
<li>no need to specify when <code class="docutils literal"><span class="pre">ANDROID_ABI=arm64-v8a</span></code>.</li>
</ul>
</li>
<li><code class="docutils literal"><span class="pre">ANDROID_ARM_NEON</span></code>: indicates if to use NEON instructions.<ul>
<li>could be <code class="docutils literal"><span class="pre">ON</span></code> or <code class="docutils literal"><span class="pre">OFF</span></code>, and defaults to <code class="docutils literal"><span class="pre">ON</span></code>, when <code class="docutils literal"><span class="pre">ANDROID_ABI=armeabi-v7a</span></code>;</li>
<li>no need to specify when <code class="docutils literal"><span class="pre">ANDROID_ABI=arm64-v8a</span></code>.</li>
</ul>
</li>
</ul>
<p>Other useful arguments:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">USE_EIGEN_FOR_BLAS</span></code>: indicates if using Eigen. Could be <code class="docutils literal"><span class="pre">ON</span></code> or <code class="docutils literal"><span class="pre">OFF</span></code>, defaults to <code class="docutils literal"><span class="pre">OFF</span></code>.</li>
<li><code class="docutils literal"><span class="pre">HOST_C/CXX_COMPILER</span></code>: 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 <code class="docutils literal"><span class="pre">CC</span></code>, or <code class="docutils literal"><span class="pre">cc</span></code>.</li>
</ul>
<p>Some frequent configurations for your reference:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>cmake -DCMAKE_SYSTEM_NAME<span class="o">=</span>Android <span class="se">\</span>
-DANDROID_STANDALONE_TOOLCHAIN<span class="o">=</span>your/path/to/arm_standalone_toolchain <span class="se">\</span>
-DANDROID_ABI<span class="o">=</span>armeabi-v7a <span class="se">\</span>
-DANDROID_ARM_NEON<span class="o">=</span>ON <span class="se">\</span>
-DANDROID_ARM_MODE<span class="o">=</span>ON <span class="se">\</span>
-DUSE_EIGEN_FOR_BLAS<span class="o">=</span>ON <span class="se">\</span>
-DCMAKE_INSTALL_PREFIX<span class="o">=</span>your/path/to/install <span class="se">\</span>
-DWITH_C_API<span class="o">=</span>ON <span class="se">\</span>
-DWITH_SWIG_PY<span class="o">=</span>OFF <span class="se">\</span>
..
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cmake</span> <span class="o">-</span><span class="n">DCMAKE_SYSTEM_NAME</span><span class="o">=</span><span class="n">Android</span> \
<span class="o">-</span><span class="n">DANDROID_STANDALONE_TOOLCHAIN</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">arm64_standalone_toolchain</span> \
<span class="o">-</span><span class="n">DANDROID_ABI</span><span class="o">=</span><span class="n">arm64</span><span class="o">-</span><span class="n">v8a</span> \
<span class="o">-</span><span class="n">DUSE_EIGEN_FOR_BLAS</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">-</span><span class="n">DCMAKE_INSTALL_PREFIX</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">install</span> \
<span class="o">-</span><span class="n">DWITH_C_API</span><span class="o">=</span><span class="n">ON</span> \
<span class="o">-</span><span class="n">DWITH_SWIG_PY</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">..</span>
</pre></div>
</div>
<p>There are some other arguments you might want to configure.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE=MinSizeRel</span></code> minimizes the size of library.</li>
<li><code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE-Release</span></code> optimizes the runtime performance.</li>
</ul>
<p>Our own tip for performance optimization to use clang and Eigen or OpenBLAS:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE=Release</span></code></li>
<li><code class="docutils literal"><span class="pre">ANDROID_TOOLCHAIN=clang</span></code></li>
<li><code class="docutils literal"><span class="pre">USE_EIGEN_BLAS=ON</span></code> for <code class="docutils literal"><span class="pre">armeabi-v7a</span></code>, or <code class="docutils literal"><span class="pre">USE_EIGEN_FOR_BLAS=OFF</span></code> for <code class="docutils literal"><span class="pre">arm64-v8a</span></code>.</li>
</ul>
</div>
<div class="section" id="build-and-install">
<span id="build-and-install"></span><h3>Build and Install<a class="headerlink" href="#build-and-install" title="永久链接至标题"></a></h3>
<p>After running <code class="docutils literal"><span class="pre">cmake</span></code>, we can run <code class="docutils literal"><span class="pre">make;</span> <span class="pre">make</span> <span class="pre">install</span></code> to build and install.</p>
<p>Before building, you might want to remove the <code class="docutils literal"><span class="pre">third_party</span></code> and <code class="docutils literal"><span class="pre">build</span></code> directories including pre-built libraries for other architectures.</p>
<p>After building,in the directory <code class="docutils literal"><span class="pre">CMAKE_INSTALL_PREFIX</span></code>, you will find three sub-directories:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">include</span></code>: the header file of the inference library,</li>
<li><code class="docutils literal"><span class="pre">lib</span></code>: the inference library built for various Android ABIs,</li>
<li><code class="docutils literal"><span class="pre">third_party</span></code>: dependent third-party libraries built for Android.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2016, PaddlePaddle developers.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: ".txt",
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" src="../../_static/translations.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.0/MathJax.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/js/perfect-scrollbar.jquery.min.js"></script>
<script src="../../_static/js/paddle_doc_init.js"></script>
</body>
</html>
\ No newline at end of file
......@@ -217,18 +217,18 @@ Android的Docker开发镜像向用户提供两个可配置的参数:</p>
|&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;|
|<code class="docutils literal"><span class="pre">ANDROID_ABI</span></code> |<code class="docutils literal"><span class="pre">armeabi-v7a,</span> <span class="pre">arm64-v8a</span></code> | <code class="docutils literal"><span class="pre">armeabi-v7a</span></code> |
|<code class="docutils literal"><span class="pre">ANDROID_API</span></code> |<code class="docutils literal"><span class="pre">&gt;=</span> <span class="pre">21</span></code> | <code class="docutils literal"><span class="pre">21</span></code> |</p>
<ul class="simple">
<li>编译<code class="docutils literal"><span class="pre">armeabi-v7a</span></code><code class="docutils literal"><span class="pre">Android</span> <span class="pre">API</span> <span class="pre">21</span></code>的PaddlePaddle库</li>
</ul>
<ul>
<li><p class="first">编译<code class="docutils literal"><span class="pre">armeabi-v7a</span></code><code class="docutils literal"><span class="pre">Android</span> <span class="pre">API</span> <span class="pre">21</span></code>的PaddlePaddle库</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ docker run -it --rm -v <span class="nv">$PWD</span>:/paddle -e <span class="s2">&quot;ANDROID_ABI=armeabi-v7a&quot;</span> -e <span class="s2">&quot;ANDROID_API=21&quot;</span> username/paddle-android:dev
</pre></div>
</div>
<ul class="simple">
<li>编译<code class="docutils literal"><span class="pre">arm64-v8a</span></code><code class="docutils literal"><span class="pre">Android</span> <span class="pre">API</span> <span class="pre">21</span></code>的PaddlePaddle库</li>
</ul>
</li>
<li><p class="first">编译<code class="docutils literal"><span class="pre">arm64-v8a</span></code><code class="docutils literal"><span class="pre">Android</span> <span class="pre">API</span> <span class="pre">21</span></code>的PaddlePaddle库</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ docker run -it --rm -v <span class="nv">$PWD</span>:/paddle -e <span class="s2">&quot;ANDROID_ABI=arm64-v8a&quot;</span> -e <span class="s2">&quot;ANDROID_API=21&quot;</span> username/paddle-android:dev
</pre></div>
</div>
</li>
</ul>
<p>执行上述<code class="docutils literal"><span class="pre">docker</span> <span class="pre">run</span></code>命令时,容器默认执行<a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build_android.sh">paddle/scripts/docker/build_android.sh</a>脚本。该脚本中记录了交叉编译Android版PaddlePaddle库常用的CMake配置,并且会根据<code class="docutils literal"><span class="pre">ANDROID_ABI</span></code><code class="docutils literal"><span class="pre">ANDROID_API</span></code>自动构建独立工具链、进行编译和安装。由于arm64架构要求Android API不小于21。因此当<code class="docutils literal"><span class="pre">ANDROID_ABI=arm64-v8a</span></code><code class="docutils literal"><span class="pre">ANDROID_API&lt;21</span></code>时,Docker容器中将默认使用<code class="docutils literal"><span class="pre">Android</span> <span class="pre">API</span> <span class="pre">21</span></code>的编译工具链。用户可以参考下文<strong>配置交叉编译参数</strong>章节,根据个人的需求修改定制Docker容器所执行的脚本。编译安装结束之后,PaddlePaddle的C-API库将被安装到<code class="docutils literal"><span class="pre">$PWD/install_android</span></code>目录,所依赖的第三方库同时也被安装到<code class="docutils literal"><span class="pre">$PWD/install_android/third_party</span></code>目录。</p>
</div>
</div>
......@@ -313,7 +313,7 @@ unzip -q android-ndk-r14b-linux-x86_64.zip
<span class="o">-</span><span class="n">DANDROID_STANDALONE_TOOLCHAIN</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">arm64_standalone_toolchain</span> \
<span class="o">-</span><span class="n">DANDROID_ABI</span><span class="o">=</span><span class="n">arm64</span><span class="o">-</span><span class="n">v8a</span> \
<span class="o">-</span><span class="n">DUSE_EIGEN_FOR_BLAS</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">-</span><span class="n">DCMAKE_INSTALL_PREFIX</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">install</span> \
<span class="o">-</span><span class="n">DCMAKE_INSTALL_PREFIX</span><span class="o">=</span><span class="n">your</span><span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">install</span> \
<span class="o">-</span><span class="n">DWITH_C_API</span><span class="o">=</span><span class="n">ON</span> \
<span class="o">-</span><span class="n">DWITH_SWIG_PY</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">..</span>
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册