build_from_source.txt 9.9 KB
Newer Older
1
Installing from Sources
Y
Yu Yang 已提交
2 3
=================

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

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

12 13
```bash
git clone https://github.com/baidu/Paddle paddle
14
cd paddle
15 16 17 18
```

## <span id="requirements">Requirements</span>

19
To compile the source code, your computer must be equipped with GCC >=4.6 or Clang compiler.
20 21 22 23 24 25 26 27 28 29 30
### Dependencies

- **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

### Options

PaddlePaddle supports some build options. To enable it, first you need to install the related libraries. 

31 32 33 34 35 36 37 38 39 40 41

| Optional             | Description                                                                  |
| -------------------- | :--------------------------------------------------------------------------- |
| **WITH_GPU**         | Compile with GPU mode.                                                       |
| **WITH_DOUBLE**      | Compile with double precision floating-point, default: single precision.     |
| **WITH_GLOG**        | Compile with glog. If not found, default: an internal log implementation.    |
| **WITH_GFLAGS**      | Compile with gflags. If not found, default: an internal flag implementation. |
| **WITH_TESTING**     | Compile with gtest for PaddlePaddle's unit testing.                          |
| **WITH_DOC**         | Compile to generate PaddlePaddle's docs, default: disabled (OFF).            |
| **WITH_SWIG_PY**     | Compile with python predict API, default: disabled (OFF).                    |
| **WITH_STYLE_CHECK** | Compile with code style check, default: enabled (ON).                        |
Y
Yu Yang 已提交
42

43 44 45 46
**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.**
Y
Yu Yang 已提交
47

48
As a simple example, consider the following:  
Y
Yu Yang 已提交
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
1. **Python Dependencies(optional)**
  
    To compile PaddlePaddle with python predict API, make sure swig installed and set `-DWITH_SWIG_PY=ON` as follows:

    ```bash
    # install swig on ubuntu
    sudo apt-get install swig
    # install swig on Mac OS X
    brew install swig

    # active swig in cmake
    cmake .. -DWITH_SWIG_PY=ON
    ```

2. **Doc Dependencies(optional)**

    To generate PaddlePaddle's documentation, install dependencies and set `-DWITH_DOC=ON` as follows:
Y
Yu Yang 已提交
67

68 69 70
    ```bash
    pip install 'sphinx>=1.4.0'
    pip install sphinx_rtd_theme breathe recommonmark
Y
Yu Yang 已提交
71

72 73 74 75 76 77 78 79 80 81
    # install doxygen on Ubuntu
    sudo apt-get install doxygen 
    # install doxygen on Mac OS X
    brew install doxygen

    # active docs in cmake
    cmake .. -DWITH_DOC=ON`
    ```

## <span id="ubuntu">Build on Ubuntu 14.04</span>
Y
Yu Yang 已提交
82 83 84 85 86

### Install Dependencies

- **CPU Dependencies**

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    ```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
    ```
Y
Yu Yang 已提交
102
  
103
- **GPU Dependencies (optional)**
Y
Yu Yang 已提交
104

105
    To build GPU version, you will need the following installed:
Y
Yu Yang 已提交
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        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*
    ```
122
    Then you need to set LD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.
123 124 125 126 127 128 129 130 131

    ```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.
Y
Yu Yang 已提交
132 133

```bash
134 135
mkdir build && cd build
cmake ..
Y
Yu Yang 已提交
136
```
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

CMake first check PaddlePaddle's dependencies in system default path. After installing some optional
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.

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
  ``` 

161
Finally, you can build PaddlePaddle:
Y
Yu Yang 已提交
162 163

```bash
164 165
# you can add build option here, such as:    
cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX=<path to install>
166
# please use sudo make install, if you want to install PaddlePaddle into the system
167 168 169
make -j `nproc` && make install
# set PaddlePaddle installation path in ~/.bashrc
export PATH=<path to install>/bin:$PATH
Y
Yu Yang 已提交
170 171
```

172 173 174 175 176 177
**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:
Y
Yu Yang 已提交
178 179

```bash
180 181 182 183
# you can run
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
# or just run 
sudo paddle version
Y
Yu Yang 已提交
184 185
```

186
## <span id="mac">Building on Mac OS X</span>
Y
Yu Yang 已提交
187

188 189 190 191 192 193
### 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.
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:
Y
Yu Yang 已提交
194 195

```bash
196 197 198 199
# install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install pip
easy_install pip
Y
Yu Yang 已提交
200 201
```

202
### Install Dependencies
Y
Yu Yang 已提交
203

204
- **CPU Dependencies**
Y
Yu Yang 已提交
205

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
  ```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
  ```
Y
Yu Yang 已提交
221

222
- **GPU Dependencies(optional)**
Y
Yu Yang 已提交
223

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    To build GPU version, you will need the following installed:

        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)

    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:

        ```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*
        ```
242
    2. Then you need to set DYLD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.
Y
Yu Yang 已提交
243

244 245 246 247 248 249 250 251
        ```bash
        export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_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.
Y
Yu Yang 已提交
252 253

```bash
254 255
mkdir build && cd build
cmake ..
Y
Yu Yang 已提交
256 257
```

258 259 260
CMake first check PaddlePaddle's dependencies in system default path. After installing some optional
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.
Y
Yu Yang 已提交
261

262
As a simple example, consider the following:
Y
Yu Yang 已提交
263

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
- **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
  ``` 

Finally, you can build PaddlePaddle:
Y
Yu Yang 已提交
282 283 284

```bash
# you can add build option here, such as:    
285 286
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
Y
Yu Yang 已提交
287
make -j `nproc` && make install
288 289
# set PaddlePaddle installation path in ~/.bashrc
export PATH=<installation path>/bin:$PATH
Y
Yu Yang 已提交
290
```
291 292 293 294 295 296
**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:
Y
Yu Yang 已提交
297 298

```bash
299 300 301 302 303
# you can run
sudo pip install <path to install>/opt/paddle/share/wheels/*.whl
# or just run 
sudo paddle version
```