build_from_source_en.rst 5.0 KB
Newer Older
武毅 已提交
1
Build from Sources
T
typhoonzero 已提交
2 3 4 5 6 7 8 9 10 11
==========================

.. _build_step:

How To Build
----------------

PaddlePaddle mainly uses `CMake <https://cmake.org>`_ and GCC, G++ as compile
tools. We recommend you to use our pre-built Docker image to run the build
to avoid installing dependencies by yourself. We have several build environment
武毅 已提交
12 13 14 15 16
Docker images `here <https://hub.docker.com/r/paddlepaddle/paddle_manylinux_devel/tags/>`_ .

If you choose not to use Docker image for your build, you need to install the
below `Compile Dependencies`_ before run the build.

T
typhoonzero 已提交
17 18 19 20 21 22
Then run:

.. code-block:: bash

   git clone https://github.com/PaddlePaddle/Paddle.git
   cd Paddle
武毅 已提交
23
   # run the following command to build a CPU-Only binaries if you are using docker
24
   docker run -it -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=OFF" paddlepaddle/paddle_manylinux_devel:cuda8.0_cudnn5 bash -x /paddle/paddle/scripts/docker/build.sh
T
typhoonzero 已提交
25 26 27
   # else run these commands
   mkdir build
   cd build
T
typhoonzero 已提交
28
   cmake -DWITH_GPU=OFF -DWITH_TESTING=OFF ..
T
typhoonzero 已提交
29 30 31 32 33 34 35 36
   make

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

37
   pip install build/python/dist/*.whl
T
typhoonzero 已提交
38

武毅 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51

.. _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

52
   docker run -it -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=ON" -e "RUN_TEST=ON" paddlepaddle/paddle_manylinux_devel:cuda8.0_cudnn5 bash -x paddle/paddle/scripts/docker/build.sh
武毅 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

If you don't use Docker, just run ctest will start the tests:

.. code-block:: bash

   mkdir build
   cd build
   cmake -DWITH_GPU=OFF -DWITH_TESTING=ON ..
   make
   ctest
   # run a single test like test_mul_op
   ctest -R test_mul_op


.. _compile_deps:
T
typhoonzero 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

Compile Dependencies
----------------

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

   "CMake", ">=3.5", ""
   "GCC", "4.8.2", "Recommend devtools2 for CentOS"
   "Python", "2.7.x", "Need libpython2.7.so"
   "pip", ">=9.0", ""
   "numpy", "", ""
   "SWIG", ">=2.0", ""
   "Go", ">=1.8", "Optional"


.. _build_options:

Build Options
----------------

Build options include whether build binaries for CPU or GPU, which BLAS
library to use etc. You may pass these settings when running cmake.
For detailed cmake tutorial please refer to `here <https://cmake.org/cmake-tutorial>`_ 。

.. _build_options_bool:

Bool Type Options
----------------

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 已提交
113
    "WITH_C_API", "Build only CAPI", "OFF"
T
typhoonzero 已提交
114 115 116 117 118 119
    "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"
    "WITH_TESTING", "Build unit tests", "ON"
120
    "WITH_DOC", "Build documentations", "OFF"
T
typhoonzero 已提交
121 122
    "WITH_SWIG_PY", "Build Python SWIG interface for V2 API", "Auto"
    "WITH_GOLANG", "Build fault-tolerant parameter server written in go", "ON"
T
typhoonzero 已提交
123
    "WITH_MKL", "Use MKL as BLAS library, else use OpenBLAS", "ON"
T
typhoonzero 已提交
124 125 126 127 128


BLAS
+++++

T
typhoonzero 已提交
129 130 131 132 133 134 135 136
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 已提交
137 138
+++++++++++

T
typhoonzero 已提交
139
PaddlePaddle will automatically find CUDA and cuDNN when compiling and running.
T
typhoonzero 已提交
140 141
parameter :code:`-DCUDA_ARCH_NAME=Auto` can be used to detect SM architecture
automatically in order to speed up the build.
T
typhoonzero 已提交
142 143 144

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 已提交
145 146 147 148 149 150 151
you built.

Pass Compile Options
++++++++++++++

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

..  code-block:: bash

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

T
typhoonzero 已提交
159
**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.**