build_from_source_en.md 6.8 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)
L
liaogang 已提交
7

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

L
liaogang 已提交
11
```bash
G
gangliao 已提交
12
git clone https://github.com/PaddlePaddle/Paddle paddle
13
cd paddle
L
Liu Yiqun 已提交
14
git submodule update --init --recursive
L
liaogang 已提交
15
```
Z
zhangjinchao01 已提交
16

W
wangyang59 已提交
17
If you already have a local PaddlePaddle repo and have not initialized the submodule, your local submodule folder will be empty. You can simply run the last line of the above codes in your PaddlePaddle home directory to initialze your submodule folder.
18

W
wangyang59 已提交
19
If you have already initialized your submodule and you would like to sync with the upstream submodule repo, you can run the following command
20 21 22 23
```
git submodule update --remote
```

L
liaogang 已提交
24
## <span id="requirements">Requirements</span>
Z
zhangjinchao01 已提交
25

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

- **Compiler**: GCC >= 4.8 or Clang >= 3.3 (AppleClang >= 5.1)
L
liaogang 已提交
29 30
- **CMake**: version >= 2.8
- **BLAS**: MKL, OpenBlas or ATLAS
L
liaogang 已提交
31 32
- **Protocol Buffers**: version >= 2.4, **Note: 3.x is not supported**
- **Python**: only python 2.7 is supported currently
Z
zhangjinchao01 已提交
33

L
liaogang 已提交
34 35 36
**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 已提交
37
### Options
Z
zhangjinchao01 已提交
38

L
liaogang 已提交
39
PaddlePaddle supports some build options. To enable it, first you need to install the related libraries. 
Z
zhangjinchao01 已提交
40

G
gangliao 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<html>
<table> 
<thead>
<tr>
<th scope="col" class="left">Optional</th>
<th scope="col" class="left">Description</th>
</tr>
</thead>
<tbody>
<tr><td class="left">WITH_GPU</td><td class="left">Compile with GPU mode.</td></tr>
<tr><td class="left">WITH_DOUBLE</td><td class="left">Compile with double precision floating-point, default: single precision.</td></tr>
<tr><td class="left">WITH_GLOG</td><td class="left">Compile with glog. If not found, default: an internal log implementation.</td></tr>
<tr><td class="left">WITH_GFLAGS</td><td class="left">Compile with gflags. If not found, default: an internal flag implementation.</td></tr>
<tr><td class="left">WITH_TESTING</td><td class="left">Compile with gtest for PaddlePaddle's unit testing.</td></tr>
<tr><td class="left">WITH_DOC</td><td class="left">	Compile to generate PaddlePaddle's docs, default: disabled (OFF).</td></tr>
<tr><td class="left">WITH_SWIG_PY</td><td class="left">Compile with python predict API, default: disabled (OFF).</td></tr>
<tr><td class="left">WITH_STYLE_CHECK</td><td class="left">Compile with code style check, default: enabled (ON).</td></tr>
</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. **Python Dependencies(optional)**
Z
zhangjinchao01 已提交
70
  
L
liaogang 已提交
71
    To compile PaddlePaddle with python predict API, make sure swig installed and set `-DWITH_SWIG_PY=ON` as follows:
Z
zhangjinchao01 已提交
72

L
liaogang 已提交
73 74 75 76 77
    ```bash
    # install swig on ubuntu
    sudo apt-get install swig
    # install swig on Mac OS X
    brew install swig
Z
zhangjinchao01 已提交
78

L
liaogang 已提交
79 80 81
    # active swig in cmake
    cmake .. -DWITH_SWIG_PY=ON
    ```
Z
zhangjinchao01 已提交
82

L
liaogang 已提交
83
2. **Doc Dependencies(optional)**
Z
zhangjinchao01 已提交
84

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

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

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

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

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

L
liaogang 已提交
102
### Install Dependencies
Z
zhangjinchao01 已提交
103

L
liaogang 已提交
104
- **CPU Dependencies**
Z
zhangjinchao01 已提交
105

L
liaogang 已提交
106 107 108
    ```bash
    # necessary
    sudo apt-get update
L
liaogang 已提交
109
    sudo apt-get install -y g++ make cmake swig build-essential libatlas-base-dev python python-pip libpython-dev m4 libprotobuf-dev protobuf-compiler python-protobuf python-numpy git
L
liaogang 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122
    # optional
    sudo apt-get install libgoogle-glog-dev
    sudo apt-get install libgflags-dev
    sudo apt-get install libgtest-dev
    sudo pip install wheel
    pushd /usr/src/gtest
    cmake .
    make
    sudo cp *.a /usr/lib
    popd
    ```
  
- **GPU Dependencies (optional)**
Z
zhangjinchao01 已提交
123

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

L
liaogang 已提交
126 127 128 129
        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 已提交
130

L
liaogang 已提交
131 132 133 134 135
    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 已提交
136

L
liaogang 已提交
137 138 139 140
    ```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*
    ```
141
    Then you need to set LD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.
L
liaogang 已提交
142 143 144 145 146 147 148 149 150

    ```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 已提交
151 152

```bash
L
liaogang 已提交
153 154
mkdir build && cd build
cmake ..
Z
zhangjinchao01 已提交
155 156
```

L
liaogang 已提交
157
CMake first check PaddlePaddle's dependencies in system default path. After installing some optional
L
liaogang 已提交
158 159
libraries, corresponding build option will be set automatically (for instance, glog, gtest and gflags).
If still not found, you can manually set it based on CMake error information from your screen.
Z
zhangjinchao01 已提交
160

L
liaogang 已提交
161 162
As a simple example, consider the following:

L
liaogang 已提交
163
- **Only CPU with swig**
L
liaogang 已提交
164 165

  ```bash
L
liaogang 已提交
166
  cmake  .. -DWITH_GPU=OFF -DWITH_SWIG_PY=ON
L
liaogang 已提交
167
  ```
L
liaogang 已提交
168
- **GPU with swig**
L
liaogang 已提交
169 170

  ```bash
L
liaogang 已提交
171
  cmake .. -DWITH_GPU=ON -DWITH_SWIG_PY=ON
L
liaogang 已提交
172 173 174 175 176 177 178
  ```

- **GPU with doc and swig**

  ```bash
  cmake .. -DWITH_GPU=ON -DWITH_DOC=ON -DWITH_SWIG_PY=ON
  ``` 
Z
zhangjinchao01 已提交
179

180
Finally, you can build PaddlePaddle:
Z
zhangjinchao01 已提交
181 182 183

```bash
# you can add build option here, such as:    
L
liaogang 已提交
184
cmake .. -DWITH_GPU=ON -DCMAKE_INSTALL_PREFIX=<path to install> -DWITH_SWIG_PY=ON
185
# please use sudo make install, if you want to install PaddlePaddle into the system
Z
zhangjinchao01 已提交
186
make -j `nproc` && make install
L
liaogang 已提交
187
# set PaddlePaddle installation path in ~/.bashrc
L
liaogang 已提交
188
export PATH=<path to install>/bin:$PATH
Z
zhangjinchao01 已提交
189 190
```

L
liaogang 已提交
191 192 193 194
If you set `WITH_SWIG_PY=ON`, related python dependencies also need to be installed.
Otherwise, PaddlePaddle will automatically install python dependencies
at first time when user run paddle commands, such as `paddle version`, `paddle train`.
It may require sudo privileges:
Z
zhangjinchao01 已提交
195 196

```bash
L
liaogang 已提交
197 198 199 200
# you can run
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
# or just run 
sudo paddle version
Z
zhangjinchao01 已提交
201
```