COMPILE.md 6.4 KB
Newer Older
J
Jiawei Wang 已提交
1
# How to compile PaddleServing
D
Dong Daxiang 已提交
2

J
Jiawei Wang 已提交
3 4 5
([简体中文](./COMPILE_CN.md)|English)

## Compilation environment requirements
B
barrierye 已提交
6

B
barrierye 已提交
7 8 9 10 11
- OS: CentOS 7
- GCC: 4.8.2 and later
- Golang: 1.9.2 and later
- Git:2.17.1 and later
- CMake:3.2.2 and later
M
MRXLT 已提交
12
- Python:2.7.2 and later / 3.6 and later
D
Dong Daxiang 已提交
13

B
barrierye 已提交
14 15
It is recommended to use Docker for compilation. We have prepared the Paddle Serving compilation environment for you: 

B
barrierye 已提交
16 17
- CPU: `hub.baidubce.com/paddlepaddle/serving:latest-devel`,dockerfile: [Dockerfile.devel](../tools/Dockerfile.devel)
- GPU: `hub.baidubce.com/paddlepaddle/serving:latest-gpu-devel`,dockerfile: [Dockerfile.gpu.devel](../tools/Dockerfile.gpu.devel)
B
barrierye 已提交
18

B
barrierye 已提交
19 20 21 22 23
This document will take Python2 as an example to show how to compile Paddle Serving. If you want to compile with Python3, just adjust the Python options of cmake:

- Set `DPYTHON_INCLUDE_DIR` to `$PYTHONROOT/include/python3.6m/`
- Set  `DPYTHON_LIBRARIES` to `$PYTHONROOT/lib64/libpython3.6.so`
- Set `DPYTHON_EXECUTABLE` to `$PYTHONROOT/bin/python3`
B
barrierye 已提交
24

J
Jiawei Wang 已提交
25
## Get Code
D
Dong Daxiang 已提交
26 27 28

``` python
git clone https://github.com/PaddlePaddle/Serving
29
cd Serving && git submodule update --init --recursive
D
Dong Daxiang 已提交
30 31
```

J
Jiawei Wang 已提交
32
## PYTHONROOT Setting
D
Dong Daxiang 已提交
33

B
barrierye 已提交
34
```shell
J
Jiawei Wang 已提交
35
# for example, the path of python is /usr/bin/python, you can set /usr as PYTHONROOT
D
Dong Daxiang 已提交
36 37 38
export PYTHONROOT=/usr/
```

J
Jiawei Wang 已提交
39
## Compile Server
B
barrierye 已提交
40

J
Jiawei Wang 已提交
41
### Integrated CPU version paddle inference library
B
barrierye 已提交
42

D
Dong Daxiang 已提交
43
``` shell
B
barrierye 已提交
44 45
mkdir build && cd build
cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python -DSERVER=ON ..
D
Dong Daxiang 已提交
46 47 48
make -j10
```

J
Jiawei Wang 已提交
49
you can execute `make install` to put targets under directory `./output`, you need to add`-DCMAKE_INSTALL_PREFIX=./output`to specify output path to cmake command shown above.
B
barrierye 已提交
50

J
Jiawei Wang 已提交
51
### Integrated GPU version paddle inference library
B
barrierye 已提交
52

D
Dong Daxiang 已提交
53
``` shell
B
barrierye 已提交
54 55
mkdir build && cd build
cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python -DSERVER=ON -DWITH_GPU=ON ..
D
Dong Daxiang 已提交
56 57 58
make -j10
```

J
Jiawei Wang 已提交
59
execute `make install` to put targets under directory `./output`
B
barrierye 已提交
60

B
barrierye 已提交
61
**Attention:** After the compilation is successful, you need to set the path of `SERVING_BIN`. See [Note](https://github.com/PaddlePaddle/Serving/blob/develop/doc/COMPILE.md#Note) for details.
M
MRXLT 已提交
62

J
Jiawei Wang 已提交
63
## Compile Client
D
Dong Daxiang 已提交
64 65

``` shell
B
barrierye 已提交
66 67
mkdir build && cd build
cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python -DCLIENT=ON ..
D
Dong Daxiang 已提交
68 69
make -j10
```
D
Dong Daxiang 已提交
70

J
Jiawei Wang 已提交
71
execute `make install` to put targets under directory `./output`
B
barrierye 已提交
72

J
Jiawei Wang 已提交
73
## Compile the App
B
barrierye 已提交
74 75 76

```bash
mkdir build && cd build
77
cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python -DAPP=ON ..
B
barrierye 已提交
78 79 80
make
```

J
Jiawei Wang 已提交
81 82 83
## Install wheel package

Regardless of the client, server or App part, after compiling, install the whl package under `python/dist/`.
B
barrierye 已提交
84

J
Jiawei Wang 已提交
85
## Note
B
barrierye 已提交
86

J
Jiawei Wang 已提交
87
When running the python server, it will check the `SERVING_BIN` environment variable. If you want to use your own compiled binary file, set the environment variable to the path of the corresponding binary file, usually`export SERVING_BIN=${BUILD_DIR}/core/general-server/serving`.
B
barrierye 已提交
88

89

J
Jiawei Wang 已提交
90
## CMake Option Description
B
barrierye 已提交
91

J
Jiawei Wang 已提交
92
| Compile Options  |                    Description             | Default |
B
barrierye 已提交
93 94 95 96 97 98 99 100 101 102 103
| :--------------: | :----------------------------------------: | :--: |
|     WITH_AVX     | Compile Paddle Serving with AVX intrinsics | OFF  |
|     WITH_MKL     |  Compile Paddle Serving with MKL support   | OFF  |
|     WITH_GPU     |   Compile Paddle Serving with NVIDIA GPU   | OFF  |
|    CUDNN_ROOT    |    Define CuDNN library and header path    |      |
|      CLIENT      |       Compile Paddle Serving Client        | OFF  |
|      SERVER      |       Compile Paddle Serving Server        | OFF  |
|       APP        |     Compile Paddle Serving App package     | OFF  |
| WITH_ELASTIC_CTR |        Compile ELASITC-CTR solution        | OFF  |
|       PACK       |              Compile for whl               | OFF  |

J
Jiawei Wang 已提交
104
### WITH_GPU Option
B
barrierye 已提交
105

J
Jiawei Wang 已提交
106
Paddle Serving supports prediction on the GPU through the PaddlePaddle inference library. The WITH_GPU option is used to detect basic libraries such as CUDA/CUDNN on the system. If an appropriate version is detected, the GPU Kernel will be compiled when PaddlePaddle is compiled.
B
barrierye 已提交
107

J
Jiawei Wang 已提交
108
To compile the Paddle Serving GPU version on bare metal, you need to install these basic libraries:
B
barrierye 已提交
109 110 111 112 113

- CUDA
- CuDNN
- NCCL2

J
Jiawei Wang 已提交
114 115 116 117
Note here:

1. The basic library versions such as CUDA/CUDNN installed on the system where Serving is compiled, needs to be compatible with the actual GPU device. For example, the Tesla V100 card requires at least CUDA 9.0. If the version of the basic library such as CUDA used during compilation is too low, the generated GPU code is not compatible with the actual hardware device, which will cause the Serving process to fail to start or serious problems such as coredump.
2. Install the CUDA driver compatible with the actual GPU device on the system running Paddle Serving, and install the basic library compatible with the CUDA/CuDNN version used during compilation. If the version of CUDA/CuDNN installed on the system running Paddle Serving is lower than the version used at compile time, it may cause some cuda function call failures and other problems.
B
barrierye 已提交
118 119


J
Jiawei Wang 已提交
120
The following is the base library version matching relationship used by the PaddlePaddle release version for reference:
B
barrierye 已提交
121 122 123 124 125 126

|        |  CUDA   |          CuDNN           | NCCL2  |
| :----: | :-----: | :----------------------: | :----: |
| CUDA 8 | 8.0.61  | CuDNN 7.1.2 for CUDA 8.0 | 2.1.4  |
| CUDA 9 | 9.0.176 | CuDNN 7.3.1 for CUDA 9.0 | 2.2.12 |

J
Jiawei Wang 已提交
127
### How to make the compiler detect the CuDNN library
B
barrierye 已提交
128

J
Jiawei Wang 已提交
129
Download the corresponding CUDNN version from NVIDIA developer official website and decompressing it, add `-DCUDNN_ROOT` to cmake command, to specify the path of CUDNN.
B
barrierye 已提交
130

J
Jiawei Wang 已提交
131
### How to make the compiler detect the nccl library
B
barrierye 已提交
132

J
Jiawei Wang 已提交
133
After downloading the corresponding version of the nccl2 library from the NVIDIA developer official website and decompressing it, add the following environment variables (take nccl2.1.4 as an example):
B
barrierye 已提交
134 135 136 137 138 139

```shell
export C_INCLUDE_PATH=/path/to/nccl2/cuda8/nccl_2.1.4-1+cuda8.0_x86_64/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/path/to/nccl2/cuda8/nccl_2.1.4-1+cuda8.0_x86_64/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=/path/to/nccl2/cuda8/nccl_2.1.4-1+cuda8.0_x86_64/lib/:$LD_LIBRARY_PATH
```