提交 7b56a1b3 编写于 作者: T Travis CI

Deploy to GitHub Pages: 3093bb80

上级 1bb7b64e
# 如何构建Raspberry pi下运行的PaddlePaddle
这里考虑的是交叉编译方式,即在Linux-x86环境下构建Raspberry pi下可运行的PaddlePaddle。
## 下载交叉编译环境
```
git clone https://github.com/raspberrypi/tools
```
如果host是x86-64环境,选用`arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64`下的作为编译工具。注意,需要系统glibc支持2.14以上。
## 编译第三方库
cmake编译PaddlePaddle时候会自动下载编译依赖的第三方库,不过openblas和protobuf最好还是在编译PaddlePaddle之前先编译好,这样可以保证编译PaddlePaddle的时候更加顺畅。
### 编译OpenBLAS
```
git clone https://github.com/xianyi/OpenBLAS.git
make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-gnueabihf-gcc NOFORTRAN=1 USE_THREAD=0
```
### 编译protobuf
```
git clone https://github.com/google/protobuf.git
git checkout 9f75c5aa851cd877fb0d93ccc31b8567a6706546
cmake ../protobuf/cmake \
-Dprotobuf_BUILD_TESTS=OFF \
-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \
-DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib
```
注意:这样编译出来的`libprotobuf.a`和`protoc`都是ARM版本的,而我们需要的是一个x86-64版本的`protoc`,所以需要用host gcc再编译一遍protobuf然后使用其中的`protoc`。
## 编译PaddlePaddle
cmake参数如下;其中`WITH_C_API`设置为ON,编译输出的output目录会中包含`include`和`lib`目录,其中`include`中包含CAPI的头文件,`lib`中包含一个ARM版本的库。另外,`CMAKE_BUILD_TYPE`设置为`MinSizeRel`可以减小编译的库的大小。
```
cmake .. -DWITH_GPU=OFF -DWITH_C_API=ON -DWITH_PYTHON=OFF -DWITH_SWIG_PY=OFF \
-DCMAKE_CXX_COMPILER:FILEPATH=arm-linux-gnueabihf-g++ \
-DCMAKE_C_COMPILER:FILEPATH=arm-linux-gnueabihf-gcc \
-DCMAKE_C_FLAGS="-mfpu=neon" \
-DCMAKE_CXX_FLAGS="-mfpu=neon" \
-DOPENBLAS_ROOT=openblas \
-DCMAKE_PREFIX_PATH=protobuf \
-DCMAKE_BUILD_TYPE=MinSizeRel
```
因为 它太大了无法显示 source diff 。你可以改为 查看blob
# 构建Android平台上的PaddlePaddle库
用户可通过交叉编译的方式,在用户熟悉的开发平台(Linux,Mac OS X和Windows)上编译Android平台上适用的PaddlePaddle库。
本文档将以Linux x86-64平台为例,介绍交叉编译Android平台上适用的PaddlePaddle库的方法和步骤。
## 准备交叉编译环境
从源码交叉编译PaddlePaddle,用户需要提前准备好交叉编译环境。Android平台上使用的C/C++交叉编译工具链为[Android NDK](https://developer.android.com/ndk/downloads/index.html?hl=zh-cn),用户可自行前往下载预编译好的版本,也可通过以下命令获取:
```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中包含了所有Android API级别、所有架构(arm/arm64/x86/mips)需要用到的编译工具和系统库。用户可根据自己的编译目标架构、所需支持的最低Android API级别,构建[独立工具链](https://developer.android.google.cn/ndk/guides/standalone_toolchain.html?hl=zh-cn)。
比如:
```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/my_standalone_toolchain
```
此命令将在your/path/to/my_standalone_toolchain目录生成一套编译工具链,面向架构为32位ARM架构,支持的最小的Android API级别为21,使用的编译器为arm-linux-androideabi-gcc (GCC) 4.9。
注意:**PaddlePaddle要求使用的编译工具链所支持的Andoid API级别不小于21**。
## 配置交叉编译参数
CMake系统对交叉编译提供了支持[cmake-toolchains](https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling)。为了简化cmake配置,PaddlePaddle为交叉编译提供了工具链配置文档[cmake/cross_compiling/android.cmake](https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake),以提供一些默认的编译器和编译参数相关配置。注意,从CMake 3.7版本开始,CMake官方对Android平台的交叉编译提供了通用的支持。PaddlePaddle若检测到用户使用的CMake版本不低于3.7时,将会将用户传进来的配置参数传递CMake系统,交由CMake系统本身来处理。有关参数配置的详细说明见[cmake-toolchains](https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling)。
交叉编译Android版本的PaddlePaddle库时,有一些必须配置的参数:
- `CMAKE_SYSTEM_NAME`,CMake编译的目标平台,必须设置为`Android`。在设置`CMAKE_SYSTEM_NAME=Android`后,PaddlePaddle的CMake系统才认为是在交叉编译Android系统的版本,并自动编译宿主机版protoc可执行文件、目标机版protobuf库、以及Android所需`arm_soft_fp_abi`分支的目标机版OpenBLAS库。此外,还会强制设置一些PaddlePaddle参数的值(`WITH_GPU=OFF`、`WITH_AVX=OFF`、`WITH_PYTHON=OFF`、`WITH_RDMA=OFF`)。
- `WITH_C_API`,必须设置为`ON`。在Android平台上只支持使用C-API来预测。
- `WITH_SWIG_PY`,必须设置为`OFF`。在Android平台上不支持通过swig调用来训练或者预测。
Android平台可选配置参数:
- `ANDROID_STANDALONE_TOOLCHAIN`,独立工具链所在的绝对路径,或者相对于构建目录的相对路径。PaddlePaddle的CMake系统将根据该值自动推导和设置需要使用的交叉编译器、sysroot、以及Android API级别;否则,用户需要在cmake时手动设置这些值。无默认值。
- `ANDROID_ABI`,目标架构ABI。目前只支持`armeabi-v7a`,默认值为`armeabi-v7a`。
- `ANDROID_NATIVE_API_LEVEL`,工具链的Android API级别。若没有显式设置,PaddlePaddle将根据`ANDROID_STANDALONE_TOOLCHAIN`的值自动推导得到。
- `ANROID_ARM_MODE`,是否使用ARM模式。可设置`ON/OFF`,默认值为`ON`。
- `ANDROID_ARM_NEON`,是否使用NEON指令。目前必须设置成`ON`,默认值为`ON`。
其他配置参数:
- `HOST_C/CXX_COMPILER`,宿主机的C/C++编译器。在编译宿主机版protoc可执行文件和目标机版OpenBLAS库时需要用到。默认设置成环境变量`CC`的值;若环境变量`CC`没有设置,则设置成`cc`编译器。
一种常用的cmake配置如下:
```bash
cmake -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_STANDALONE_TOOLCHAIN=your/path/to/my_standalone_toolchain \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_ARM_NEON=ON \
-DANDROID_ARM_MODE=ON \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_SWIG_PY=OFF \
..
```
用户还可根据自己的需求设置其他编译参数。比如希望最小化生成的库的大小,可以设置`CMAKE_BUILD_TYPE`为`MinSizeRel`;若希望最快的执行速度,则可设置`CMAKE_BUILD_TYPE`为`Release`。亦可以通过手动设置`CMAKE_C/CXX_FLAGS_MINSIZEREL/RELEASE`来影响PaddlePaddle的编译过程。
## 编译和安装
CMake配置完成后,执行以下命令,PaddlePaddle将自动下载和编译所有第三方依赖库、编译和安装PaddlePaddle预测库。
```bash
make
make install
```
注意:如果你曾经在源码目录下编译过其他平台的PaddlePaddle库,请先使用`rm -rf`命令删除`third_party`目录和`build`目录,以确保所有的第三方依赖库和PaddlePaddle代码都是针对新的CMake配置重新编译的。
执行完安装命令后,`your/path/to/install`目录中会包含`include`和`lib`目录,其中`include`中包含C-API的头文件,`lib`中包含一个Android版本的库。自此,PaddlePaddle的已经安装完成,用户可将`your/path/to/install`目录下的生成文件用于深度学习相关Android App中,调用方法见C-API文档。
# 构建Raspberry Pi平台上的PaddlePaddle库
对于Rasspberry Pi系统,用户可通过ssh等方式登录到Raspberry Pi系统上,按照[源码编译PaddlePaddle](http://www.paddlepaddle.org/doc_cn/getstarted/build_and_install/cmake/build_from_source_cn.html)相关文档所述,直接编译Raspberry Pi平台上适用的PaddlePaddle库。
用户也可以在自己熟悉的开发平台上,通过交叉编译的方式来编译。这篇文档将以Linux x86-64平台为例,介绍交叉编译Raspberry Pi平台上适用的PaddlePaddle的方法和步骤。
## 准备交叉编译环境
从源码交叉编译PaddlePaddle,用户需要提前准备好交叉编译环境。用户可自行前往[github](https://github.com/raspberrypi/tools)下载Raspberry Pi平台使用的C/C++交叉编译工具链,也可通过以下命令获取:
```bash
git clone https://github.com/raspberrypi/tools.git
```
该github仓库中包含若干个预编译好的、针对不同平台的编译工具。宿主机是Linux x86-64环境,则需选用`arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64`下的作为编译工具,所使用的编译器为arm-linux-gnueabihf-gcc 4.8.3。
注意,该编译工具链需要系统glibc支持2.14以上。
## 配置交叉编译参数
CMake系统对交叉编译提供了支持[cmake-toolchains](https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling)。为了简化cmake配置,PaddlePaddle为交叉编译提供了工具链配置文档[cmake/cross_compiling/raspberry_pi.cmake](https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/raspberry_pi.cmake),以提供一些默认的编译器和编译参数相关配置。
交叉编译Raspberry Pi版本PaddlePaddle库时,有一些必须配置的参数:
- `CMAKE_SYSTEM_NAME`,CMake编译的目标平台,必须配置为`RPi`。在设置`CMAKE_SYSTEM_NAME=RPi`后,PaddlePaddle的CMake系统才认为在是在交叉编译Raspberry Pi系统的版本,并自动编译宿主机版protoc可执行文件、目标机版protobuf库、以及目标机版OpenBLAS库。
Raspberry Pi平台可选配置参数:
- `RPI_TOOLCHAIN`,编译工具链所在的绝对路径,或者相对于构建目录的相对路径。PaddlePaddle的CMake系统将根据该值自动设置需要使用的交叉编译器;否则,用户需要在cmake时手动设置这些值。无默认值。
- `RPI_ARM_NEON`,是否使用NEON指令。目前必须设置成`ON`,默认值为`ON`。
其他配置参数:
- `HOST_C/CXX_COMPILER`,宿主机的C/C++编译器。在编译宿主机版protoc可执行文件和目标机版OpenBLAS库时需要用到。默认设置成环境变量`CC`的值;若环境变量`CC`没有设置,则设置成`cc`编译器。
cmake参数如下;
```
cmake -DCMAKE_SYSTEM_NAME=RPi \
-DRPI_TOOLCHAIN=your/path/to/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64 \
-DRPI_ARM_NEON=ON \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_GPU=OFF \
-DWITH_C_API=ON \
-DWITH_PYTHON=OFF \
-DWITH_SWIG_PY=OFF \
..
```
用户还可根据自己的需求设置其他编译参数。比如希望最小化生成的库的大小,可以设置`CMAKE_BUILD_TYPE`为`MinSizeRel`;若希望最快的执行速度,则可设置`CMAKE_BUILD_TYPE`为`Release`。亦可以通过手动设置`CMAKE_C/CXX_FLAGS_MINSIZEREL/RELEASE`来影响PaddlePaddle的编译过程。
## 编译和安装
CMake配置完成后,执行以下命令,PaddlePaddle将自动下载和编译所有第三方依赖库、编译和安装PaddlePaddle。
```bash
make
make install
```
注意:如果你曾经在源码目录下编译过其他平台的PaddlePaddle库,请先使用`rm -rf`命令删除`third_party`目录和`build`目录,以确保所有的第三方依赖库和PaddlePaddle代码都是针对新的CMake配置重新编译的。
执行完安装命令后,由于上一步cmake配置中`WITH_C_API`设置为`ON`,`your/path/to/install`目录中会包含`include`和`lib`目录,其中`include`中包含C-API的头文件,`lib`中包含一个Raspberry Pi版本的库。
更多的编译配置见[源码编译PaddlePaddle](http://www.paddlepaddle.org/doc_cn/getstarted/build_and_install/cmake/build_from_source_cn.html)相关文档。
# 如何构建Raspberry pi下运行的PaddlePaddle
这里考虑的是交叉编译方式,即在Linux-x86环境下构建Raspberry pi下可运行的PaddlePaddle。
## 下载交叉编译环境
```
git clone https://github.com/raspberrypi/tools
```
如果host是x86-64环境,选用`arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64`下的作为编译工具。注意,需要系统glibc支持2.14以上。
## 编译第三方库
cmake编译PaddlePaddle时候会自动下载编译依赖的第三方库,不过openblas和protobuf最好还是在编译PaddlePaddle之前先编译好,这样可以保证编译PaddlePaddle的时候更加顺畅。
### 编译OpenBLAS
```
git clone https://github.com/xianyi/OpenBLAS.git
make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-gnueabihf-gcc NOFORTRAN=1 USE_THREAD=0
```
### 编译protobuf
```
git clone https://github.com/google/protobuf.git
git checkout 9f75c5aa851cd877fb0d93ccc31b8567a6706546
cmake ../protobuf/cmake \
-Dprotobuf_BUILD_TESTS=OFF \
-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \
-DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib
```
注意:这样编译出来的`libprotobuf.a`和`protoc`都是ARM版本的,而我们需要的是一个x86-64版本的`protoc`,所以需要用host gcc再编译一遍protobuf然后使用其中的`protoc`。
## 编译PaddlePaddle
cmake参数如下;其中`WITH_C_API`设置为ON,编译输出的output目录会中包含`include`和`lib`目录,其中`include`中包含CAPI的头文件,`lib`中包含一个ARM版本的库。另外,`CMAKE_BUILD_TYPE`设置为`MinSizeRel`可以减小编译的库的大小。
```
cmake .. -DWITH_GPU=OFF -DWITH_C_API=ON -DWITH_PYTHON=OFF -DWITH_SWIG_PY=OFF \
-DCMAKE_CXX_COMPILER:FILEPATH=arm-linux-gnueabihf-g++ \
-DCMAKE_C_COMPILER:FILEPATH=arm-linux-gnueabihf-gcc \
-DCMAKE_C_FLAGS="-mfpu=neon" \
-DCMAKE_CXX_FLAGS="-mfpu=neon" \
-DOPENBLAS_ROOT=openblas \
-DCMAKE_PREFIX_PATH=protobuf \
-DCMAKE_BUILD_TYPE=MinSizeRel
```
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>如何构建Raspberry pi下运行的PaddlePaddle &mdash; PaddlePaddle documentation</title>
<title>构建Android平台上的PaddlePaddle库 &mdash; PaddlePaddle 文档</title>
......@@ -29,10 +29,10 @@
<link rel="index" title="Index"
<link rel="index" title="索引"
href="../../genindex.html"/>
<link rel="search" title="Search" href="../../search.html"/>
<link rel="top" title="PaddlePaddle documentation" href="../../index.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" />
......@@ -81,10 +81,10 @@
<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>
<li class="toctree-l1"><a class="reference internal" href="../../about/index_en.html">ABOUT</a></li>
<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>
......@@ -106,33 +106,40 @@
<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/ubuntu_install_en.html">Debian Package installation guide</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>
<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/ubuntu_install_cn.html">Ubuntu部署PaddlePaddle</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_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>
<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_en.html">Run 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/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></li>
<li class="toctree-l2"><a class="reference internal" href="../optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_cn.html">运行分布式训练</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/write_docs_cn.html">如何贡献/修改文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev/contribute_to_paddle_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/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-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-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>
......@@ -142,11 +149,11 @@
<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>
<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="../../about/index_en.html">ABOUT</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index_cn.html">FAQ</a></li>
</ul>
......@@ -167,7 +174,7 @@
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li>如何构建Raspberry pi下运行的PaddlePaddle</li>
<li>构建Android平台上的PaddlePaddle库</li>
</ul>
</div>
......@@ -176,55 +183,70 @@
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="raspberry-pipaddlepaddle">
<span id="raspberry-pipaddlepaddle"></span><h1>如何构建Raspberry pi下运行的PaddlePaddle<a class="headerlink" href="#raspberry-pipaddlepaddle" title="Permalink to this headline"></a></h1>
<p>这里考虑的是交叉编译方式,即在Linux-x86环境下构建Raspberry pi下可运行的PaddlePaddle。</p>
<div class="section" id="androidpaddlepaddle">
<span id="androidpaddlepaddle"></span><h1>构建Android平台上的PaddlePaddle库<a class="headerlink" href="#androidpaddlepaddle" title="永久链接至标题"></a></h1>
<p>用户可通过交叉编译的方式,在用户熟悉的开发平台(Linux,Mac OS X和Windows)上编译Android平台上适用的PaddlePaddle库。
本文档将以Linux x86-64平台为例,介绍交叉编译Android平台上适用的PaddlePaddle库的方法和步骤。</p>
<div class="section" id="">
<span id="id1"></span><h2>下载交叉编译环境<a class="headerlink" href="#" title="Permalink to this headline"></a></h2>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">raspberrypi</span><span class="o">/</span><span class="n">tools</span>
<span id="id1"></span><h2>准备交叉编译环境<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>从源码交叉编译PaddlePaddle,用户需要提前准备好交叉编译环境。Android平台上使用的C/C++交叉编译工具链为<a class="reference external" href="https://developer.android.com/ndk/downloads/index.html?hl=zh-cn">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>如果host是x86-64环境,选用<code class="docutils literal"><span class="pre">arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64</span></code>下的作为编译工具。注意,需要系统glibc支持2.14以上。</p>
</div>
<div class="section" id="">
<span id="id2"></span><h2>编译第三方库<a class="headerlink" href="#" title="Permalink to this headline"></a></h2>
<p>cmake编译PaddlePaddle时候会自动下载编译依赖的第三方库,不过openblas和protobuf最好还是在编译PaddlePaddle之前先编译好,这样可以保证编译PaddlePaddle的时候更加顺畅。</p>
<div class="section" id="openblas">
<span id="openblas"></span><h3>编译OpenBLAS<a class="headerlink" href="#openblas" title="Permalink to this headline"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">xianyi</span><span class="o">/</span><span class="n">OpenBLAS</span><span class="o">.</span><span class="n">git</span>
<span class="n">make</span> <span class="n">TARGET</span><span class="o">=</span><span class="n">ARMV7</span> <span class="n">HOSTCC</span><span class="o">=</span><span class="n">gcc</span> <span class="n">CC</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">gcc</span> <span class="n">NOFORTRAN</span><span class="o">=</span><span class="mi">1</span> <span class="n">USE_THREAD</span><span class="o">=</span><span class="mi">0</span>
<p>Android NDK中包含了所有Android API级别、所有架构(arm/arm64/x86/mips)需要用到的编译工具和系统库。用户可根据自己的编译目标架构、所需支持的最低Android API级别,构建<a class="reference external" href="https://developer.android.google.cn/ndk/guides/standalone_toolchain.html?hl=zh-cn">独立工具链</a>
比如:</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/my_standalone_toolchain
</pre></div>
</div>
<p>此命令将在your/path/to/my_standalone_toolchain目录生成一套编译工具链,面向架构为32位ARM架构,支持的最小的Android API级别为21,使用的编译器为arm-linux-androideabi-gcc (GCC) 4.9。</p>
<p>注意:<strong>PaddlePaddle要求使用的编译工具链所支持的Andoid API级别不小于21</strong></p>
</div>
<div class="section" id="protobuf">
<span id="protobuf"></span><h3>编译protobuf<a class="headerlink" href="#protobuf" title="Permalink to this headline"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">google</span><span class="o">/</span><span class="n">protobuf</span><span class="o">.</span><span class="n">git</span>
<span class="n">git</span> <span class="n">checkout</span> <span class="mi">9</span><span class="n">f75c5aa851cd877fb0d93ccc31b8567a6706546</span>
<span class="n">cmake</span> <span class="o">../</span><span class="n">protobuf</span><span class="o">/</span><span class="n">cmake</span> \
<span class="o">-</span><span class="n">Dprotobuf_BUILD_TESTS</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">-</span><span class="n">DCMAKE_CXX_COMPILER</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">g</span><span class="o">++</span> \
<span class="o">-</span><span class="n">DCMAKE_C_COMPILER</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">gcc</span> \
<span class="o">-</span><span class="n">DCMAKE_POSITION_INDEPENDENT_CODE</span><span class="o">=</span><span class="n">ON</span> \
<span class="o">-</span><span class="n">DCMAKE_BUILD_TYPE</span><span class="o">=</span><span class="n">Release</span> \
<span class="o">-</span><span class="n">DCMAKE_INSTALL_LIBDIR</span><span class="o">=</span><span class="n">lib</span>
<div class="section" id="">
<span id="id2"></span><h2>配置交叉编译参数<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>CMake系统对交叉编译提供了支持<a class="reference external" href="https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling">cmake-toolchains</a>。为了简化cmake配置,PaddlePaddle为交叉编译提供了工具链配置文档<a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/android.cmake">cmake/cross_compiling/android.cmake</a>,以提供一些默认的编译器和编译参数相关配置。注意,从CMake 3.7版本开始,CMake官方对Android平台的交叉编译提供了通用的支持。PaddlePaddle若检测到用户使用的CMake版本不低于3.7时,将会将用户传进来的配置参数传递CMake系统,交由CMake系统本身来处理。有关参数配置的详细说明见<a class="reference external" href="https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling">cmake-toolchains</a></p>
<p>交叉编译Android版本的PaddlePaddle库时,有一些必须配置的参数:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_SYSTEM_NAME</span></code>,CMake编译的目标平台,必须设置为<code class="docutils literal"><span class="pre">Android</span></code>。在设置<code class="docutils literal"><span class="pre">CMAKE_SYSTEM_NAME=Android</span></code>后,PaddlePaddle的CMake系统才认为是在交叉编译Android系统的版本,并自动编译宿主机版protoc可执行文件、目标机版protobuf库、以及Android所需<code class="docutils literal"><span class="pre">arm_soft_fp_abi</span></code>分支的目标机版OpenBLAS库。此外,还会强制设置一些PaddlePaddle参数的值(<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><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>,必须设置为<code class="docutils literal"><span class="pre">ON</span></code>。在Android平台上只支持使用C-API来预测。</li>
<li><code class="docutils literal"><span class="pre">WITH_SWIG_PY</span></code>,必须设置为<code class="docutils literal"><span class="pre">OFF</span></code>。在Android平台上不支持通过swig调用来训练或者预测。</li>
</ul>
<p>Android平台可选配置参数:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">ANDROID_STANDALONE_TOOLCHAIN</span></code>,独立工具链所在的绝对路径,或者相对于构建目录的相对路径。PaddlePaddle的CMake系统将根据该值自动推导和设置需要使用的交叉编译器、sysroot、以及Android API级别;否则,用户需要在cmake时手动设置这些值。无默认值。</li>
<li><code class="docutils literal"><span class="pre">ANDROID_ABI</span></code>,目标架构ABI。目前只支持<code class="docutils literal"><span class="pre">armeabi-v7a</span></code>,默认值为<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>,工具链的Android API级别。若没有显式设置,PaddlePaddle将根据<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>,是否使用ARM模式。可设置<code class="docutils literal"><span class="pre">ON/OFF</span></code>,默认值为<code class="docutils literal"><span class="pre">ON</span></code></li>
<li><code class="docutils literal"><span class="pre">ANDROID_ARM_NEON</span></code>,是否使用NEON指令。目前必须设置成<code class="docutils literal"><span class="pre">ON</span></code>,默认值为<code class="docutils literal"><span class="pre">ON</span></code></li>
</ul>
<p>其他配置参数:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">HOST_C/CXX_COMPILER</span></code>,宿主机的C/C++编译器。在编译宿主机版protoc可执行文件和目标机版OpenBLAS库时需要用到。默认设置成环境变量<code class="docutils literal"><span class="pre">CC</span></code>的值;若环境变量<code class="docutils literal"><span class="pre">CC</span></code>没有设置,则设置成<code class="docutils literal"><span class="pre">cc</span></code>编译器。</li>
</ul>
<p>一种常用的cmake配置如下:</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/my_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>
-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>
<p>注意:这样编译出来的<code class="docutils literal"><span class="pre">libprotobuf.a</span></code><code class="docutils literal"><span class="pre">protoc</span></code>都是ARM版本的,而我们需要的是一个x86-64版本的<code class="docutils literal"><span class="pre">protoc</span></code>,所以需要用host gcc再编译一遍protobuf然后使用其中的<code class="docutils literal"><span class="pre">protoc</span></code></p>
<p>用户还可根据自己的需求设置其他编译参数。比如希望最小化生成的库的大小,可以设置<code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code><code class="docutils literal"><span class="pre">MinSizeRel</span></code>;若希望最快的执行速度,则可设置<code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code><code class="docutils literal"><span class="pre">Release</span></code>。亦可以通过手动设置<code class="docutils literal"><span class="pre">CMAKE_C/CXX_FLAGS_MINSIZEREL/RELEASE</span></code>来影响PaddlePaddle的编译过程</p>
</div>
</div>
<div class="section" id="paddlepaddle">
<span id="paddlepaddle"></span><h2>编译PaddlePaddle<a class="headerlink" href="#paddlepaddle" title="Permalink to this headline"></a></h2>
<p>cmake参数如下;其中<code class="docutils literal"><span class="pre">WITH_C_API</span></code>设置为ON,编译输出的output目录会中包含<code class="docutils literal"><span class="pre">include</span></code><code class="docutils literal"><span class="pre">lib</span></code>目录,其中<code class="docutils literal"><span class="pre">include</span></code>中包含CAPI的头文件,<code class="docutils literal"><span class="pre">lib</span></code>中包含一个ARM版本的库。另外,<code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code>设置为<code class="docutils literal"><span class="pre">MinSizeRel</span></code>可以减小编译的库的大小。</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cmake</span> <span class="o">..</span> <span class="o">-</span><span class="n">DWITH_GPU</span><span class="o">=</span><span class="n">OFF</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_PYTHON</span><span class="o">=</span><span class="n">OFF</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><span class="n">DCMAKE_CXX_COMPILER</span><span class="p">:</span><span class="n">FILEPATH</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">g</span><span class="o">++</span> \
<span class="o">-</span><span class="n">DCMAKE_C_COMPILER</span><span class="p">:</span><span class="n">FILEPATH</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">gcc</span> \
<span class="o">-</span><span class="n">DCMAKE_C_FLAGS</span><span class="o">=</span><span class="s2">&quot;-mfpu=neon&quot;</span> \
<span class="o">-</span><span class="n">DCMAKE_CXX_FLAGS</span><span class="o">=</span><span class="s2">&quot;-mfpu=neon&quot;</span> \
<span class="o">-</span><span class="n">DOPENBLAS_ROOT</span><span class="o">=</span><span class="n">openblas</span> \
<span class="o">-</span><span class="n">DCMAKE_PREFIX_PATH</span><span class="o">=</span><span class="n">protobuf</span> \
<span class="o">-</span><span class="n">DCMAKE_BUILD_TYPE</span><span class="o">=</span><span class="n">MinSizeRel</span>
<div class="section" id="">
<span id="id3"></span><h2>编译和安装<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>CMake配置完成后,执行以下命令,PaddlePaddle将自动下载和编译所有第三方依赖库、编译和安装PaddlePaddle预测库。</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make
make install
</pre></div>
</div>
<p>注意:如果你曾经在源码目录下编译过其他平台的PaddlePaddle库,请先使用<code class="docutils literal"><span class="pre">rm</span> <span class="pre">-rf</span></code>命令删除<code class="docutils literal"><span class="pre">third_party</span></code>目录和<code class="docutils literal"><span class="pre">build</span></code>目录,以确保所有的第三方依赖库和PaddlePaddle代码都是针对新的CMake配置重新编译的。</p>
<p>执行完安装命令后,<code class="docutils literal"><span class="pre">your/path/to/install</span></code>目录中会包含<code class="docutils literal"><span class="pre">include</span></code><code class="docutils literal"><span class="pre">lib</span></code>目录,其中<code class="docutils literal"><span class="pre">include</span></code>中包含C-API的头文件,<code class="docutils literal"><span class="pre">lib</span></code>中包含一个Android版本的库。自此,PaddlePaddle的已经安装完成,用户可将<code class="docutils literal"><span class="pre">your/path/to/install</span></code>目录下的生成文件用于深度学习相关Android App中,调用方法见C-API文档。</p>
</div>
</div>
......@@ -270,7 +292,8 @@
<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/translations.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.0/MathJax.js"></script>
......
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>如何构建Raspberry pi下运行的PaddlePaddle &mdash; PaddlePaddle 文档</title>
<title>构建Raspberry Pi平台上的PaddlePaddle库 &mdash; PaddlePaddle 文档</title>
......@@ -174,7 +174,7 @@
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li>如何构建Raspberry pi下运行的PaddlePaddle</li>
<li>构建Raspberry Pi平台上的PaddlePaddle库</li>
</ul>
</div>
......@@ -184,54 +184,58 @@
<div itemprop="articleBody">
<div class="section" id="raspberry-pipaddlepaddle">
<span id="raspberry-pipaddlepaddle"></span><h1>如何构建Raspberry pi下运行的PaddlePaddle<a class="headerlink" href="#raspberry-pipaddlepaddle" title="永久链接至标题"></a></h1>
<p>这里考虑的是交叉编译方式,即在Linux-x86环境下构建Raspberry pi下可运行的PaddlePaddle。</p>
<span id="raspberry-pipaddlepaddle"></span><h1>构建Raspberry Pi平台上的PaddlePaddle库<a class="headerlink" href="#raspberry-pipaddlepaddle" title="永久链接至标题"></a></h1>
<p>对于Rasspberry Pi系统,用户可通过ssh等方式登录到Raspberry Pi系统上,按照<a class="reference external" href="http://www.paddlepaddle.org/doc_cn/getstarted/build_and_install/cmake/build_from_source_cn.html">源码编译PaddlePaddle</a>相关文档所述,直接编译Raspberry Pi平台上适用的PaddlePaddle库。</p>
<p>用户也可以在自己熟悉的开发平台上,通过交叉编译的方式来编译。这篇文档将以Linux x86-64平台为例,介绍交叉编译Raspberry Pi平台上适用的PaddlePaddle的方法和步骤。</p>
<div class="section" id="">
<span id="id1"></span><h2>下载交叉编译环境<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">raspberrypi</span><span class="o">/</span><span class="n">tools</span>
<span id="id1"></span><h2>准备交叉编译环境<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>从源码交叉编译PaddlePaddle,用户需要提前准备好交叉编译环境。用户可自行前往<a class="reference external" href="https://github.com/raspberrypi/tools">github</a>下载Raspberry Pi平台使用的C/C++交叉编译工具链,也可通过以下命令获取:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git clone https://github.com/raspberrypi/tools.git
</pre></div>
</div>
<p>如果host是x86-64环境,选用<code class="docutils literal"><span class="pre">arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64</span></code>下的作为编译工具。注意,需要系统glibc支持2.14以上。</p>
<p>该github仓库中包含若干个预编译好的、针对不同平台的编译工具。宿主机是Linux x86-64环境,则需选用<code class="docutils literal"><span class="pre">arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64</span></code>下的作为编译工具,所使用的编译器为arm-linux-gnueabihf-gcc 4.8.3。</p>
<p>注意,该编译工具链需要系统glibc支持2.14以上。</p>
</div>
<div class="section" id="">
<span id="id2"></span><h2>编译第三方库<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>cmake编译PaddlePaddle时候会自动下载编译依赖的第三方库,不过openblas和protobuf最好还是在编译PaddlePaddle之前先编译好,这样可以保证编译PaddlePaddle的时候更加顺畅。</p>
<div class="section" id="openblas">
<span id="openblas"></span><h3>编译OpenBLAS<a class="headerlink" href="#openblas" title="永久链接至标题"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">xianyi</span><span class="o">/</span><span class="n">OpenBLAS</span><span class="o">.</span><span class="n">git</span>
<span class="n">make</span> <span class="n">TARGET</span><span class="o">=</span><span class="n">ARMV7</span> <span class="n">HOSTCC</span><span class="o">=</span><span class="n">gcc</span> <span class="n">CC</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">gcc</span> <span class="n">NOFORTRAN</span><span class="o">=</span><span class="mi">1</span> <span class="n">USE_THREAD</span><span class="o">=</span><span class="mi">0</span>
</pre></div>
</div>
</div>
<div class="section" id="protobuf">
<span id="protobuf"></span><h3>编译protobuf<a class="headerlink" href="#protobuf" title="永久链接至标题"></a></h3>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">google</span><span class="o">/</span><span class="n">protobuf</span><span class="o">.</span><span class="n">git</span>
<span class="n">git</span> <span class="n">checkout</span> <span class="mi">9</span><span class="n">f75c5aa851cd877fb0d93ccc31b8567a6706546</span>
<span class="n">cmake</span> <span class="o">../</span><span class="n">protobuf</span><span class="o">/</span><span class="n">cmake</span> \
<span class="o">-</span><span class="n">Dprotobuf_BUILD_TESTS</span><span class="o">=</span><span class="n">OFF</span> \
<span class="o">-</span><span class="n">DCMAKE_CXX_COMPILER</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">g</span><span class="o">++</span> \
<span class="o">-</span><span class="n">DCMAKE_C_COMPILER</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">gcc</span> \
<span class="o">-</span><span class="n">DCMAKE_POSITION_INDEPENDENT_CODE</span><span class="o">=</span><span class="n">ON</span> \
<span class="o">-</span><span class="n">DCMAKE_BUILD_TYPE</span><span class="o">=</span><span class="n">Release</span> \
<span class="o">-</span><span class="n">DCMAKE_INSTALL_LIBDIR</span><span class="o">=</span><span class="n">lib</span>
<span id="id2"></span><h2>配置交叉编译参数<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>CMake系统对交叉编译提供了支持<a class="reference external" href="https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling">cmake-toolchains</a>。为了简化cmake配置,PaddlePaddle为交叉编译提供了工具链配置文档<a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/raspberry_pi.cmake">cmake/cross_compiling/raspberry_pi.cmake</a>,以提供一些默认的编译器和编译参数相关配置。</p>
<p>交叉编译Raspberry Pi版本PaddlePaddle库时,有一些必须配置的参数:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">CMAKE_SYSTEM_NAME</span></code>,CMake编译的目标平台,必须配置为<code class="docutils literal"><span class="pre">RPi</span></code>。在设置<code class="docutils literal"><span class="pre">CMAKE_SYSTEM_NAME=RPi</span></code>后,PaddlePaddle的CMake系统才认为在是在交叉编译Raspberry Pi系统的版本,并自动编译宿主机版protoc可执行文件、目标机版protobuf库、以及目标机版OpenBLAS库。</li>
</ul>
<p>Raspberry Pi平台可选配置参数:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">RPI_TOOLCHAIN</span></code>,编译工具链所在的绝对路径,或者相对于构建目录的相对路径。PaddlePaddle的CMake系统将根据该值自动设置需要使用的交叉编译器;否则,用户需要在cmake时手动设置这些值。无默认值。</li>
<li><code class="docutils literal"><span class="pre">RPI_ARM_NEON</span></code>,是否使用NEON指令。目前必须设置成<code class="docutils literal"><span class="pre">ON</span></code>,默认值为<code class="docutils literal"><span class="pre">ON</span></code></li>
</ul>
<p>其他配置参数:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">HOST_C/CXX_COMPILER</span></code>,宿主机的C/C++编译器。在编译宿主机版protoc可执行文件和目标机版OpenBLAS库时需要用到。默认设置成环境变量<code class="docutils literal"><span class="pre">CC</span></code>的值;若环境变量<code class="docutils literal"><span class="pre">CC</span></code>没有设置,则设置成<code class="docutils literal"><span class="pre">cc</span></code>编译器。</li>
</ul>
<p>cmake参数如下;</p>
<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">RPi</span> \
<span class="o">-</span><span class="n">DRPI_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">arm</span><span class="o">-</span><span class="n">bcm2708</span><span class="o">/</span><span class="n">gcc</span><span class="o">-</span><span class="n">linaro</span><span class="o">-</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">raspbian</span><span class="o">-</span><span class="n">x64</span> \
<span class="o">-</span><span class="n">DRPI_ARM_NEON</span><span class="o">=</span><span class="n">ON</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_GPU</span><span class="o">=</span><span class="n">OFF</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_PYTHON</span><span class="o">=</span><span class="n">OFF</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>注意:这样编译出来的<code class="docutils literal"><span class="pre">libprotobuf.a</span></code><code class="docutils literal"><span class="pre">protoc</span></code>都是ARM版本的,而我们需要的是一个x86-64版本的<code class="docutils literal"><span class="pre">protoc</span></code>,所以需要用host gcc再编译一遍protobuf然后使用其中的<code class="docutils literal"><span class="pre">protoc</span></code></p>
<p>用户还可根据自己的需求设置其他编译参数。比如希望最小化生成的库的大小,可以设置<code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code><code class="docutils literal"><span class="pre">MinSizeRel</span></code>;若希望最快的执行速度,则可设置<code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code><code class="docutils literal"><span class="pre">Release</span></code>。亦可以通过手动设置<code class="docutils literal"><span class="pre">CMAKE_C/CXX_FLAGS_MINSIZEREL/RELEASE</span></code>来影响PaddlePaddle的编译过程</p>
</div>
</div>
<div class="section" id="paddlepaddle">
<span id="paddlepaddle"></span><h2>编译PaddlePaddle<a class="headerlink" href="#paddlepaddle" title="永久链接至标题"></a></h2>
<p>cmake参数如下;其中<code class="docutils literal"><span class="pre">WITH_C_API</span></code>设置为ON,编译输出的output目录会中包含<code class="docutils literal"><span class="pre">include</span></code><code class="docutils literal"><span class="pre">lib</span></code>目录,其中<code class="docutils literal"><span class="pre">include</span></code>中包含CAPI的头文件,<code class="docutils literal"><span class="pre">lib</span></code>中包含一个ARM版本的库。另外,<code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code>设置为<code class="docutils literal"><span class="pre">MinSizeRel</span></code>可以减小编译的库的大小。</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cmake</span> <span class="o">..</span> <span class="o">-</span><span class="n">DWITH_GPU</span><span class="o">=</span><span class="n">OFF</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_PYTHON</span><span class="o">=</span><span class="n">OFF</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><span class="n">DCMAKE_CXX_COMPILER</span><span class="p">:</span><span class="n">FILEPATH</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">g</span><span class="o">++</span> \
<span class="o">-</span><span class="n">DCMAKE_C_COMPILER</span><span class="p">:</span><span class="n">FILEPATH</span><span class="o">=</span><span class="n">arm</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnueabihf</span><span class="o">-</span><span class="n">gcc</span> \
<span class="o">-</span><span class="n">DCMAKE_C_FLAGS</span><span class="o">=</span><span class="s2">&quot;-mfpu=neon&quot;</span> \
<span class="o">-</span><span class="n">DCMAKE_CXX_FLAGS</span><span class="o">=</span><span class="s2">&quot;-mfpu=neon&quot;</span> \
<span class="o">-</span><span class="n">DOPENBLAS_ROOT</span><span class="o">=</span><span class="n">openblas</span> \
<span class="o">-</span><span class="n">DCMAKE_PREFIX_PATH</span><span class="o">=</span><span class="n">protobuf</span> \
<span class="o">-</span><span class="n">DCMAKE_BUILD_TYPE</span><span class="o">=</span><span class="n">MinSizeRel</span>
<div class="section" id="">
<span id="id3"></span><h2>编译和安装<a class="headerlink" href="#" title="永久链接至标题"></a></h2>
<p>CMake配置完成后,执行以下命令,PaddlePaddle将自动下载和编译所有第三方依赖库、编译和安装PaddlePaddle。</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make
make install
</pre></div>
</div>
<p>注意:如果你曾经在源码目录下编译过其他平台的PaddlePaddle库,请先使用<code class="docutils literal"><span class="pre">rm</span> <span class="pre">-rf</span></code>命令删除<code class="docutils literal"><span class="pre">third_party</span></code>目录和<code class="docutils literal"><span class="pre">build</span></code>目录,以确保所有的第三方依赖库和PaddlePaddle代码都是针对新的CMake配置重新编译的。</p>
<p>执行完安装命令后,由于上一步cmake配置中<code class="docutils literal"><span class="pre">WITH_C_API</span></code>设置为<code class="docutils literal"><span class="pre">ON</span></code><code class="docutils literal"><span class="pre">your/path/to/install</span></code>目录中会包含<code class="docutils literal"><span class="pre">include</span></code><code class="docutils literal"><span class="pre">lib</span></code>目录,其中<code class="docutils literal"><span class="pre">include</span></code>中包含C-API的头文件,<code class="docutils literal"><span class="pre">lib</span></code>中包含一个Raspberry Pi版本的库。</p>
<p>更多的编译配置见<a class="reference external" href="http://www.paddlepaddle.org/doc_cn/getstarted/build_and_install/cmake/build_from_source_cn.html">源码编译PaddlePaddle</a>相关文档。</p>
</div>
</div>
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册