Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add centos support, including building from source doc, rpm package and docker images #212

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/cudnn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif()
if(CUDNN_FOUND)
file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_VERSION_FILE_CONTENTS)

get_filename_component(CUDNN_LIB_PATH ${CUDNN_LIBRARY} DIRECTORY)
get_filename_component(CUDNN_LIB_PATH ${CUDNN_LIBRARY} PATH)

string(REGEX MATCH "define CUDNN_VERSION +([0-9]+)"
CUDNN_VERSION "${CUDNN_VERSION_FILE_CONTENTS}")
Expand Down
5 changes: 4 additions & 1 deletion cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ set(CPACK_PACKAGE_DESCRIPTION "")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libatlas3-base, libgflags2, libgoogle-glog0, libprotobuf8, libpython2.7, libstdc++6, python-numpy, python-pip, python-pip-whl, python-protobuf")
set(CPACK_DEBIAN_PACKAGE_SECTION Devel)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJ_ROOT}/paddle/scripts/deb/postinst")
#set(CPACK_GENERATOR "DEB")
## RPM Settings
set(CPACK_RPM_PACKAGE_NAME paddle)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJ_ROOT}/paddle/scripts/rpm/postinst")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So where is RPM CPACK_RPM_PACKAGE_REQUIRES?

set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /usr/bin /usr/opt)
# Start cpack
include (CMakePackageConfigHelpers)
include (CPack)
Expand Down
115 changes: 109 additions & 6 deletions doc/build/build_from_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Installing from Sources
* [1. Download and Setup](#download)
* [2. Requirements](#requirements)
* [3. Build on Ubuntu](#ubuntu)
* [4. Build on Mac OS X](#mac)
* [4. Build on Centos](#centos)
* [5. Build on Mac OS X](#mac)

## <span id="download">Download and Setup</span>
You can download PaddlePaddle from the [github source](https://github.com/gangliao/Paddle).
You can download PaddlePaddle from the [github source](https://github.com/baidu/Paddle).

```bash
git clone https://github.com/baidu/Paddle paddle
Expand Down Expand Up @@ -61,8 +62,10 @@ As a simple example, consider the following:
To compile PaddlePaddle with python predict API, make sure swig installed and set `-DWITH_SWIG_PY=ON` as follows:

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

Expand All @@ -80,6 +83,8 @@ As a simple example, consider the following:

# install doxygen on Ubuntu
sudo apt-get install doxygen
# install doxygen on Centos
sudo yum install doxygen
# install doxygen on Mac OS X
brew install doxygen

Expand Down Expand Up @@ -171,13 +176,112 @@ Finally, you can build PaddlePaddle:

```bash
# you can add build option here, such as:
cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX=<path to install>
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
make -j `nproc` && make install
# set PaddlePaddle installation path in ~/.bashrc
export PATH=<path to install>/bin:$PATH
export PATH=<installation path>/bin:$PATH
```
**Note:**

If you set `WITH_SWIG_PY=ON`, related python dependencies also need to be installed.
Otherwise, PaddlePaddle will automatically install python dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不对的,即使设置了swig ON, 第一次调用paddle的时候,也会把dependencies装完。

at first time when user run paddle commands, such as `paddle version`, `paddle train`.
It may require sudo privileges:

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

## <span id="centos">Build on Centos 7</span>

### Install Dependencies

- **CPU Dependencies**

```bash
# necessary
sudo yum -y update
sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
sudo yum -y install git gcc gcc-c++ make cmake python-devel openblas-devel protobuf-devel protobuf-python m4 python-pip
sudo pip install --upgrade pip
sudo pip install 'numpy>=1.11.0'
sudo pip install wheel
# optional
sudo yum -y install glog-devel gflags-devel gtest-devel
```

- **GPU Dependencies (optional)**

To build GPU version, you will need the following installed:

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*
```
Then you need to set LD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc.

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

```bash
mkdir build && cd build
cmake ..
```

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

Finally, you can build PaddlePaddle:

```bash
# you can add build option here, such as:
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
make -j `nproc` && make install
# set PaddlePaddle installation path in ~/.bashrc
export PATH=<installation path>/bin:$PATH
```
**Note:**

If you set `WITH_SWIG_PY=ON`, related python dependencies also need to be installed.
Expand Down Expand Up @@ -254,7 +358,6 @@ easy_install pip
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.
Expand Down
3 changes: 2 additions & 1 deletion doc/build/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ Install PaddlePaddle
internal/install_from_jumbo.md
docker_install.rst
ubuntu_install.rst
centos_install.rst

Build from Source
-----------------

.. warning::

Please use :code:`deb` package or :code:`docker` image to install paddle. The building guide is used for hacking or contributing to PaddlePaddle.
Please use :code:`deb` package, :code:`rpm` package or :code:`docker` image to install paddle. The building guide is used for hacking or contributing to PaddlePaddle.


If you want to hack and contribute PaddlePaddle source code, following guides can help you\:
Expand Down
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.cpu-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM centos:7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=OFF
ENV IS_DEVEL=OFF
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=ON
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.cpu-demo-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM centos:7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=OFF
ENV IS_DEVEL=ON
ENV WITH_DEMO=ON
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=ON
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.cpu-devel-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM centos:7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=OFF
ENV IS_DEVEL=ON
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=ON
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.cpu-noavx-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM centos:7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=OFF
ENV IS_DEVEL=OFF
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=OFF
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.cpu-noavx-demo-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM centos:7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=OFF
ENV IS_DEVEL=ON
ENV WITH_DEMO=ON
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=OFF
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.cpu-noavx-devel-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM centos:7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=OFF
ENV IS_DEVEL=ON
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=OFF
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.gpu-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nvidia/cuda:7.5-cudnn5-devel-centos7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=ON
ENV IS_DEVEL=OFF
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=ON
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.gpu-demo-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nvidia/cuda:7.5-cudnn5-devel-centos7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=ON
ENV IS_DEVEL=ON
ENV WITH_DEMO=ON
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=ON
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.gpu-devel-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nvidia/cuda:7.5-cudnn5-devel-centos7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=ON
ENV IS_DEVEL=ON
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=ON
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.gpu-noavx-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nvidia/cuda:7.5-cudnn5-devel-centos7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=ON
ENV IS_DEVEL=OFF
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=OFF
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.gpu-noavx-demo-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nvidia/cuda:7.5-cudnn5-devel-centos7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=ON
ENV IS_DEVEL=ON
ENV WITH_DEMO=ON
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=OFF
RUN cd /root/ && bash build_centos.sh
11 changes: 11 additions & 0 deletions paddle/scripts/docker/Dockerfile.gpu-noavx-devel-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nvidia/cuda:7.5-cudnn5-devel-centos7
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build_centos.sh /root/
ENV WITH_GPU=ON
ENV IS_DEVEL=ON
ENV WITH_DEMO=OFF
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=OFF
RUN cd /root/ && bash build_centos.sh
4 changes: 2 additions & 2 deletions paddle/scripts/docker/Dockerfile.m4
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM PADDLE_BASE_IMAGE
MAINTAINER PaddlePaddle Dev Team <[email protected]>
COPY build.sh /root/
COPY BUILD_SCRIPT /root/
ENV WITH_GPU=PADDLE_WITH_GPU
ENV IS_DEVEL=PADDLE_IS_DEVEL
ENV WITH_DEMO=PADDLE_WITH_DEMO
ENV PIP_INSTALL_ARGS ""
ENV PIP_GENERAL_ARGS ""
ENV USE_UBUNTU_MIRROR OFF
ENV WITH_AVX=PADDLE_WITH_AVX
RUN cd /root/ && bash build.sh
RUN cd /root/ && bash BUILD_SCRIPT
43 changes: 43 additions & 0 deletions paddle/scripts/docker/build_centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

function abort(){
echo "An error occurred. Exiting..." 1>&2
exit 1
}

trap 'abort' 0
set -e
yum -y update
rpm -Uvh http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
yum -y install git gcc gcc-c++ make cmake python-devel openblas-devel protobuf-devel protobuf-python m4 python-pip swig
yum -y install glog-devel gflags-devel
pip install --upgrade pip
pip install wheel
pip install 'numpy>=1.11.0'


cd ~
git clone https://github.com/baidu/Paddle.git paddle
cd paddle
mkdir build
cd build
cmake .. -DWITH_DOC=OFF -DWITH_GPU=${WITH_GPU} -DWITH_SWIG_PY=ON\
-DWITH_STYLE_CHECK=OFF -DWITH_AVX=${WITH_AVX}
make -j `nproc`
# because durning make install, there are several warning, so set +e, do not cause abort
make install
echo 'export LD_LIBRARY_PATH=/usr/lib64:${LD_LIBRARY_PATH}' >> /etc/profile
pip ${PIP_GENERAL_ARGS} install ${PIP_INSTALL_ARGS} /usr/local/opt/paddle/share/wheels/*.whl
paddle version # print version after build

if [ ${WITH_DEMO} == "ON" ]; then
pip ${PIP_GENERAL_ARGS} install ${PIP_INSTALL_ARGS} BeautifulSoup docopt \
PyYAML pillow
fi
if [ ${IS_DEVEL} == "OFF" ]; then # clean build packages.
cd ~
rm -rf paddle
fi
rm -rf /var/cache/yum/*
rm -rf /root/.cache/pip/*
trap : 0
Loading