build_from_source_en.md 8.4 KB
Newer Older
L
liaogang 已提交
1
Installing from Sources
G
gangliao 已提交
2
==========================
Z
zhangjinchao01 已提交
3

L
liaogang 已提交
4 5 6
* [1. Download and Setup](#download)
* [2. Requirements](#requirements)
* [3. Build on Ubuntu](#ubuntu)
Q
qijun 已提交
7 8
* [4. Build on Centos](#centos)

L
liaogang 已提交
9

L
liaogang 已提交
10
## <span id="download">Download and Setup</span> 
G
gangliao 已提交
11
You can download PaddlePaddle from the [github source](https://github.com/PaddlePaddle/Paddle).
Z
zhangjinchao01 已提交
12

L
liaogang 已提交
13
```bash
G
gangliao 已提交
14
git clone https://github.com/PaddlePaddle/Paddle paddle
15
cd paddle
L
liaogang 已提交
16 17
```
## <span id="requirements">Requirements</span>
Z
zhangjinchao01 已提交
18

L
liaogang 已提交
19 20
To compile the source code, your computer must be equipped with the following dependencies.

L
liaogang 已提交
21
- **Compiler**: GCC >= 4.8 or Clang >= 3.3 (AppleClang >= 5.1) and gfortran compiler
L
liaogang 已提交
22
- **CMake**: CMake >= 3.0 (at least CMake 3.4 on Mac OS X)
L
liaogang 已提交
23
- **BLAS**: MKL, OpenBlas or ATLAS
L
liaogang 已提交
24
- **Python**: only support Python 2.7
25
- **Go**
Z
zhangjinchao01 已提交
26

L
liaogang 已提交
27 28 29
**Note:** For CUDA 7.0 and CUDA 7.5, GCC 5.0 and up are not supported!
For CUDA 8.0, GCC versions later than 5.3 are not supported!

L
liaogang 已提交
30
### Options
Z
zhangjinchao01 已提交
31

L
liaogang 已提交
32
PaddlePaddle supports some build options. 
Z
zhangjinchao01 已提交
33

G
gangliao 已提交
34 35 36 37 38 39 40 41 42
<html>
<table> 
<thead>
<tr>
<th scope="col" class="left">Optional</th>
<th scope="col" class="left">Description</th>
</tr>
</thead>
<tbody>
L
liaogang 已提交
43 44 45 46 47 48 49 50 51 52 53 54
<tr><td class="left">WITH_GPU</td><td class="left">Compile PaddlePaddle with NVIDIA GPU</td></tr>
<tr><td class="left">WITH_AVX</td><td class="left">Compile PaddlePaddle with AVX intrinsics</td></tr>
<tr><td class="left">WITH_DSO</td><td class="left">Compile PaddlePaddle with dynamic linked CUDA</td></tr>
<tr><td class="left">WITH_TESTING</td><td class="left">Compile PaddlePaddle with unit testing</td></tr>
<tr><td class="left">WITH_SWIG_PY</td><td class="left">Compile PaddlePaddle with inference api</td></tr>
<tr><td class="left">WITH_STYLE_CHECK</td><td class="left">Compile PaddlePaddle with style check</td></tr>
<tr><td class="left">WITH_PYTHON</td><td class="left">Compile PaddlePaddle with python interpreter</td></tr>
<tr><td class="left">WITH_DOUBLE</td><td class="left">Compile PaddlePaddle with double precision</td></tr>
<tr><td class="left">WITH_RDMA</td><td class="left">Compile PaddlePaddle with RDMA support</td></tr>
<tr><td class="left">WITH_TIMER</td><td class="left">Compile PaddlePaddle with stats timer</td></tr>
<tr><td class="left">WITH_PROFILER</td><td class="left">Compile PaddlePaddle with GPU profiler</td></tr>
<tr><td class="left">WITH_DOC</td><td class="left">Compile PaddlePaddle with documentation</td></tr>
55
<tr><td class="left">WITH_COVERAGE</td><td class="left">Compile PaddlePaddle with code coverage</td></tr>
L
liaogang 已提交
56 57
<tr><td class="left">COVERALLS_UPLOAD</td><td class="left">Package code coverage data to coveralls</td></tr>
<tr><td class="left">ON_TRAVIS</td><td class="left">Exclude special unit test on Travis CI</td></tr>
G
gangliao 已提交
58
</tbody>
G
gangliao 已提交
59
</table>
G
gangliao 已提交
60
</html>
Z
zhangjinchao01 已提交
61

L
liaogang 已提交
62
**Note:**
L
liaogang 已提交
63 64
  - The GPU version works best with Cuda Toolkit 8.0 and cuDNN v5.
  - Other versions like Cuda Toolkit 7.0, 7.5 and cuDNN v3, v4 are also supported.
L
liaogang 已提交
65
  - **To utilize cuDNN v5, Cuda Toolkit 7.5 is prerequisite and vice versa.**
Z
zhangjinchao01 已提交
66

L
liaogang 已提交
67
As a simple example, consider the following:  
Z
zhangjinchao01 已提交
68

L
liaogang 已提交
69
1. **BLAS Dependencies(optional)**
Z
zhangjinchao01 已提交
70
  
L
liaogang 已提交
71 72
    CMake will search BLAS libraries from system. If not found, OpenBLAS will be downloaded, built and installed automatically.
    To utilize preinstalled BLAS, you can simply specify MKL, OpenBLAS or ATLAS via `MKL_ROOT`, `OPENBLAS_ROOT` or `ATLAS_ROOT`.
Z
zhangjinchao01 已提交
73

L
liaogang 已提交
74
    ```bash
L
liaogang 已提交
75 76 77 78
    # specify MKL
    cmake .. -DMKL_ROOT=<mkl_path>
    # or specify OpenBLAS
    cmake .. -DOPENBLAS_ROOT=<openblas_path>
L
liaogang 已提交
79
    ```
Z
zhangjinchao01 已提交
80

L
liaogang 已提交
81
2. **Doc Dependencies(optional)**
Z
zhangjinchao01 已提交
82

L
liaogang 已提交
83
    To generate PaddlePaddle's documentation, install dependencies and set `-DWITH_DOC=ON` as follows:
Z
zhangjinchao01 已提交
84

L
liaogang 已提交
85 86
    ```bash
    pip install 'sphinx>=1.4.0'
87
    pip install sphinx_rtd_theme recommonmark
Z
zhangjinchao01 已提交
88

L
liaogang 已提交
89 90 91 92
    # install doxygen on Ubuntu
    sudo apt-get install doxygen 
    # install doxygen on Mac OS X
    brew install doxygen
Z
zhangjinchao01 已提交
93

L
liaogang 已提交
94 95 96
    # active docs in cmake
    cmake .. -DWITH_DOC=ON`
    ```
Z
zhangjinchao01 已提交
97

L
liaogang 已提交
98
## <span id="ubuntu">Build on Ubuntu 14.04</span>
Z
zhangjinchao01 已提交
99

L
liaogang 已提交
100
### Install Dependencies
Z
zhangjinchao01 已提交
101

L
liaogang 已提交
102
- **Paddle Dependencies**
Z
zhangjinchao01 已提交
103

L
liaogang 已提交
104 105 106
    ```bash
    # necessary
    sudo apt-get update
L
liaogang 已提交
107 108
    sudo apt-get install -y git curl gcc g++ gfortran make build-essential automake
    sudo apt-get install -y python python-pip python-numpy libpython-dev bison
L
liaogang 已提交
109 110
    sudo pip install 'protobuf==3.1.0.post1'

111 112 113 114 115 116 117 118 119 120 121 122
    # Install Go
    # You can follow https://golang.org/doc/install for a detailed explanation.
    wget -O go.tgz https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz && \
    tar -C $HOME -xzf go.tgz && \
    mkdir $HOME/gopath && \
    rm go.tgz

    # Setup environment variables
    export GOROOT=$HOME/go
    export GOPATH=$HOME/gopath
    export PATH=$PATH:$GOROOT/bin

L
liaogang 已提交
123 124 125 126
    # install cmake 3.4
    curl -sSL https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz | tar -xz && \
        cd cmake-3.4.1 && ./bootstrap && make -j4 && sudo make install && \
        cd .. && rm -rf cmake-3.4.1
L
liaogang 已提交
127
    ```
L
liaogang 已提交
128

L
liaogang 已提交
129
- **GPU Dependencies (optional)**
Z
zhangjinchao01 已提交
130

L
liaogang 已提交
131
    To build GPU version, you will need the following installed:
Z
zhangjinchao01 已提交
132

L
liaogang 已提交
133 134 135 136
        1. a CUDA-capable GPU
        2. A supported version of Linux with a gcc compiler and toolchain
        3. NVIDIA CUDA Toolkit (available at http://developer.nvidia.com/cuda-downloads)
        4. NVIDIA cuDNN Library (availabel at https://developer.nvidia.com/cudnn)
Z
zhangjinchao01 已提交
137

L
liaogang 已提交
138 139 140 141 142
    The CUDA development environment relies on tight integration with the host development environment,
    including the host compiler and C runtime libraries, and is therefore only supported on
    distribution versions that have been qualified for this CUDA Toolkit release.
        
    After downloading cuDNN library, issue the following commands:
Z
zhangjinchao01 已提交
143

L
liaogang 已提交
144 145 146 147
    ```bash
    sudo tar -xzf cudnn-7.5-linux-x64-v5.1.tgz -C /usr/local
    sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
    ```
148
    Then you need to set LD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.
L
liaogang 已提交
149 150 151 152 153 154 155 156 157

    ```bash
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
    export PATH=/usr/local/cuda/bin:$PATH
    ```

### Build and Install

As usual, the best option is to create build folder under paddle project directory.
Z
zhangjinchao01 已提交
158 159

```bash
L
liaogang 已提交
160
mkdir build && cd build
L
liaogang 已提交
161
``` 
L
liaogang 已提交
162

L
liaogang 已提交
163
Finally, you can build and install PaddlePaddle:
Z
zhangjinchao01 已提交
164 165 166

```bash
# you can add build option here, such as:    
L
liaogang 已提交
167
cmake .. -DCMAKE_INSTALL_PREFIX=<path to install>
168
# please use sudo make install, if you want to install PaddlePaddle into the system
Z
zhangjinchao01 已提交
169
make -j `nproc` && make install
L
liaogang 已提交
170
# set PaddlePaddle installation path in ~/.bashrc
L
liaogang 已提交
171
export PATH=<path to install>/bin:$PATH
L
liaogang 已提交
172
# install PaddlePaddle Python modules.
L
liaogang 已提交
173
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
Z
zhangjinchao01 已提交
174
```
Q
qijun 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
## <span id="centos">Build on Centos 7</span>

### Install Dependencies

- **CPU Dependencies**

    ```bash
    # necessary
    sudo yum update
    sudo yum install -y epel-release
    sudo yum install -y make cmake3 python-devel python-pip gcc-gfortran swig git
    sudo pip install wheel numpy
    sudo pip install 'protobuf>=3.0.0'
    ```
  
- **GPU Dependencies (optional)**

    To build GPU version, you will need the following installed:

        1. a CUDA-capable GPU
        2. A supported version of Linux with a gcc compiler and toolchain
        3. NVIDIA CUDA Toolkit (available at http://developer.nvidia.com/cuda-downloads)
        4. NVIDIA cuDNN Library (availabel at https://developer.nvidia.com/cudnn)

    The CUDA development environment relies on tight integration with the host development environment,
    including the host compiler and C runtime libraries, and is therefore only supported on
    distribution versions that have been qualified for this CUDA Toolkit release.
        
    After downloading cuDNN library, issue the following commands:

    ```bash
    sudo tar -xzf cudnn-7.5-linux-x64-v5.1.tgz -C /usr/local
    sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
    ```
    Then you need to set LD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.

    ```bash
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
    export PATH=/usr/local/cuda/bin:$PATH
    ```

### Build and Install

As usual, the best option is to create build folder under paddle project directory.

```bash
mkdir build && cd build
``` 

Finally, you can build and install PaddlePaddle:

```bash
# you can add build option here, such as:    
cmake3 .. -DCMAKE_INSTALL_PREFIX=<path to install>
# please use sudo make install, if you want to install PaddlePaddle into the system
make -j `nproc` && make install
# set PaddlePaddle installation path in ~/.bashrc
export PATH=<path to install>/bin:$PATH
# install PaddlePaddle Python modules.
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
```