cross_compiling_for_android_en.html 28.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26


<!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>
  

  
  

  

  
  
    

  

  
  
27
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
28 29 30 31 32
  

  
  
        <link rel="index" title="Index"
33 34 35 36 37 38
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="PaddlePaddle  documentation" href="../index.html"/>
        <link rel="up" title="MOBILE" href="index_en.html"/>
        <link rel="next" title="Build PaddlePaddle for Raspberry Pi" href="cross_compiling_for_raspberry_en.html"/>
        <link rel="prev" title="MOBILE" href="index_en.html"/> 
39 40

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" />
41
  <link rel="stylesheet" href="../_static/css/override.css" type="text/css" />
42 43 44 45 46 47 48 49 50 51 52 53 54
  <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>

  

  
55
  <script src="../_static/js/modernizr.min.js"></script>
56 57 58 59 60 61 62 63

</head>

<body class="wy-body-for-nav" role="document">

  
  <header class="site-header">
    <div class="site-logo">
64
      <a href="/"><img src="../_static/images/PP_w.png"></a>
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    </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">
        
86 87 88 89 90
        <ul class="current">
<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="../howto/index_en.html">HOW TO</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/index_en.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index_en.html">MOBILE</a></li>
91 92 93 94
</ul>

        
<div role="search">
95
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    <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">
        
          
111 112 113
          <ul class="current">
<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>
114 115 116
<li class="toctree-l3"><a class="reference internal" href="../getstarted/build_and_install/pip_install_en.html">Install Using pip</a></li>
<li class="toctree-l3"><a class="reference internal" href="../getstarted/build_and_install/docker_install_en.html">Run in Docker Containers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../getstarted/build_and_install/build_from_source_en.html">Build from Sources</a></li>
117 118 119 120
</ul>
</li>
</ul>
</li>
121 122 123 124 125
<li class="toctree-l1"><a class="reference internal" href="../howto/index_en.html">HOW TO</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../howto/usage/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/usage/cmd_parameter/use_case_en.html">Use Case</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/usage/cmd_parameter/arguments_en.html">Argument Outline</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/usage/cmd_parameter/detail_introduction_en.html">Detail Description</a></li>
126 127
</ul>
</li>
128 129 130 131 132
<li class="toctree-l2"><a class="reference internal" href="../howto/usage/cluster/cluster_train_en.html">PaddlePaddle Distributed Training</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/usage/k8s/k8s_en.html">Paddle On Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/usage/k8s/k8s_aws_en.html">Distributed PaddlePaddle Training on AWS with Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/dev/new_layer_en.html">Write New Layers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../howto/dev/contribute_to_paddle_en.html">Contribute Code</a></li>
133
<li class="toctree-l2"><a class="reference internal" href="../howto/dev/write_docs_en.html">Contribute Documentation</a></li>
134 135
<li class="toctree-l2"><a class="reference internal" href="../howto/deep_model/rnn/index_en.html">RNN Models</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/deep_model/rnn/rnn_config_en.html">RNN Configuration</a></li>
136 137
</ul>
</li>
138
<li class="toctree-l2"><a class="reference internal" href="../howto/optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
139 140
</ul>
</li>
141 142 143 144 145 146 147 148 149
<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>
150 151
</ul>
</li>
152 153 154 155 156 157
<li class="toctree-l2"><a class="reference internal" href="../api/v2/data.html">Data Reader Interface and DataSets</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/data/data_reader.html">Data Reader Interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/data/image.html">Image Interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/data/dataset.html">Dataset</a></li>
</ul>
</li>
158
<li class="toctree-l2"><a class="reference internal" href="../api/v2/run_logic.html">Training and Inference</a></li>
159 160 161 162 163 164 165 166 167 168 169 170 171
<li class="toctree-l2"><a class="reference internal" href="../api/v2/fluid.html">Fluid</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/layers.html">Layers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/data_feeder.html">DataFeeder</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/executor.html">Executor</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/initializer.html">Initializer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/evaluator.html">Evaluator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/nets.html">Nets</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/param_attr.html">ParamAttr</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/profiler.html">Profiler</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/v2/fluid/regularizer.html">Regularizer</a></li>
</ul>
</li>
172 173 174 175 176
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="index_en.html">MOBILE</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">Build PaddlePaddle for Android</a></li>
<li class="toctree-l2"><a class="reference internal" href="cross_compiling_for_raspberry_en.html">Build PaddlePaddle for Raspberry Pi</a></li>
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
</ul>
</li>
</ul>

        
    </nav>
    
    <section class="doc-content-wrap">

      

 







<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
      
199 200
        <li><a href="index_en.html">MOBILE</a> > </li>
      
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    <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>
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
<table class="docutils">
<colgroup>
  <col width="25%" />
  <col width="50%" />
  <col width="25%" />
</colgroup>
<thead valign="bottom">
  <tr class="row-odd">
  <th class="head">Argument</th>
  <th class="head">Optional Values</th>
  <th class="head">Default</th>
</tr>
</thead>
<tbody valign="top">
  <tr class="row-even">
  <td>ANDROID_ABI</td>
  <td>armeabi-v7a, arm64-v8a</td>
  <td>armeabi-v7a</td>
</tr>
<tr class="row-odd">
  <td>ANDROID_API</td>
  <td>>= 21</td>
  <td>21</td>
</tr>
</tbody>
</table><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>
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
<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>
  
380 381 382 383 384 385 386 387 388
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="cross_compiling_for_raspberry_en.html" class="btn btn-neutral float-right" title="Build PaddlePaddle for Raspberry Pi" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="index_en.html" class="btn btn-neutral" title="MOBILE" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414

  <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 = {
415
            URL_ROOT:'../',
416 417 418 419 420 421 422
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: ".txt",
        };
    </script>
423 424 425
      <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>
426 427 428 429 430 431
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
       
  

  
  
432
    <script type="text/javascript" src="../_static/js/theme.js"></script>
433 434 435 436
  
  
  <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>
437
  <script src="../_static/js/paddle_doc_init.js"></script> 
438 439 440

</body>
</html>