build_from_source.md 10.8 KB
Newer Older
L
liaogang 已提交
1
Installing from Sources
Z
zhangjinchao01 已提交
2 3
=================

L
liaogang 已提交
4 5 6 7
* [1. Download and Setup](#download)
* [2. Requirements](#requirements)
* [3. Build on Ubuntu](#ubuntu)
* [4. Build on Mac OS X](#mac)
L
liaogang 已提交
8

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

L
liaogang 已提交
12 13
```bash
git clone https://github.com/baidu/Paddle paddle
14
cd paddle
L
liaogang 已提交
15
```
Z
zhangjinchao01 已提交
16

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

19
To compile the source code, your computer must be equipped with GCC >=4.6 or Clang compiler.
L
liaogang 已提交
20
### Dependencies
Z
zhangjinchao01 已提交
21

L
liaogang 已提交
22 23 24 25
- **CMake**: version >= 2.8
- **BLAS**: MKL, OpenBlas or ATLAS
- **protobuf**: version >= 2.4, **Note: 3.x is not supported**
- **python**: only python 2.7 is supported currently
Z
zhangjinchao01 已提交
26

L
liaogang 已提交
27
### Options
Z
zhangjinchao01 已提交
28

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

G
gangliao 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 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 74 75
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;border-color:#ccc;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:0px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#fff;border-top-width:1px;border-bottom-width:1px;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:0px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#f0f0f0;border-top-width:1px;border-bottom-width:1px;}
.tg .tg-yw4l{vertical-align:top}
.tg .tg-9hbo{font-weight:bold;vertical-align:top}
</style>
<table class="tg">
  <tr>
    <th class="tg-yw4l">Optional</th>
    <th class="tg-yw4l">Description</th>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_GPU</td>
    <td class="tg-yw4l">Compile with GPU mode.</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_DOUBLE</td>
    <td class="tg-yw4l">Compile with double precision floating-point, default: single precision.</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_GLOG</td>
    <td class="tg-yw4l">Compile with glog. If not found, default: an internal log implementation.</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_GFLAGS</td>
    <td class="tg-yw4l">Compile with gflags. If not found, default: an internal flag implementation.</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_TESTING</td>
    <td class="tg-yw4l">Compile with gtest for PaddlePaddle's unit testing.</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_DOC</td>
    <td class="tg-yw4l">Compile to generate PaddlePaddle's docs, default: disabled (OFF)</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_SWIG_PY</td>
    <td class="tg-yw4l">Compile with python predict API, default: disabled (OFF).</td>
  </tr>
  <tr>
    <td class="tg-9hbo">WITH_STYLE_CHECK</td>
    <td class="tg-yw4l">Compile with code style check, default: enabled (ON).</td>
  </tr>
</table>
Z
zhangjinchao01 已提交
76

L
liaogang 已提交
77 78 79 80
**Note:**
  - The GPU version works best with Cuda Toolkit 7.5 and cuDNN v5.
  - Other versions like Cuda Toolkit 6.5, 7.0, 8.0 and cuDNN v2, v3, v4 are also supported.
  - **To utilize cuDNN v5, Cuda Toolkit 7.5 is prerequisite and vice versa.**
Z
zhangjinchao01 已提交
81

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

L
liaogang 已提交
84
1. **Python Dependencies(optional)**
Z
zhangjinchao01 已提交
85
  
L
liaogang 已提交
86
    To compile PaddlePaddle with python predict API, make sure swig installed and set `-DWITH_SWIG_PY=ON` as follows:
Z
zhangjinchao01 已提交
87

L
liaogang 已提交
88 89 90 91 92
    ```bash
    # install swig on ubuntu
    sudo apt-get install swig
    # install swig on Mac OS X
    brew install swig
Z
zhangjinchao01 已提交
93

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

L
liaogang 已提交
98
2. **Doc Dependencies(optional)**
Z
zhangjinchao01 已提交
99

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

L
liaogang 已提交
102 103 104
    ```bash
    pip install 'sphinx>=1.4.0'
    pip install sphinx_rtd_theme breathe recommonmark
Z
zhangjinchao01 已提交
105

L
liaogang 已提交
106 107 108 109
    # install doxygen on Ubuntu
    sudo apt-get install doxygen 
    # install doxygen on Mac OS X
    brew install doxygen
Z
zhangjinchao01 已提交
110

L
liaogang 已提交
111 112 113
    # active docs in cmake
    cmake .. -DWITH_DOC=ON`
    ```
Z
zhangjinchao01 已提交
114

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

L
liaogang 已提交
117
### Install Dependencies
Z
zhangjinchao01 已提交
118

L
liaogang 已提交
119
- **CPU Dependencies**
Z
zhangjinchao01 已提交
120

L
liaogang 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    ```bash
    # necessary
    sudo apt-get update
    sudo apt-get install -y g++ make cmake build-essential libatlas-base-dev python python-pip libpython-dev m4 libprotobuf-dev protobuf-compiler python-protobuf python-numpy git
    # 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 已提交
138

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

L
liaogang 已提交
141 142 143 144
        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 已提交
145

L
liaogang 已提交
146 147 148 149 150
    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 已提交
151

L
liaogang 已提交
152 153 154 155
    ```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*
    ```
156
    Then you need to set LD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.
L
liaogang 已提交
157 158 159 160 161 162 163 164 165

    ```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 已提交
166 167

```bash
L
liaogang 已提交
168 169
mkdir build && cd build
cmake ..
Z
zhangjinchao01 已提交
170 171
```

L
liaogang 已提交
172
CMake first check PaddlePaddle's dependencies in system default path. After installing some optional
L
liaogang 已提交
173 174
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 已提交
175

L
liaogang 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
As a simple example, consider the following:

- **Only CPU**

  ```bash
  cmake  .. -DWITH_GPU=OFF -DWITH_DOC=OFF
  ```
- **GPU**

  ```bash
  cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF
  ```

- **GPU with doc and swig**

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

195
Finally, you can build PaddlePaddle:
Z
zhangjinchao01 已提交
196 197 198

```bash
# you can add build option here, such as:    
L
liaogang 已提交
199
cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX=<path to install>
200
# please use sudo make install, if you want to install PaddlePaddle into the system
Z
zhangjinchao01 已提交
201
make -j `nproc` && make install
L
liaogang 已提交
202
# set PaddlePaddle installation path in ~/.bashrc
L
liaogang 已提交
203
export PATH=<path to install>/bin:$PATH
Z
zhangjinchao01 已提交
204 205
```

L
liaogang 已提交
206 207 208 209 210 211
**Note:**

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 已提交
212 213

```bash
L
liaogang 已提交
214 215 216 217
# you can run
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
# or just run 
sudo paddle version
Z
zhangjinchao01 已提交
218
```
L
liaogang 已提交
219

L
liaogang 已提交
220 221 222 223 224 225 226
## <span id="mac">Building on Mac OS X</span>

### Prerequisites
This guide is based on Mac OS X 10.11 (El Capitan). Note that if you are running an up to date version of OS X, 
you will already have Python 2.7.10 and Numpy 1.8 installed.

The best option is to use the package manager homebrew to handle installations and upgrades for you.
L
liaogang 已提交
227
To install [homebrew](http://brew.sh/), first open a terminal window (you can find Terminal in the Utilities folder in Applications), and issue the command:
L
liaogang 已提交
228 229 230 231 232 233 234 235 236 237 238 239

```bash
# install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install pip
easy_install pip
```

### Install Dependencies

- **CPU Dependencies**

L
liaogang 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
  ```bash
  # Install fundamental dependents 
  brew install glog gflags cmake protobuf openblas

  # Install google test on Mac OS X
  # Download gtest 1.7.0
  wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz
  tar -xvf googletest-release-1.7.0.tar.gz && cd googletest-release-1.7.0
  # Build gtest
  mkdir build && cmake ..
  make
  # Install gtest library
  sudo cp -r ../include/gtest /usr/local/include/
  sudo cp lib*.a /usr/local/lib
  ```

L
liaogang 已提交
256 257
- **GPU Dependencies(optional)**

L
liaogang 已提交
258
    To build GPU version, you will need the following installed:
L
liaogang 已提交
259

L
liaogang 已提交
260 261 262 263 264
        1. a CUDA-capable GPU
        2. Mac OS X 10.11 or later
        2. the Clang compiler and toolchain installed using Xcode
        3. NVIDIA CUDA Toolkit (available at http://developer.nvidia.com/cuda-downloads)
        4. NVIDIA cuDNN Library (availabel at https://developer.nvidia.com/cudnn)
L
liaogang 已提交
265

L
liaogang 已提交
266 267 268 269 270
    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.
        
    1. After downloading cuDNN library, issue the following commands:
L
liaogang 已提交
271

L
liaogang 已提交
272 273 274 275
        ```bash
        sudo tar -xzf cudnn-7.5-osx-x64-v5.0-ga.tgz -C /usr/local
        sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
        ```
276
    2. Then you need to set DYLD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.
L
liaogang 已提交
277

L
liaogang 已提交
278 279 280 281
        ```bash
        export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
        export PATH=/usr/local/cuda/bin:$PATH
        ```
L
liaogang 已提交
282

L
liaogang 已提交
283
### Build and Install
L
liaogang 已提交
284

L
liaogang 已提交
285
As usual, the best option is to create build folder under paddle project directory.
L
liaogang 已提交
286 287

```bash
L
liaogang 已提交
288 289
mkdir build && cd build
cmake ..
L
liaogang 已提交
290 291
```

L
liaogang 已提交
292
CMake first check PaddlePaddle's dependencies in system default path. After installing some optional
L
liaogang 已提交
293 294
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.
L
liaogang 已提交
295

L
liaogang 已提交
296
As a simple example, consider the following:
L
liaogang 已提交
297

L
liaogang 已提交
298
- **Only CPU**
L
liaogang 已提交
299

L
liaogang 已提交
300 301 302 303
  ```bash
  cmake  .. -DWITH_GPU=OFF -DWITH_DOC=OFF
  ```
- **GPU**
L
liaogang 已提交
304

L
liaogang 已提交
305 306 307
  ```bash
  cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF
  ```
L
liaogang 已提交
308

L
liaogang 已提交
309
- **GPU with doc and swig**
L
liaogang 已提交
310

L
liaogang 已提交
311 312 313
  ```bash
  cmake .. -DWITH_GPU=ON -DWITH_DOC=ON -DWITH_SWIG_PY=ON
  ``` 
L
liaogang 已提交
314

L
liaogang 已提交
315
Finally, you can build PaddlePaddle:
L
liaogang 已提交
316 317 318

```bash
# you can add build option here, such as:    
L
liaogang 已提交
319 320
cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX=<installation path>
# please use sudo make install, if you want to install PaddlePaddle into the system
L
liaogang 已提交
321
make -j `nproc` && make install
L
liaogang 已提交
322 323
# set PaddlePaddle installation path in ~/.bashrc
export PATH=<installation path>/bin:$PATH
L
liaogang 已提交
324
```
L
liaogang 已提交
325 326 327 328 329 330
**Note:**

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:
L
liaogang 已提交
331 332

```bash
L
liaogang 已提交
333
# you can run
L
liaogang 已提交
334
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
L
liaogang 已提交
335 336
# or just run 
sudo paddle version
L
liaogang 已提交
337
```