Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate the iOS build doc #6180

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions doc/mobile/cross_compiling_for_ios_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,19 @@ PaddlePaddle为交叉编译提供了工具链配置文档[cmake/cross_compiling/

- `CMAKE_SYSTEM_NAME`,CMake编译的目标平台,必须设置为`iOS`。在设置`CMAKE_SYSTEM_NAME=iOS`后,PaddlePaddle的CMake系统会自动编译所有的第三方依赖库,并且强制设置一些PaddlePaddle参数的值(`WITH_C_API=ON`、`WITH_GPU=OFF`、`WITH_AVX=OFF`、`WITH_PYTHON=OFF`、`WITH_RDMA=OFF`)。
- `WITH_C_API`,是否编译C-API预测库,必须设置为ON。在iOS平台上只支持使用C-API来预测。
- `WITH_SWIG_PY`,必须设置为ON。在iOS平台上不支持通过swig调用来训练或者预测。
- `WITH_SWIG_PY`,必须设置为OFF。在iOS平台上不支持通过swig调用来训练或者预测。
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for correct the typo.


iOS平台可选配置参数:

- `IOS_PLATFORM`,可设置为`OS/SIMULATOR`,默认值为`OS`。
- `IOS_PLATFORM`,可设置为`OS`或者`SIMULATOR`,默认值为`OS`。
- `OS`,构建目标为`arm`架构的iPhone或者iPad等物理设备。
- `SIMULATOR`,构建目标为`x86`架构的模拟器平台。
- `IOS_ARCH`,目标架构。针对不同的`IOS_PLATFORM`,可设置的目标架构如下表所示,默认编译所有架构:

<table class="docutils">
<colgroup>
<col width="35%" />
<col width="65%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd">
<th class="head">IOS_PLATFORM</th>
<th class="head">IOS_ARCH</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even">
<td>OS</td>
<td>armv7, armv7s, arm64 </td>
</tr>
<tr class="row-odd">
<td>SIMULATOR</td>
<td>i386, x86_64 </td>
</tr>
</tbody>
</table>
| `IOS_PLATFORM` | `IOS_ARCH` |
|----------------|------------|
| `OS` | armv7, armv7s, arm64 |
| `SIMULATOR` | i386, x86_64 |
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't change the html table to markdown table. Markdown table cannot be correctly shown on the website. It is shown as:

image

You can preview the generated documentation as #6014.


- `IOS_DEPLOYMENT_TARGET`,最小的iOS部署版本,默认值为`7.0`。
- `IOS_ENABLE_BITCODE`,是否使能[Bitcode](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html#//apple_ref/doc/uid/TP40012582-CH35-SW3),可设置`ON/OFF`,默认值为`ON`。
Expand Down
132 changes: 132 additions & 0 deletions doc/mobile/cross_compiling_for_ios_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Build PaddlePaddle for iOS
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add cross_compiling_for_ios_en.md to index_en.rst.


The cross-compiling of iOS requires a MacOS system.

## The Build Environment

Please download and install Xcode from App Store on the MacOS system.
After a successful installation, we should be able to run the
following command

```bash
xcodebuild -version
```

## Configure CMake Options

A complete list of CMake options related to iOS is
at
[here](https://github.com/PaddlePaddle/Paddle/blob/develop/cmake/cross_compiling/ios.cmake).

Some of these options are mandatory:

- `CMAKE_SYSTEM_NAME`: The target platform; must be `iOS`. This
setting would automatically trigger some more changes, including
`WITH_C_API=ON`, `WITH_GPU=OFF`, `WITH_AVX=OFF`, `WITH_PYTHON=OFF`,
`WITH_RDMA=OFF`.
- `WITH_C_API`: If build the inference library; must be `ON`, because
that is the only way we support inference on iOS.
- `WITH_SWIG_PY`: Must be `OFF` because we don't support that Python
programs calls into C/C++ programs via SWIG on iOS.

Some optional configurations:

- `IOS_PLATFORM`: could be `OS` or `SIMULATOR`. The default value is `OS`.
- `OS`: the build result is supposed to run on an iPhone or an iPad
with a real ARM CPU.
- `SIMULATOR`: the build result can run on the x86 simulator
provided by Xcode.
- `IOS_ARCH`: the value depends on that of `IOS_PLATFORM`:

| `IOS_PLATFORM` | `IOS_ARCH` |
|----------------|------------|
| `OS` | armv7, armv7s, arm64 |
| `SIMULATOR` | i386, x86_64 |

- `IOS_DEPLOYMENT_TARGET`: The supported minimum iOS version. The
default value is `7.0`.
- `IOS_ENABLE_BITCODE`: If
use
[Bitcode](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html#//apple_ref/doc/uid/TP40012582-CH35-SW3).
The default value is `ON`.
- `IOS_USE_VECLIB_FOR_BLAS`: If
use
[vecLib](https://developer.apple.com/documentation/accelerate/veclib),
a BLAS implementation for iOS. The default value is `OFF`.
- `IOS_DEVELOPMENT_ROOT`: If not specified, PaddlePaddle's build
system will set one according to the value of `IOS_PLATFORM`.
- `IOS_SDK_ROOT`: The iOS SDK directory. If not specified,
PaddlePaddle's build system will choose the most recent version in
the directory of `IOS_DEVELOPMENT_ROOT`.

Other options:

- `USE_EIGEN_FOR_BLAS`: If use Eigen. It is only reasonable to set
this option when `IOS_USE_VECLIB_FOR_BLAS=OFF`.
- `HOST_C/CXX_COMPILER`: The host C/C++ compiler. The default value
is the value of the environment variable `CC/CXX`, or `cc` and `c++`
respectively.


Here follows a commonly-used cmake configuration that builds binaries
for iPhone and iPad:

```bash
cmake -DCMAKE_SYSTEM_NAME=iOS \
-DIOS_PLATFORM=OS \
-DIOS_ARCH="armv7;arm64" \
-DIOS_ENABLE_BITCODE=ON \
-DIOS_USE_VECLIB_FOR_BLAS=ON \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_TESTING=OFF \
-DWITH_SWIG_PY=OFF \
..
```


Here follows another configuration that builds binaries for the
simulator:

```bash
cmake -DCMAKE_SYSTEM_NAME=iOS \
-DIOS_PLATFORM=SIMULATOR \
-DIOS_ARCH="x86_64" \
-DIOS_USE_VECLIB_FOR_BLAS=ON \
-DCMAKE_INSTALL_PREFIX=your/path/to/install \
-DWITH_C_API=ON \
-DWITH_TESTING=OFF \
-DWITH_SWIG_PY=OFF \
..
```

If we want to minimize the size of the generated binary files,we can
set `CMAKE_BUILD_TYPE=MinSizeRel`. Or, if we want to optimize for
runtime performance, we can set `CMAKE_BUILD_TYPE=Release` and/or
`IOS_USE_VECLIB_FOR_BLAS=ON`. We can also set `CMAKE_C/CXX_FLAGS` to
have more control of the building process.


## Build and Install

After the cmake command completes, run the following commands to
download third-party dependencies and build PaddlePaddle:

```
$ make
$ make install
```

Please be aware that if you had been built for other platforms, please
`rm -rf build` so to remove all existing intermediate build results.

After `make install`, you will find the following content in
`your/path/to/install`:

- `include`: the header files of the inference library,
- `lib`: the inference library,
- `third_party`: all built third-party libraries.

We can build a version that supports real iOS hardware and the
simulator, by building the IOS and SIMULATOR version separately, and
merge them using `lipo`.