COMPILE.md 11.2 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
|            module            |              version              |
| :--------------------------: | :-------------------------------: |
W
wangjiawei04 已提交
9 10 11
|              OS              |     Ubuntu16 and 18/CentOS 7      |
|             gcc              | 4.8.5(Cuda 9.0 and 10.0) and 8.2(Others) |
|           gcc-c++            | 4.8.5(Cuda 9.0 and 10.0) and 8.2(Others) |
B
barrierye 已提交
12
|            cmake             |          3.2.0 and later          |
W
wangjiawei04 已提交
13
|            Python            |  2.7.2 and later / 3.5.1 and later |
B
barrierye 已提交
14 15 16 17 18 19 20
|              Go              |          1.9.2 and later          |
|             git              |         2.17.1 and later          |
|         glibc-static         |               2.17                |
|        openssl-devel         |              1.0.2k               |
|         bzip2-devel          |          1.0.6 and later          |
| python-devel / python3-devel | 2.7.5 and later / 3.6.8 and later |
|         sqlite-devel         |         3.7.17 and later          |
W
wangjiawei04 已提交
21
|           patchelf           |                0.9                |
B
barrierye 已提交
22 23 24
|           libXext            |               1.3.3               |
|            libSM             |               1.2.2               |
|          libXrender          |              0.9.10               |
D
Dong Daxiang 已提交
25

B
barrierye 已提交
26
It is recommended to use Docker for compilation. We have prepared the Paddle Serving compilation environment for you, see [this document](DOCKER_IMAGES.md).
B
barrierye 已提交
27

J
Jiawei Wang 已提交
28
## Get Code
D
Dong Daxiang 已提交
29 30 31

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

W
wangjiawei04 已提交
35
## PYTHONROOT settings
D
Dong Daxiang 已提交
36

B
barrierye 已提交
37
```shell
W
wangjiawei04 已提交
38 39
# For example, the path of python is /usr/bin/python, you can set PYTHONROOT
export PYTHONROOT=/usr
D
Dong Daxiang 已提交
40 41
```

W
wangjiawei04 已提交
42
If you are using a Docker development image, please follow the following to determine the Python version to be compiled, and set the corresponding environment variables
B
barrierye 已提交
43

W
wangjiawei04 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
```
#Python 2.7
export PYTHONROOT=/usr/local/python2.7.15/
export PYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/
export PYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so
export PYTHON_EXECUTABLE=$PYTHONROOT/bin/python2.7

#Python 3.5
export PYTHONROOT=/usr/local/python3.5.1
export PYTHON_INCLUDE_DIR=$PYTHONROOT/include/python3.5m
export PYTHON_LIBRARIES=$PYTHONROOT/lib/libpython3.5m.so
export PYTHON_EXECUTABLE=$PYTHONROOT/bin/python3.5

#Python3.6
export PYTHONROOT=/usr/local/
export PYTHON_INCLUDE_DIR=$PYTHONROOT/include/python3.6m
export PYTHON_LIBRARIES=$PYTHONROOT/lib/libpython3.6m.so
export PYTHON_EXECUTABLE=$PYTHONROOT/bin/python3.6

#Python3.7
export PYTHONROOT=/usr/local/
export PYTHON_INCLUDE_DIR=$PYTHONROOT/include/python3.7m
export PYTHON_LIBRARIES=$PYTHONROOT/lib/libpython3.7m.so
export PYTHON_EXECUTABLE=$PYTHONROOT/bin/python3.7

#Python3.8
export PYTHONROOT=/usr/local/
export PYTHON_INCLUDE_DIR=$PYTHONROOT/include/python3.8
export PYTHON_LIBRARIES=$PYTHONROOT/lib/libpython3.8.so
export PYTHON_EXECUTABLE=$PYTHONROOT/bin/python3.8
B
barrierye 已提交
74

W
wangjiawei04 已提交
75
```
B
barrierye 已提交
76 77 78 79

## Install Python dependencies

```shell
T
TeslaZhao 已提交
80
pip install -r python/requirements.txt -i https://mirror.baidu.com/pypi/simple
B
barrierye 已提交
81 82
```

W
wangjiawei04 已提交
83
If you use other Python version, please use the right `pip` accordingly.
B
barrierye 已提交
84

B
barriery 已提交
85
## GOPATH Setting
W
wangjiawei04 已提交
86
The default GOPATH is set to `$HOME/go`, you can also set it to other values. **If it is the Docker environment provided by Serving, you do not need to set up.**
B
barrierye 已提交
87

B
barriery 已提交
88 89 90 91 92 93 94 95
```shell
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
```

## Get go packages

```shell
M
fix ci  
MRXLT 已提交
96
go env -w GO111MODULE=on
M
MRXLT 已提交
97
go env -w GOPROXY=https://goproxy.cn,direct
M
MRXLT 已提交
98 99 100 101
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.15.2
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v1.15.2
go get -u github.com/golang/protobuf/protoc-gen-go@v1.4.3
go get -u google.golang.org/grpc@v1.33.0
B
barriery 已提交
102
```
M
bug fix  
MRXLT 已提交
103

B
barrierye 已提交
104

J
Jiawei Wang 已提交
105
## Compile Server
B
barrierye 已提交
106

J
Jiawei Wang 已提交
107
### Integrated CPU version paddle inference library
B
barrierye 已提交
108

D
Dong Daxiang 已提交
109
``` shell
B
barrierye 已提交
110
mkdir server-build-cpu && cd server-build-cpu
M
bug fix  
MRXLT 已提交
111
cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
M
MRXLT 已提交
112 113 114
    -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so \
    -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
    -DSERVER=ON ..
D
Dong Daxiang 已提交
115 116 117
make -j10
```

J
Jiawei Wang 已提交
118
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 已提交
119

J
Jiawei Wang 已提交
120
### Integrated GPU version paddle inference library
121

W
wangjiawei04 已提交
122 123
Compared with CPU environment, GPU environment needs to refer to the following table,
**It should be noted that the following table is used as a reference for non-Docker compilation environment. The Docker compilation environment has been configured with relevant parameters and does not need to be specified in cmake process. **
M
MRXLT 已提交
124

W
wangjiawei04 已提交
125
| cmake environment variable | meaning | GPU environment considerations | whether Docker environment is needed |
T
TeslaZhao 已提交
126
|-----------------------|-------------------------------------|-------------------------------|--------------------|
T
TeslaZhao 已提交
127
| CUDA_TOOLKIT_ROOT_DIR | cuda installation path, usually /usr/local/cuda | Required for all environments | No (/usr/local/cuda) |
W
wangjiawei04 已提交
128 129 130
| CUDNN_LIBRARY | The directory where libcudnn.so.* is located, usually /usr/local/cuda/lib64/ | Required for all environments | No (/usr/local/cuda/lib64/) |
| CUDA_CUDART_LIBRARY | The directory where libcudart.so.* is located, usually /usr/local/cuda/lib64/ | Required for all environments | No (/usr/local/cuda/lib64/) |
| TENSORRT_ROOT | The upper level directory of the directory where libnvinfer.so.* is located, depends on the TensorRT installation directory | Cuda 9.0/10.0 does not need, other needs | No (/usr) |
M
MRXLT 已提交
131

T
TeslaZhao 已提交
132
If not in Docker environment, users can refer to the following execution methods. The specific path is subject to the current environment, and the code is only for reference.TENSORRT_LIBRARY_PATH is related to the TensorRT version and should be set according to the actual situation。For example, in the cuda10.1 environment, the TensorRT version is 6.0 (/usr/local/TensorRT-6.0.1.5/targets/x86_64-linux-gnu/),In the cuda10.2 environment, the TensorRT version is 7.1 (/usr/local/TensorRT-7.1.3.4/targets/x86_64-linux-gnu/).
W
wangjiawei04 已提交
133 134

``` shell
H
HexToString 已提交
135
export CUDA_PATH='/usr/local/cuda'
136 137
export CUDNN_LIBRARY='/usr/local/cuda/lib64/'
export CUDA_CUDART_LIBRARY="/usr/local/cuda/lib64/"
W
wangjiawei04 已提交
138
export TENSORRT_LIBRARY_PATH="/usr/local/TensorRT-6.0.1.5/targets/x86_64-linux-gnu/"
139

W
wangjiawei04 已提交
140 141 142 143
mkdir server-build-gpu && cd server-build-gpu
cmake -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR \
    -DPYTHON_LIBRARIES=$PYTHON_LIBRARIES \
    -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
M
MRXLT 已提交
144 145
    -DCUDA_TOOLKIT_ROOT_DIR=${CUDA_PATH} \
    -DCUDNN_LIBRARY=${CUDNN_LIBRARY} \
146
    -DCUDA_CUDART_LIBRARY=${CUDA_CUDART_LIBRARY} \
T
TeslaZhao 已提交
147
    -DTENSORRT_ROOT=${TENSORRT_LIBRARY_PATH} \
M
MRXLT 已提交
148
    -DSERVER=ON \
W
wangjiawei04 已提交
149
    -DWITH_GPU=ON ..
D
Dong Daxiang 已提交
150 151 152
make -j10
```

W
wangjiawei04 已提交
153
Execute `make install` to put the target output in the `./output` directory.
B
barrierye 已提交
154

W
wangjiawei04 已提交
155
**Note:** After the compilation is successful, you need to set the `SERVING_BIN` path, see the following [Notes](COMPILE.md#Notes) ).
B
barrierye 已提交
156

J
Jiawei Wang 已提交
157
## Compile Client
D
Dong Daxiang 已提交
158 159

``` shell
B
barrierye 已提交
160
mkdir client-build && cd client-build
M
bug fix  
MRXLT 已提交
161 162 163 164
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 已提交
165 166
make -j10
```
D
Dong Daxiang 已提交
167

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

B
barrierye 已提交
170 171


J
Jiawei Wang 已提交
172
## Compile the App
B
barrierye 已提交
173 174

```bash
B
barrierye 已提交
175
mkdir app-build && cd app-build
M
MRXLT 已提交
176 177 178 179
cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
    -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so \
    -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
    -DAPP=ON ..
B
barrierye 已提交
180 181 182
make
```

B
barrierye 已提交
183 184


J
Jiawei Wang 已提交
185 186
## Install wheel package

B
barrierye 已提交
187
Regardless of the client, server or App part, after compiling, install the whl package in `python/dist/` in the temporary directory(`server-build-cpu`, `server-build-gpu`, `client-build`,`app-build`) of the compilation process.
188
for example:cd server-build-cpu/python/dist && pip install -U xxxxx.whl
B
barrierye 已提交
189 190


J
Jiawei Wang 已提交
191
## Note
B
barrierye 已提交
192

J
Jiawei Wang 已提交
193
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`.
J
Jiawei Wang 已提交
194
BUILD_DIR is the absolute path of server build CPU or server build GPU。
195
for example: cd server-build-cpu && export SERVING_BIN=${PWD}/core/general-server/serving
B
barrierye 已提交
196

197

B
barrierye 已提交
198

B
barrierye 已提交
199 200 201 202 203 204
## Verify

Please use the example under `python/examples` to verify.



J
Jiawei Wang 已提交
205
## CMake Option Description
B
barrierye 已提交
206

J
Jiawei Wang 已提交
207
| Compile Options  |                    Description             | Default |
B
barrierye 已提交
208 209 210 211
| :--------------: | :----------------------------------------: | :--: |
|     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  |
M
MRXLT 已提交
212 213 214
|  CUDNN_LIBRARY   |    Define CuDNN library and header path    |      |
| CUDA_TOOLKIT_ROOT_DIR |       Define CUDA PATH                |      |
|   TENSORRT_ROOT  |           Define TensorRT PATH             |      |
B
barrierye 已提交
215 216 217 218 219
|      CLIENT      |       Compile Paddle Serving Client        | OFF  |
|      SERVER      |       Compile Paddle Serving Server        | OFF  |
|       APP        |     Compile Paddle Serving App package     | OFF  |
|       PACK       |              Compile for whl               | OFF  |

J
Jiawei Wang 已提交
220
### WITH_GPU Option
B
barrierye 已提交
221

J
Jiawei Wang 已提交
222
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 已提交
223

J
Jiawei Wang 已提交
224
To compile the Paddle Serving GPU version on bare metal, you need to install these basic libraries:
B
barrierye 已提交
225 226 227

- CUDA
- CuDNN
M
MRXLT 已提交
228 229

To compile the TensorRT version, you need to install the TensorRT library.
B
barrierye 已提交
230

J
Jiawei Wang 已提交
231 232 233 234
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 已提交
235 236


J
Jiawei Wang 已提交
237
The following is the base library version matching relationship used by the PaddlePaddle release version for reference:
B
barrierye 已提交
238

W
wangjiawei04 已提交
239 240 241 242 243 244 245
|          |  CUDA   |   CuDNN      | TensorRT |
| :----:   | :-----: | :----------: | :----:   |
| post9    |  9.0    | CuDNN 7.6.4  |          |
| post10   |  10.0   | CuDNN 7.6.5  |          |
| post101  |  10.1   | CuDNN 7.6.5  | 6.0.1    |
| post102  |  10.2   | CuDNN 8.0.5  | 7.1.3    |
| post11   |  11.0   | CuDNN 8.0.4  | 7.1.3    |
B
barrierye 已提交
246

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

J
Jiawei Wang 已提交
249
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.