Skip to content

Commit ec69768

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into multigpumultinode
2 parents ce08dc8 + 7ed457e commit ec69768

File tree

17 files changed

+235
-23
lines changed

17 files changed

+235
-23
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.

paddle/fluid/framework/parallel_executor.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,17 @@ void ParallelExecutor::SplitTensorToPlaces(
174174
const std::unordered_map<std::string, LoDTensor> &feed_tensors) {
175175
for (auto it : feed_tensors) {
176176
auto lod_tensors = it.second.SplitLoDTensor(member_->places_);
177+
PADDLE_ENFORCE_EQ(
178+
member_->places_.size(), lod_tensors.size(),
179+
"The number of samples of current batch is less than the count of "
180+
"devices, currently, it is not allowed. (%d vs %d)",
181+
member_->places_.size(), lod_tensors.size());
177182
for (size_t j = 0; j < member_->places_.size(); ++j) {
178183
// TODO(panxy0718): Do I need to delete this var?
179-
member_->local_scopes_[j]
180-
->Var(it.first)
181-
->GetMutable<LoDTensor>()
182-
->ShareDataWith(lod_tensors[j]);
184+
auto t =
185+
member_->local_scopes_[j]->Var(it.first)->GetMutable<LoDTensor>();
186+
t->ShareDataWith(lod_tensors[j]);
187+
t->set_lod(lod_tensors[j].lod());
183188
}
184189
}
185190
}

paddle/fluid/operators/batch_norm_op.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/batch_norm_op.h"
16+
#include <string>
1617
#include "paddle/fluid/framework/data_layout.h"
1718

1819
namespace paddle {

paddle/fluid/operators/batch_norm_op.cu.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/batch_norm_op.h"
16-
#include "paddle/fluid/framework/data_layout.h"
17-
1816
#include <cfloat>
17+
#include "paddle/fluid/framework/data_layout.h"
1918
#include "paddle/fluid/operators/math/math_function.h"
2019
#include "paddle/fluid/platform/cudnn_helper.h"
2120
#include "paddle/fluid/platform/float16.h"

paddle/fluid/operators/batch_size_like.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16-
16+
#include <algorithm>
17+
#include <vector>
1718
#include "paddle/fluid/framework/op_registry.h"
1819
#include "paddle/fluid/operators/math/math_function.h"
1920

paddle/fluid/operators/box_coder_op.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ See the License for the specific language governing permissions and
1010
limitations under the License. */
1111

1212
#pragma once
13+
#include <string>
1314
#include "paddle/fluid/framework/op_registry.h"
1415
#include "paddle/fluid/operators/math/math_function.h"
1516

paddle/fluid/operators/compare_op.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/compare_op.h"
16+
#include <string>
1617
#include "paddle/fluid/framework/op_registry.h"
1718

1819
namespace paddle {

paddle/fluid/operators/concat_op.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/concat_op.h"
16+
#include <string>
1617
#include <vector>
1718

1819
namespace paddle {

paddle/fluid/operators/cond_op.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
#include <string>
1617
#include <vector>
1718
#include "glog/logging.h"
1819
#include "paddle/fluid/framework/ddim.h"

paddle/fluid/operators/conv_transpose_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/conv_transpose_op.h"
16+
#include <string>
17+
#include <vector>
1618

1719
namespace paddle {
1820
namespace operators {

0 commit comments

Comments
 (0)