build_from_source_en.rst 9.5 KB
Newer Older
武毅 已提交
1
Build from Sources
T
typhoonzero 已提交
2 3
==========================

4
.. _requirements:
T
typhoonzero 已提交
5

6
Requirements
T
typhoonzero 已提交
7 8
----------------

9 10 11
To build PaddlePaddle, you need

1. A computer -- Linux, Windows, MacOS.
12
2. Docker.
13

W
weixing02 已提交
14
Nothing else.  Not even Python and GCC, because you can install all build tools into a Docker image.
15 16 17
We run all the tools by running this image.

.. _build_step:
武毅 已提交
18

19 20
How To Build
----------------
武毅 已提交
21

22 23 24
You need to use Docker to build PaddlePaddle
to avoid installing dependencies by yourself. We have several pre-built
Docker images `here <https://hub.docker.com/r/paddlepaddle/paddle_manylinux_devel/tags/>`_ ,
25
you can also find how to build and use paddle_manylinux_devel Docker image from
26
`here <https://github.com/PaddlePaddle/Paddle/tree/develop/tools/manylinux1/>`__
27
Or you can build your own image from source as the optional step below:
T
typhoonzero 已提交
28

W
weixing02 已提交
29 30
If you don't wish to use docker,you need to install several compile dependencies manually as :ref:`Compile Dependencies <_compile_deps>` shows to start compilation.

T
typhoonzero 已提交
31 32
.. code-block:: bash

33
   # 1. clone the source code
T
typhoonzero 已提交
34 35
   git clone https://github.com/PaddlePaddle/Paddle.git
   cd Paddle
36 37 38
   # 2. Optional: build development docker image from source
   docker build -t paddle:dev .
   # 3. Run the following command to build a CPU-Only binaries
Y
Yancey 已提交
39
   docker run -it -v $PWD:/paddle -w /paddle -e "PYTHON_ABI=cp27-cp27mu" -e "WITH_GPU=OFF" -e "WITH_TESTING=OFF" paddlepaddle/paddle_manylinux_devel:cuda8.0_cudnn5 ./paddle/scripts/paddle_build.sh build
40
   # 4. Or, use your built Docker image to build PaddlePaddle (must run step 2)
L
Lei Wang 已提交
41
   docker run -it -v $PWD:/paddle -w /paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=OFF" paddle:dev ./paddle/scripts/paddle_build.sh build
42

Y
Yancey 已提交
43 44 45
NOTE: 

- The above command try to mount the current working directory (root directory of source code)
L
Lei Wang 已提交
46
into :code:`/paddle` directory inside docker container.
T
typhoonzero 已提交
47

Y
Yancey 已提交
48 49 50
- You need to pass in the required environment variable :code:`PYTHON_ABI` to specify a `Python ABI <https://www.python.org/dev/peps/pep-0425/#id8>`__.
Currently PaddlePaddle supported Python ABIs include :code:`cp27-cp27m` and :code:`cp27-cp27mu` .

T
typhoonzero 已提交
51 52 53 54 55 56
When the compile finishes, you can get the output whl package under
build/python/dist, then you can choose to install the whl on local
machine or copy it to the target machine.

.. code-block:: bash

57
   pip install build/python/dist/*.whl
T
typhoonzero 已提交
58

L
Luo Tao 已提交
59
If the machine has installed PaddlePaddle before, there are two methods:
60 61 62

.. code-block:: bash

L
Luo Tao 已提交
63 64 65 66 67
   1. uninstall and reinstall
   pip uninstall paddlepaddle
   pip install build/python/dist/*.whl

   2. upgrade directly
68
   pip install build/python/dist/*.whl -U
武毅 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81

.. _run_test:

Run Tests
----------------

If you wish to run the tests, you may follow the below steps:

When using Docker, set :code:`RUN_TEST=ON` and :code:`WITH_TESTING=ON` will run test immediately after the build.
Set :code:`WITH_GPU=ON` Can also run tests on GPU.

.. code-block:: bash

L
Lei Wang 已提交
82
   docker run -it -v $PWD:/paddle -w /paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=ON" -e "RUN_TEST=ON" paddlepaddle/paddle_manylinux_devel:cuda8.0_cudnn5 ./paddle/scripts/paddle_build.sh test
武毅 已提交
83

84
If you wish to run only one unit test, like :code:`test_sum_op`:
武毅 已提交
85 86 87

.. code-block:: bash

L
Lei Wang 已提交
88 89 90
   docker run -it -v $PWD:/paddle -w /paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=ON" -e "RUN_TEST=OFF" paddlepaddle/paddle_manylinux_devel:cuda8.0_cudnn5 /bin/bash
   ./paddle/scripts/paddle_build.sh build
   cd build
91 92 93 94 95
   ctest -R test_sum_op -V

.. _faq_docker:

Frequently Asked Questions
96
---------------------------
97 98 99 100 101 102 103 104 105 106 107 108 109 110

- What is Docker?

  If you haven't heard of it, consider it something like Python's virtualenv.

- Docker or virtual machine?

  Some people compare Docker with VMs, but Docker doesn't virtualize any hardware nor running a guest OS, which means there is no compromise on the performance.

- Why Docker?

  Using a Docker image of build tools standardizes the building environment, which makes it easier for others to reproduce your problems and to help.

  Also, some build tools don't run on Windows or Mac or BSD, but Docker runs almost everywhere, so developers can use whatever computer they want.
武毅 已提交
111

112 113 114 115 116 117
- Can I choose not to use Docker?

  Sure, you don't have to install build tools into a Docker image; instead, you can install them on your local computer.  This document exists because Docker would make the development way easier.

- How difficult is it to learn Docker?

W
weixing02 已提交
118
    It takes you ten minutes to read `an introductory article <https://docs.docker.com/get-started>`_ and saves you more than one hour to install all required build tools, configure them, especially when new versions of PaddlePaddle require some new tools.  Not even to mention the time saved when other people trying to reproduce the issue you have.
119 120 121 122 123 124 125

- Can I use my favorite IDE?

  Yes, of course.  The source code resides on your local computer, and you can edit it using whatever editor you like.

  Many PaddlePaddle developers are using Emacs.  They add the following few lines into their `~/.emacs` configure file:

W
Wang,Jeff 已提交
126 127 128 129
  .. code-block:: emacs

    (global-set-key "\C-cc" 'compile)
    (setq compile-command "docker run --rm -it -v $(git rev-parse --show-toplevel):/paddle paddle:dev")
130 131 132 133 134

  so they could type `Ctrl-C` and `c` to build PaddlePaddle from source.

- Does Docker do parallel building?

W
weixing02 已提交
135
  Our building Docker image runs a  `Bash script <https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build.sh>`_ , which calls `make -j$(nproc)` to starts as many processes as the number of your CPU cores.
136 137 138 139 140 141 142

- Docker requires sudo

  An owner of a computer has the administrative privilege, a.k.a., sudo, and Docker requires this privilege to work properly.  If you use a shared computer for development, please ask the administrator to install and configure Docker.  We will do our best to support rkt, another container technology that doesn't require sudo.

- Docker on Windows/MacOS builds slowly

W
weixing02 已提交
143
  On Windows and MacOS, Docker containers run in a Linux VM.  You might want to give this VM some more memory and CPUs so to make the building efficient.  Please refer to `this issue  <https://github.com/PaddlePaddle/Paddle/issues/627>`_ for details.
144 145 146

- Not enough disk space

W
weixing02 已提交
147
  Examples in this article use option `--rm` with the `docker run` command.  This option ensures that stopped containers do not exist on hard disks.  We can use `docker ps -a` to list all containers, including stopped.  Sometimes `docker build` generates some intermediate dangling images, which also take disk space.  To clean them, please refer to `this article <https://zaiste.net/posts/removing_docker_containers/>`_ .
武毅 已提交
148 149

.. _compile_deps:
T
typhoonzero 已提交
150

151
Appendix: Compile Dependencies
152
-------------------------------
T
typhoonzero 已提交
153 154 155 156 157 158 159 160

PaddlePaddle need the following dependencies when compiling, other dependencies
will be downloaded automatically.

.. csv-table:: PaddlePaddle Compile Dependencies
   :header: "Dependency", "Version", "Description"
   :widths: 10, 15, 30

T
typhoonzero 已提交
161
   "CMake", ">=3.2", ""
T
typhoonzero 已提交
162
   "GCC", "4.8.2", "Recommend devtools2 for CentOS"
T
update  
typhoonzero 已提交
163 164 165
   "Python", "2.7.x", "Need libpython2.7.so"
   "pip", ">=9.0", ""
   "numpy", "", ""
T
typhoonzero 已提交
166
   "SWIG", ">=2.0", ""
T
update  
typhoonzero 已提交
167
   "Go", ">=1.8", "Optional"
T
typhoonzero 已提交
168 169 170 171


.. _build_options:

172
Appendix: Build Options
173
-------------------------
T
typhoonzero 已提交
174 175 176

Build options include whether build binaries for CPU or GPU, which BLAS
library to use etc. You may pass these settings when running cmake.
177
For detailed cmake tutorial please refer to `here <https://cmake.org/cmake-tutorial>`__ 。
T
typhoonzero 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190


You can add :code:`-D` argument to pass such options, like:

..  code-block:: bash

    cmake .. -DWITH_GPU=OFF

..  csv-table:: Bool Type Options
    :header: "Option", "Description", "Default"
    :widths: 1, 7, 2

    "WITH_GPU", "Build with GPU support", "ON"
T
typhoonzero 已提交
191
    "WITH_C_API", "Build only CAPI", "OFF"
T
typhoonzero 已提交
192 193 194 195 196
    "WITH_DOUBLE", "Build with double precision", "OFF"
    "WITH_DSO", "Dynamically load CUDA libraries", "ON"
    "WITH_AVX", "Build with AVX support", "ON"
    "WITH_PYTHON", "Build with integrated Python interpreter", "ON"
    "WITH_STYLE_CHECK", "Check code style when building", "ON"
197
    "WITH_TESTING", "Build unit tests", "OFF"
198
    "WITH_DOC", "Build documentations", "OFF"
T
typhoonzero 已提交
199
    "WITH_SWIG_PY", "Build Python SWIG interface for V2 API", "Auto"
200
    "WITH_GOLANG", "Build fault-tolerant parameter server written in go", "OFF"
T
typhoonzero 已提交
201
    "WITH_MKL", "Use MKL as BLAS library, else use OpenBLAS", "ON"
T
typhoonzero 已提交
202 203 204 205 206


BLAS
+++++

T
typhoonzero 已提交
207 208 209 210 211 212 213 214
PaddlePaddle supports `MKL <https://software.intel.com/en-us/intel-mkl>`_ and
`OpenBlAS <http://www.openblas.net/>`_ as BLAS library。By default it uses MKL.
If you are using MKL and your machine supports AVX2, MKL-DNN will also be downloaded
and used, for more `details <https://github.com/PaddlePaddle/Paddle/tree/develop/doc/design/mkldnn#cmake>`_ .

If you choose not to use MKL, then OpenBlAS will be used.

CUDA/cuDNN
T
typhoonzero 已提交
215 216
+++++++++++

T
typhoonzero 已提交
217
PaddlePaddle will automatically find CUDA and cuDNN when compiling and running.
T
typhoonzero 已提交
218 219
parameter :code:`-DCUDA_ARCH_NAME=Auto` can be used to detect SM architecture
automatically in order to speed up the build.
T
typhoonzero 已提交
220 221 222

PaddlePaddle can build with any version later than cuDNN v5.1, and we intend to
keep on with latest cuDNN versions. Be sure to run with the same version of cuDNN
T
typhoonzero 已提交
223 224 225
you built.

Pass Compile Options
226
++++++++++++++++++++++
T
typhoonzero 已提交
227 228 229

You can pass compile options to use intended BLAS/CUDA/Cudnn libraries.
When running cmake command, it will search system paths like
T
typhoonzero 已提交
230
:code:`/usr/lib:/usr/local/lib` and then search paths that you
T
typhoonzero 已提交
231 232 233 234
passed to cmake, i.e.

..  code-block:: bash

T
typhoonzero 已提交
235
    cmake .. -DWITH_GPU=ON -DWITH_TESTING=OFF -DCUDNN_ROOT=/opt/cudnnv5
T
typhoonzero 已提交
236

T
typhoonzero 已提交
237
**NOTE: These options only take effect when running cmake for the first time, you need to clean the cmake cache or clean the build directory (** :code:`rm -rf` **) if you want to change it.**