compile_Ubuntu_en.md 14.0 KB
Newer Older
1
# **Compile on Ubuntu from Source Code**
2

3
## Environment preparation
4

5 6 7 8 9 10
* **Ubuntu version (64 bit)**
    * **Ubuntu 14.04 (GPU version supports CUDA 10.0/10.1)**
    * **Ubuntu 16.04 (GPU version supports CUDA 9.0/9.1/9.2/10.0/10.1)**
    * **Ubuntu 18.04 (GPU version supports CUDA 10.0/10.1)**
* **Python version 2.7.15+/3.5.1+/3.6/3.7 (64 bit)**
* **pip or pip3 version 9.0.1+ (64 bit)**
11

12
## Choose CPU/GPU
13

14
* If your computer doesn't have NVIDIA® GPU, please install CPU version of PaddlePaddle
15

16 17 18 19 20
* If your computer has NVIDIA® GPU, and the following conditions are met,GPU version of PaddlePaddle is recommended.
    * **CUDA toolkit 10.0 with cuDNN v7.3+(for multi card support, NCCL2.3.7 or higher)**
    * **CUDA toolkit 9.0 with cuDNN v7.3+(for multi card support, NCCL2.3.7 or higher)**
    * **CUDA toolkit 8.0 with cuDNN v7.1+(for multi card support, NCCL2.1.15-2.2.13)**
    * **Hardware devices with GPU computing power over 1.0**
21

22
        You can refer to NVIDIA official documents for installation process and configuration method of CUDA and cudnn. Please refer to[CUDA](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/),[cuDNN](https://docs.nvidia.com/deeplearning/sdk/cudnn-install/)
23

24
* * If you need to use multi card environment, please make sure that you have installed nccl2 correctly, or install nccl2 according to the following instructions (here is the installation instructions of nccl2 under ubuntu 16.04, CUDA9 and cuDNN7). For more version of installation information, please refer to NVIDIA[official website](https://developer.nvidia.com/nccl):
25 26


27 28 29
        wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
        dpkg -i nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
        sudo apt-get install -y libnccl2=2.3.7-1+cuda9.0 libnccl-dev=2.3.7-1+cuda9.0
30

31
## Installation steps
32

33
There are two compilation methods in Ubuntu system:
34

35 36
* Compile with docker (GPU version under Ubuntu 18.04 is not supported temporarily)
* Local compilation
37

38 39 40 41 42 43
<a name="ubt_docker"></a>
### **Compile with docker**

[Docker](https://docs.docker.com/install/) is an open source application container engine. Using docker, you can not only isolate the installation and use of paddlepaddle from the system environment, but also share GPU, network and other resources with the host

Compiling PaddlePaddle with Docker,you need:
44

45
- On the local host [Install Docker](https://hub.docker.com/search/?type=edition&offering=community)
46

47
- To enable GPU support on Linux, please [Install nvidia-docker](https://github.com/NVIDIA/nvidia-docker)
48

49
Please follow the steps below to install:
50

51
1. First, select the path where you want to store PaddlePaddle, and then use the following command to clone the source code of PaddlePaddle from GitHub to the folder named Paddle under the current local directory:
52

53
    `git clone https://github.com/PaddlePaddle/Paddle.git`
54

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
2. Enter the Paddle Directory: `cd Paddle`

3. Create and enter a Docker container that meets the compilation environment:

    * Compile CPU version of PaddlePaddle:



        `docker run --name paddle-test -v $PWD:/paddle --network=host -it hub.baidubce.com/paddlepaddle/paddle:latest-dev /bin/bash`

        > --name paddle-test names the Docker container you created as paddle-test;


        > -v $PWD:/paddle mount the current directory to the /paddle directory in the docker container (PWD variable in Linux will be expanded to [absolute path](https://baike.baidu.com/item/绝对路径/481185) of the current path);


        > -it keeps interaction with the host,`hub.baidubce.com/paddlepaddle/paddle:latest-dev` use the image named `hub.baidubce.com/paddlepaddle/paddle:latest-dev` to create Docker container, /bin/bash start the /bin/bash command after entering the container.


    * Compile GPU version of PaddlePaddle:



        `nvidia-docker run --name paddle-test -v $PWD:/paddle --network=host -it hub.baidubce.com/paddlepaddle/paddle:latest-dev /bin/bash`

        > --name paddle-test names the Docker container you created as paddle-test;
81 82


83
        > -v $PWD:/paddle mount the current directory to the /paddle directory in the docker container (PWD variable in Linux will be expanded to [absolute path](https://baike.baidu.com/item/绝对路径/481185) of the current path);
84 85


86
        > -it keeps interaction with the host,`hub.baidubce.com/paddlepaddle/paddle:latest-dev` use the image named `hub.baidubce.com/paddlepaddle/paddle:latest-dev` to create Docker container, /bin/bash start the /bin/bash command after entering the container.
87 88


89
        > Note: hub.baidubce.com/paddlepaddle/paddle:latest-dev internally install CUDA 8.0.
90

91 92
4. After entering Docker, enter the Paddle Directory:

J
joejiong 已提交
93
    `cd ../paddle`
94 95 96 97 98 99 100 101 102 103 104 105

5. Switch to a more stable release branch for compilation:

    `git checkout [name of the branch]`

    For example:

    `git checkout release/1.5`

    Note: python3.6、python3.7 version started supporting from release/1.2 branch

6. Create and enter /paddle/build Directory:
106

107
    `mkdir -p /paddle/build && cd /paddle/build`
108

109
7. Use the following command to install dependencies:
110

111 112
        For Python2: pip install protobuf
        For Python3: pip3.5 install protobuf
113

114
    Note: We used Python3.5 command as an example above, if the version of your Python is 3.6/3.7, please change Python3.5 in the commands to Python3.6/Python3.7
115

116
    > Install protobuf
117

118
    `apt install patchelf`
119

120 121
    > Install patchelf
    This is a small but useful program, it can be used to modify dynamic linker and RPATH of ELF executable
122

123
8. Execute cmake:
124

125
    > For the specific meaning of compilation options, you can read [Compile options table](../Tables.html#Compile)
126

127
    > Please attention to modify parameters `-DPY_VERSION` for the version of Python you want to compile with, for example `-DPY_VERSION=3.5` means the version of python is 3.5.x
128

129
    *  Compile**CPU version of PaddlePaddle**:
130

131
        `cmake .. -DPY_VERSION=3.5 -DWITH_GPU=OFF -DWITH_TESTING=OFF -DCMAKE_BUILD_TYPE=Release`
132

133
    *  Compile**GPU version of PaddlePaddle**:
134

135 136 137
        `cmake .. -DPY_VERSION=3.5 -DWITH_GPU=ON -DWITH_TESTING=OFF -DCMAKE_BUILD_TYPE=Release`

9. Execute compiling:
138

139
    `make -j$(nproc)`
140

141
    > Use multicore compilation
142

143
10. after compiling successful, enter `/paddle/build/python/dist` Directory and find generated `.whl` package: `cd /paddle/build/python/dist`
144

145
11. Install the compiled `.whl` package on the current machine or target machine:
146

147 148
        For Python2: pip install -U(whl package name)
        For Python3: pip3.5 install -U(whl package name)
149

150
    Note: For the command involving Python 3, we use Python 3.5 as an example above, if the version of your Python is 3.6/3.7, please change Python3.5 in the commands to Python3.6/Python3.7
151

152
Congratulations, now you have completed the compilation and installation of PaddlePaddle. You only need to enter the Docker container and run PaddlePaddle to start using. For more Docker usage, please refer to [official docker documentation](https://docs.docker.com)
153 154 155

> Note: In order to reduce the size, `vim` is not installed in PaddlePaddle Docker image by default. You can edit the code in the container after executing `apt-get install -y vim` in the container.

156
<a name="ubt_source"></a>
157 158 159 160 161 162 163 164 165 166
### ***Local compilation***

**Please strictly follow the following instructions step by step**

1. Check that your computer and operating system meet the compilation standards we support: `uname -m && cat /etc/*release`

2. Update the source of `apt`: `apt update`, and install openCV in advance.

3. We support compiling and installing with virtualenv. First, create a virtual environment called `paddle-venv` with the following command:

167
    * a. Install Python-dev: (Please note that gcc4.8 is not supported in python2.7 under Ubuntu 16.04, please use gcc5.4 to compile Paddle)
168

169 170
            For Python2: apt install python-dev
            For Python3: apt install python3.5-dev
171

172
    * b. Install pip: (Please ensure that pip version is 9.0.1 and above ): 
173

174 175
            For Python2: apt install python-pip
            For Python3: apt-get udpate && apt-get install -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa && apt install curl && curl https://bootstrap.pypa.io/get-pip. Py -o - | python3.5 && easy_install pip
176 177


178
    * c. Install the virtual environment `virtualenv` and `virtualenvwrapper` and create a virtual environment called `paddle-venv` :
179

180
        1.  `apt install virtualenv` or `pip install virtualenv` or `pip3 install virtualenv`
181 182 183
        2. `apt install virtualenvwrapper` or `pip install virtualenvwrapper` or `pip3 install virtualenvwrapper`
        3. Find `virtualenvwrapper.sh`: `find / -name virtualenvwrapper.sh`
        4. (Only for Python3) Set the interpreter path for the virtual environment: `export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.5`
184
        5. See the installation method in `virtualenvwrapper.sh`: `cat virtualenvwrapper.sh`, this shell file describes the steps and commands
185
        6. Install `virtualwrapper` according to the installation method in `virtualenvwrapper.sh`
186 187 188 189
        7. Set VIRTUALENVWRAPPER_PYTHON:`export VIRTUALENVWRAPPER_PYTHON=[python-lib-path]:$PATH` (Here, replace the last two directories of [python-lib-path] with /bin/)
        8. Create a virtual environment called `paddle-venv`: `mkvirtualenv paddle-venv`

    Note: for the above commands involving Python 3, we use Python 3.5 as an example. If your Python version is 3.6 / 3.7, please change Python 3.5 in the above commands to Python 3.6 / Python 3.7
190 191 192 193 194

4. Enter the virtual environment: `workon paddle-venv`

5. Before **executing the compilation**, please confirm that the related dependencies mentioned in [the compile dependency table](../Tables.html/#third_party) are installed in the virtual environment:

195
    * Here is the installation method for `patchELF`. Other dependencies can be installed using `apt install` or `pip install` followed by the name and version:
196

197
        `apt install patchelf`
198

199
        > Users who can't use apt installation can refer to patchElF [github official documentation](https://gist.github.com/ruario/80fefd174b3395d34c14).
200 201 202

6. Clone the PaddlePaddle source code in the Paddle folder in the current directory and go to the Paddle directory:

203
    - `git clone https://github.com/PaddlePaddle/Paddle.git`
204

205
    - `cd Paddle`
206 207 208

7. Switch to a more stable release branch to compile, replacing the brackets and their contents with **the target branch name**:

209
    - `git checkout [name of target branch]`
210

211 212 213 214
    For example:

    `git checkout release/1.5`

215 216
8. And please create and enter a directory called build:

217
    `mkdir build && cd build`
218 219 220

9. Execute cmake:

221
    > For details on the compilation options, see [the compilation options table](../Tables.html/#Compile).
222

223
    * For users who need to compile the **CPU version of PaddlePaddle**: (For Python3: Please configure the correct python version for the PY_VERSION parameter)
224

225 226
            For Python2: cmake .. -DWITH_FLUID_ONLY=ON -DWITH_GPU=OFF -DWITH_TESTING=OFF -DCMAKE_BUILD_TYPE=Release
            For Python3: cmake .. -DPY_VERSION=3.5 -DWITH_FLUID_ONLY=ON -DWITH_GPU=OFF -DWITH_TESTING=OFF -DCMAKE_BUILD_TYPE=Release
227 228


229
    * For users who need to compile **GPU version of PaddlePaddle**: (*only support ubuntu16.04/14.04*)
230

231
        1. Please make sure that you have installed nccl2 correctly, or install nccl2 according to the following instructions (here is ubuntu 16.04, CUDA9, ncDNN7 nccl2 installation instructions), for more information on the installation information please refer to the [NVIDIA official website](https://developer.nvidia.com/nccl/nccl-download):
232

233
            i. `wget http: / /developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb `
234

235
            ii. `dpkg -i nvidia-machine-learning-repo-ubuntu1604_1 .0.0-1_amd64.deb`
236

237
            iii. `sudo apt-get install -y libnccl2=2.2.13-1+cuda9.0 libnccl-dev=2.2.13-1+cuda9.0`
238

239
        2. If you have already installed `nccl2` correctly, you can start cmake: *(For Python3: Please configure the correct python version for the PY_VERSION parameter)*
240

241 242
                For Python2: cmake .. -DWITH_FLUID_ONLY=ON -DWITH_GPU=ON -DWITH_TESTING=OFF -DCMAKE_BUILD_TYPE=Release
                For Python3: cmake .. -DPY_VERSION=3.5 -DWITH_FLUID_ONLY=ON -DWITH_GPU=ON -DWITH_TESTING=OFF -DCMAKE_BUILD_TYPE=Release
243 244


245
    Note: We used Python3.5 command as an example above, if the version of your Python is 3.6/3.7, please change Python3.5 in the commands to Python3.6/Python3.7
246 247 248

10. Compile with the following command:

249
    `make -j$(nproc)`
250

251 252 253 254
    > compile using multi-core

    > If “Too many open files” error is displayed during compilation, please use the instruction ulimit -n 8192  to increase the number of files allowed to be opened by the current process. Generally speaking, 8192 can ensure the completion of compilation.

255 256 257 258
11. After compiling successfully, go to the `/paddle/build/python/dist `directory and find the generated `.whl` package: `cd /paddle/build/python/dist`

12. Install the compiled `.whl` package on the current machine or target machine:

259
    `Pip install (whl package name)` or `pip3 install (whl package name)`
260 261 262 263 264 265

Congratulations, now you have completed the process of compiling PaddlePaddle natively.

<br/><br/>
### ***Verify installation***

266 267 268
After the installation is complete, you can use `python` or `python3` to enter the Python interpreter and then use `import paddle.fluid as fluid` and then  `fluid.install_check.run_check()` to verify that the installation was successful.

If `Your Paddle Fluid is installed succesfully!` appears, it means the installation was successful.
269 270 271

<br/><br/>
### ***How to uninstall***
272
Please use the following command to uninstall PaddlePaddle:
273 274 275 276

- ***CPU version of PaddlePaddle***: `pip uninstall paddlepaddle` or `pip3 uninstall paddlepaddle`

- ***GPU version of PaddlePaddle***: `pip uninstall paddlepaddle-gpu` or `pip3 uninstall paddlepaddle-gpu`
277 278

Users installing PaddlePaddle with Docker, please use above commands in the container involved PaddlePaddle and attention to use the corresponding version of Pip