Skip to content

Commit 133dfc0

Browse files
authored
Merge pull request #629 from wangkuiyi/docker_openssh
Re-define the way we build Docker images
2 parents 95ef1af + 8e6965b commit 133dfc0

18 files changed

+131
-349
lines changed

CMakeLists.txt

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
cmake_minimum_required(VERSION 2.8)
22

33
project(paddle CXX C)
4-
set(PADDLE_MAJOR_VERSION 0)
5-
set(PADDLE_MINOR_VERSION 9)
6-
set(PADDLE_PATCH_VERSION 0)
7-
set(PADDLE_VERSION ${PADDLE_MAJOR_VERSION}.${PADDLE_MINOR_VERSION}.${PADDLE_PATCH_VERSION})
84

95
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
106
set(PROJ_ROOT ${CMAKE_SOURCE_DIR})
@@ -56,7 +52,7 @@ option(ON_COVERALLS "Generating code coverage data on coveralls or not." OFF)
5652
option(COVERALLS_UPLOAD "Uploading the generated coveralls json." ON)
5753

5854
if(NOT CMAKE_BUILD_TYPE)
59-
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
55+
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
6056
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel"
6157
FORCE)
6258
endif()
@@ -75,31 +71,11 @@ include(check_packages)
7571
include(swig)
7672
include(coveralls)
7773

78-
# add PaddlePaddle version
79-
if(DEFINED ENV{PADDLE_VERSION})
80-
add_definitions(-DPADDLE_VERSION=\"$ENV{PADDLE_VERSION}\")
81-
else()
82-
if(EXISTS ${PROJ_ROOT}/.svn/)
83-
find_package(Subversion REQUIRED)
84-
if(SUBVERSION_FOUND)
85-
Subversion_WC_INFO(${PROJ_ROOT} Project)
86-
add_definitions(-DPADDLE_VERSION=${Project_WC_REVISION})
87-
endif()
88-
elseif(EXISTS ${PROJ_ROOT}/.git/)
89-
find_package(Git REQUIRED)
90-
execute_process(
91-
COMMAND ${GIT_EXECUTABLE} log -1 --format=%H
92-
WORKING_DIRECTORY ${PROJ_ROOT}
93-
OUTPUT_VARIABLE GIT_SHA1
94-
RESULT_VARIABLE GIT_RESULT
95-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
96-
if(NOT ${GIT_RESULT})
97-
add_definitions(-DPADDLE_VERSION=\"${GIT_SHA1}\")
98-
else()
99-
message(WARNING "Cannot add paddle version from git tag")
100-
endif()
101-
endif()
102-
endif()
74+
# Set PaddlePaddle version to Git tag name or Git commit ID.
75+
find_package(Git REQUIRED)
76+
# version.cmake will get the current PADDLE_VERSION
77+
include(version)
78+
add_definitions(-DPADDLE_VERSION=\"${PADDLE_VERSION}\")
10379

10480

10581
if(NOT WITH_GPU)

cmake/version.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Get the latest git tag.
2+
set(PADDLE_VERSION $ENV{PADDLE_VERSION})
3+
set(tmp_version "HEAD")
4+
while ("${PADDLE_VERSION}" STREQUAL "")
5+
execute_process(
6+
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 ${tmp_version}
7+
WORKING_DIRECTORY ${PROJ_ROOT}
8+
OUTPUT_VARIABLE GIT_TAG_NAME
9+
RESULT_VARIABLE GIT_RESULT
10+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
11+
if (NOT ${GIT_RESULT})
12+
# Check the tag is a correct version
13+
if (${GIT_TAG_NAME} MATCHES "v[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
14+
string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
15+
else() # otherwise, get the previous git tag name.
16+
set(tmp_version "${GIT_TAG_NAME}~1")
17+
endif()
18+
else()
19+
set(PADDLE_VERSION "0.0.0")
20+
message(WARNING "Cannot add paddle version from git tag")
21+
endif()
22+
endwhile()
23+
24+
message(STATUS "Paddle version is ${PADDLE_VERSION}")
Lines changed: 47 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,81 @@
1-
Docker installation guide
2-
==========================
1+
Using and Building Docker Images
2+
================================
33

4-
PaddlePaddle provide the `Docker <https://www.docker.com/>`_ image. `Docker`_ is a lightweight container utilities. The performance of PaddlePaddle in `Docker`_ container is basically as same as run it in a normal linux. The `Docker`_ is a very convenient way to deliver the binary release for linux programs.
4+
We release PaddlePaddle in the form of `Docker <https://www.docker.com/>`_ images on `dockerhub.com <https://hub.docker.com/r/paddledev/paddle/>`_. Running as Docker containers is currently the only officially-supported way to running PaddlePaddle.
55

6-
.. note::
6+
Run Docker images
7+
-----------------
78

8-
The `Docker`_ image is the recommended way to run PaddlePaddle
9+
For each version of PaddlePaddle, we release 4 variants of Docker images:
910

10-
PaddlePaddle Docker images
11-
--------------------------
11+
+-----------------+-------------+-------+
12+
| | CPU AVX | GPU |
13+
+=================+=============+=======+
14+
| cpu | yes | no |
15+
+-----------------+-------------+-------+
16+
| cpu-noavx | no | no |
17+
+-----------------+-------------+-------+
18+
| gpu | yes | yes |
19+
+-----------------+-------------+-------+
20+
| gpu-noavx | no | yes |
21+
+-----------------+-------------+-------+
1222

13-
There are 12 `images <https://hub.docker.com/r/paddledev/paddle/tags/>`_ for PaddlePaddle, and the name is :code:`paddle-dev/paddle`, tags are\:
23+
We run the following command on Linux to check if the CPU supports :code:`AVX`.
1424

25+
.. code-block:: bash
1526
16-
+-----------------+------------------+------------------------+-----------------------+
17-
| | normal | devel | demo |
18-
+=================+==================+========================+=======================+
19-
| CPU | cpu-latest | cpu-devel-latest | cpu-demo-latest |
20-
+-----------------+------------------+------------------------+-----------------------+
21-
| GPU | gpu-latest | gpu-devel-latest | gpu-demo-latest |
22-
+-----------------+------------------+------------------------+-----------------------+
23-
| CPU WITHOUT AVX | cpu-noavx-latest | cpu-devel-noavx-latest | cpu-demo-noavx-latest |
24-
+-----------------+------------------+------------------------+-----------------------+
25-
| GPU WITHOUT AVX | gpu-noavx-latest | gpu-devel-noavx-latest | gpu-demo-noavx-latest |
26-
+-----------------+------------------+------------------------+-----------------------+
27+
if cat /proc/cpuinfo | grep -i avx; then echo Yes; else echo No; fi
2728
28-
And the three columns are:
29+
On Mac OS X, we need to run
2930

30-
* normal\: The docker image only contains binary of PaddlePaddle.
31-
* devel\: The docker image contains PaddlePaddle binary, source code and essential build environment.
32-
* demo\: The docker image contains the dependencies to run PaddlePaddle demo.
31+
.. code-block:: bash
3332
34-
And the four rows are:
33+
sysctl -a | grep machdep.cpu.leaf7_features
3534
36-
* CPU\: CPU Version. Support CPU which has :code:`AVX` instructions.
37-
* GPU\: GPU Version. Support GPU, and cpu has :code:`AVX` instructions.
38-
* CPU WITHOUT AVX\: CPU Version, which support most CPU even doesn't have :code:`AVX` instructions.
39-
* GPU WITHOUT AVX\: GPU Version, which support most CPU even doesn't have :code:`AVX` instructions.
4035
41-
User can choose any version depends on machine. The following script can help you to detect your CPU support :code:`AVX` or not.
36+
Once we determine the proper variant, we can cope with the Docker image tag name by appending the version number. For example, the following command runs the AVX-enabled image of the most recent version:
4237

43-
.. code-block:: bash
44-
45-
if cat /proc/cpuinfo | grep -q avx ; then echo "Support AVX"; else echo "Not support AVX"; fi
38+
.. code-block:: bash
4639
47-
If the output is :code:`Support AVX`, then you can choose the AVX version of PaddlePaddle, otherwise, you need select :code:`noavx` version of PaddlePaddle. For example, the CPU develop version of PaddlePaddle is :code:`paddle-dev/paddle:cpu-devel-latest`.
40+
docker run -it --rm paddledev/paddle:cpu-latest /bin/bash
4841
49-
The PaddlePaddle images don't contain any entry command. You need to write your entry command to use this image. See :code:`Remote Access` part or just use following command to run a :code:`bash`
42+
To run a GPU-enabled image, you need to install CUDA and let Docker knows about it:
5043

51-
.. code-block:: bash
52-
53-
docker run -it paddledev/paddle:cpu-latest /bin/bash
54-
55-
56-
Download and Run Docker images
57-
------------------------------
58-
59-
You have to install Docker in your machine which has linux kernel version 3.10+ first. You can refer to the official guide https://docs.docker.com/engine/installation/ for further information.
60-
61-
You can use :code:`docker pull ` to download images first, or just launch a container with :code:`docker run` \:
62-
63-
.. code-block:: bash
64-
65-
docker run -it paddledev/paddle:cpu-latest
66-
67-
68-
If you want to launch container with GPU support, you need to set some environment variables at the same time:
69-
70-
.. code-block:: bash
44+
.. code-block:: bash
7145
7246
export CUDA_SO="$(\ls /usr/lib64/libcuda* | xargs -I{} echo '-v {}:{}') $(\ls /usr/lib64/libnvidia* | xargs -I{} echo '-v {}:{}')"
7347
export DEVICES=$(\ls /dev/nvidia* | xargs -I{} echo '--device {}:{}')
7448
docker run ${CUDA_SO} ${DEVICES} -it paddledev/paddle:gpu-latest
7549
50+
The default entry point of all our Docker images starts the OpenSSH server. To run PaddlePaddle and to expose OpenSSH port to 2202 on the host computer:
7651

77-
Some notes for docker
78-
---------------------
79-
80-
Performance
81-
+++++++++++
82-
83-
Since Docker is based on the lightweight virtual containers, the CPU computing performance maintains well. And GPU driver and equipments are all mapped to the container, so the GPU computing performance would not be seriously affected.
84-
85-
If you use high performance nic, such as RDMA(RoCE 40GbE or IB 56GbE), Ethernet(10GbE), it is recommended to use config "-net = host".
86-
87-
88-
89-
90-
Remote access
91-
+++++++++++++
92-
52+
.. code-block:: bash
9353
94-
If you want to enable ssh access background, you need to build an image by yourself. Please refer to official guide https://docs.docker.com/engine/reference/builder/ for further information.
54+
docker run -d -p 2202:22 paddledev/paddle:cpu-latest
9555
96-
Following is a simple Dockerfile with ssh:
56+
Then we can login to the container using username :code:`root` and password :code:`root`:
9757

98-
.. literalinclude:: ../../doc_cn/build_and_install/install/paddle_ssh.Dockerfile
58+
.. code-block:: bash
9959
100-
Then you can build an image with Dockerfile and launch a container:
60+
ssh -p 2202 root@localhost
10161
102-
.. code-block:: bash
10362
104-
# cd into Dockerfile directory
105-
docker build . -t paddle_ssh
106-
# run container, and map host machine port 8022 to container port 22
107-
docker run -d -p 8022:22 --name paddle_ssh_machine paddle_ssh
63+
Build Docker images
64+
-------------------
10865

109-
Now, you can ssh on port 8022 to access the container, username is root, password is also root:
66+
Developers might want to build Docker images from their local commit or from a tagged version. Suppose that your local repo is at :code:`~/work/Paddle`, the following steps builds a cpu variant from your current work:
11067

111-
.. code-block:: bash
68+
.. code-block:: bash
11269
113-
ssh -p 8022 root@YOUR_HOST_MACHINE
70+
cd ~/Paddle
71+
./paddle/scripts/docker/generates.sh # Use m4 to generate Dockerfiles for each variant.
72+
docker build -t paddle:latest -f ./paddle/scripts/docker/Dockerfile.cpu
11473
115-
You can stop and delete the container as following:
74+
As a release engineer, you might want to build Docker images for a certain version and publish them to dockerhub.com. You can do this by switching to the right Git tag, or create a new tag, before running `docker build`. For example, the following commands build Docker images for v0.9.0:
11675

117-
.. code-block:: bash
76+
.. code-block:: bash
11877
119-
# stop
120-
docker stop paddle_ssh_machine
121-
# delete
122-
docker rm paddle_ssh_machine
78+
cd ~/Paddle
79+
git checkout tags/v0.9.0
80+
./paddle/scripts/docker/generates.sh # Use m4 to generate Dockerfiles for each variant.
81+
docker build -t paddle:cpu-v0.9.0 -f ./paddle/scripts/docker/Dockerfile.cpu

paddle/scripts/docker/Dockerfile.cpu

Lines changed: 0 additions & 12 deletions
This file was deleted.

paddle/scripts/docker/Dockerfile.cpu-demo

Lines changed: 0 additions & 12 deletions
This file was deleted.

paddle/scripts/docker/Dockerfile.cpu-devel

Lines changed: 0 additions & 12 deletions
This file was deleted.

paddle/scripts/docker/Dockerfile.cpu-noavx

Lines changed: 0 additions & 12 deletions
This file was deleted.

paddle/scripts/docker/Dockerfile.cpu-noavx-demo

Lines changed: 0 additions & 12 deletions
This file was deleted.

paddle/scripts/docker/Dockerfile.cpu-noavx-devel

Lines changed: 0 additions & 12 deletions
This file was deleted.

paddle/scripts/docker/Dockerfile.gpu

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)