Skip to content

Commit 3ebc5e1

Browse files
cwgisabhinavarora
authored andcommitted
Update compile_paddle_lib_en.md (#9795)
* Update compile_paddle_lib_en.md Fix #8916 * Update compile_paddle_lib_en.md
1 parent e0babe7 commit 3ebc5e1

File tree

1 file changed

+173
-1
lines changed

1 file changed

+173
-1
lines changed
Lines changed: 173 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,175 @@
11
## Install and Build
22

3-
TBD
3+
### Download & Install
4+
5+
Download the latest C-API development package from CI system and install. You can find the required version in the table below:
6+
<table>
7+
<thead>
8+
<tr>
9+
<th>Version Tips</th>
10+
<th>C-API</th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<tr>
15+
<td>cpu_avx_mkl</td>
16+
<td><a href="https://guest:@paddleci.ngrok.io/repository/download/Manylinux1_CpuAvxCp27cp27mu/.lastSuccessful/paddle.tgz" rel="nofollow">paddle.tgz</a></td>
17+
</tr>
18+
<tr>
19+
<td>cpu_avx_openblas</td>
20+
<td>-</td>
21+
</tr>
22+
<tr>
23+
<td>cpu_noavx_openblas</td>
24+
<td><a href="https://guest:@paddleci.ngrok.io/repository/download/Manylinux1_CpuNoavxOpenblas/.lastSuccessful/paddle.tgz" rel="nofollow">paddle.tgz</a></td>
25+
</tr>
26+
<tr>
27+
<td>cuda7.5_cudnn5_avx_mkl</td>
28+
<td><a href="https://guest:@paddleci.ngrok.io/repository/download/Manylinux1_Cuda75cudnn5cp27cp27mu/.lastSuccessful/paddle.tgz" rel="nofollow">paddle.tgz</a></td>
29+
</tr>
30+
<tr>
31+
<td>cuda8.0_cudnn5_avx_mkl</td>
32+
<td><a href="https://guest:@paddleci.ngrok.io/repository/download/Manylinux1_Cuda80cudnn5cp27cp27mu/.lastSuccessful/paddle.tgz" rel="nofollow">paddle.tgz</a></td>
33+
</tr>
34+
<tr>
35+
<td>cuda8.0_cudnn7_avx_mkl</td>
36+
<td><a href="https://guest:@paddleci.ngrok.io/repository/download/Manylinux1_Cuda8cudnn7cp27cp27mu/.lastSuccessful/paddle.tgz" rel="nofollow">paddle.tgz</a></td>
37+
</tr></tbody></table>
38+
39+
### From source
40+
41+
Users can also compile the C-API library from PaddlePaddle source code by compiling with the following compilation options:
42+
43+
<table>
44+
<thead>
45+
<tr>
46+
<th>Options</th>
47+
<th>Value</th>
48+
</tr>
49+
</thead>
50+
<tbody>
51+
<tr>
52+
<td>WITH_C_API</td>
53+
<td>ON</td>
54+
</tr>
55+
<tr>
56+
<td>WITH_PYTHON</td>
57+
<td>OFF(recommended)</td>
58+
</tr>
59+
<tr>
60+
<td>WITH_SWIG_PY</td>
61+
<td>OFF(recommended)</td>
62+
</tr>
63+
<tr>
64+
<td>WITH_GOLANG</td>
65+
<td>OFF(recommended)</td>
66+
</tr>
67+
<tr>
68+
<td>WITH_GPU</td>
69+
<td>ON/OFF</td>
70+
</tr>
71+
<tr>
72+
<td>WITH_MKL</td>
73+
<td>ON/OFF</td>
74+
</tr></tbody></table>
75+
76+
It is best to set up with recommended values to avoid linking with unnecessary libraries. Set other compilation options as you need.
77+
78+
Pull the latest following code snippet from github, and configure compilation options(replace PADDLE_ROOT with the installation path of the PaddlePaddle C-API inference library):
79+
80+
```shell
81+
PADDLE_ROOT=/path/of/capi
82+
git clone https://github.com/PaddlePaddle/Paddle.git
83+
cd Paddle
84+
mkdir build
85+
cd build
86+
cmake -DCMAKE_INSTALL_PREFIX=$PADDLE_ROOT \
87+
-DCMAKE_BUILD_TYPE=Release \
88+
-DWITH_C_API=ON \
89+
-DWITH_SWIG_PY=OFF \
90+
-DWITH_GOLANG=OFF \
91+
-DWITH_PYTHON=OFF \
92+
-DWITH_MKL=OFF \
93+
-DWITH_GPU=OFF \
94+
..
95+
```
96+
97+
After running the above code to generate Makefile , run: `make && make install`. After successful compilation, the dependencies required by C-API(includes: (1)PaddlePaddle inference library and header files; (2) Third-party libraries and header files) will be stored in the `PADDLE_ROOT` directory.
98+
99+
If the compilation is successful, see the following directory structure under `PADDLE_ROOT`(includes PaddlePaddle header files and libraries, and third-party libraries and header files(determined by the link methods if necessary)):
100+
101+
```text
102+
├── include
103+
│   └── paddle
104+
│   ├── arguments.h
105+
│   ├── capi.h
106+
│   ├── capi_private.h
107+
│   ├── config.h
108+
│   ├── error.h
109+
│   ├── gradient_machine.h
110+
│   ├── main.h
111+
│   ├── matrix.h
112+
│   ├── paddle_capi.map
113+
│   └── vector.h
114+
├── lib
115+
│   ├── libpaddle_capi_engine.a
116+
│   ├── libpaddle_capi_layers.a
117+
│   ├── libpaddle_capi_shared.so
118+
│   └── libpaddle_capi_whole.a
119+
└── third_party
120+
├── gflags
121+
│   ├── include
122+
│   │   └── gflags
123+
│   │   ├── gflags_completions.h
124+
│   │   ├── gflags_declare.h
125+
│   │   ...
126+
│   └── lib
127+
│   └── libgflags.a
128+
├── glog
129+
│   ├── include
130+
│   │   └── glog
131+
│   │   ├── config.h
132+
│   │   ...
133+
│   └── lib
134+
│   └── libglog.a
135+
├── openblas
136+
│   ├── include
137+
│   │   ├── cblas.h
138+
│   │   ...
139+
│   └── lib
140+
│   ...
141+
├── protobuf
142+
│   ├── include
143+
│   │   └── google
144+
│   │   └── protobuf
145+
│   │   ...
146+
│   └── lib
147+
│   └── libprotobuf-lite.a
148+
└── zlib
149+
├── include
150+
│   ...
151+
└── lib
152+
...
153+
154+
```
155+
156+
### Linking Description:
157+
158+
There are three kinds of linking methods:
159+
160+
1. Linking with dynamic library `libpaddle_capi_shared.so`(This way is much more convenient and easier, **Without special requirements, it is recommended**), refer to the following:
161+
1. Compiling with CPU version and using `OpenBLAS`; only need to link one library named `libpaddle_capi_shared.so` to develop prediction program through C-API.
162+
1. Compiling with CPU version and using `MKL` lib, you need to link MKL library directly to develop prediction program through PaddlePaddle C-API, due to `MKL` has its own dynamic library.
163+
1. Compiling with GPU version, CUDA library will be loaded dynamically on prediction program run-time, and also set CUDA library to  `LD_LIBRARY_PATH` environment variable.
164+
165+
2. Linking with static library `libpaddle_capi_whole.a`,refer to the following:
166+
1. Specify `-Wl,--whole-archive` linking options.
167+
1. Explicitly link third-party libraries such as `gflags``glog``libz``protobuf` .etc, you can find them under `PADDLE_ROOT/third_party` directory.
168+
1. Use OpenBLAS library if compiling C-API,must explicitly link `libopenblas.a`.
169+
1. Use MKL when compiling C-API, must explicitly link MKL dynamic library.
170+
171+
3. Linking with static library `libpaddle_capi_layers.a` and `libpaddle_capi_engine.a`,refer to the following:
172+
1. This linking methods is mainly used for mobile prediction.
173+
1. Split `libpaddle_capi_whole.a` into two static linking library at least to reduce the size of linking libraries.
174+
1. Specify `-Wl,--whole-archive -lpaddle_capi_layers`  and `-Wl,--no-whole-archive -lpaddle_capi_engine` for linking.
175+
1. The third-party dependencies need explicitly link same as method 2 above.

0 commit comments

Comments
 (0)