Skip to content

Commit fc2e6f1

Browse files
committed
Merge branch 'develop' into print_attention_weight
2 parents 4c134c7 + 5810d63 commit fc2e6f1

File tree

483 files changed

+26569
-7233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

483 files changed

+26569
-7233
lines changed

.clang_format.hook

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
readonly VERSION="3.8"
5+
6+
version=$(clang-format -version)
7+
8+
if ! [[ $version == *"$VERSION"* ]]; then
9+
echo "clang-format version check failed."
10+
echo "a version contains '$VERSION' is needed, but get '$version'"
11+
echo "you can install the right version, and make an soft-link to '\$PATH' env"
12+
exit -1
13+
fi
14+
15+
clang-format $@

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ cmake-build-*
2424
python/paddle/v2/framework/core.so
2525
CMakeFiles
2626
cmake_install.cmake
27-
27+
paddle/.timestamp
28+
python/paddlepaddle.egg-info/

.pre-commit-config.yaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717
- id: detect-private-key
1818
files: (?!.*third_party)^.*$ | (?!.*book)^.*$
1919
- id: end-of-file-fixer
20-
- repo: https://github.com/PaddlePaddle/clang-format-pre-commit-hook.git
21-
sha: 28c0ea8a67a3e2dbbf4822ef44e85b63a0080a29
20+
- repo: local
2221
hooks:
23-
- id: clang-formater
24-
- repo: https://github.com/dnephin/pre-commit-golang
25-
sha: e4693a4c282b4fc878eda172a929f7a6508e7d16
22+
- id: clang-format-with-version-check
23+
name: clang-format
24+
description: Format files with ClangFormat.
25+
entry: ./.clang_format.hook -i
26+
language: system
27+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$
28+
- repo: https://github.com/PaddlePaddle/pre-commit-golang
29+
sha: 8337620115c25ff8333f1b1a493bd031049bd7c0
2630
hooks:
27-
- id: go-fmt
28-
files: (.*\.go)
29-
- id: go-lint
30-
files: (.*\.go)
31+
- id: go-fmt
32+
types:
33+
- go
34+
- id: gometalinter
35+
types:
36+
- go

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ cache:
44
- $HOME/.ccache
55
- $HOME/.cache/pip
66
- $TRAVIS_BUILD_DIR/build/third_party
7+
- $TRAVIS_BUILD_DIR/build_android/third_party
78
sudo: required
89
dist: trusty
910
os:
1011
- linux
1112
env:
1213
- JOB=build_doc
1314
- JOB=check_style
15+
- JOB=build_android
1416
addons:
1517
apt:
1618
packages:
@@ -35,10 +37,12 @@ before_install:
3537
- if [[ "$JOB" == "check_style" ]]; then sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format; fi
3638
# Paddle is using protobuf 3.1 currently. Protobuf 3.2 breaks the compatibility. So we specify the python
3739
# protobuf version.
38-
- pip install numpy wheel 'protobuf==3.1' sphinx==1.5.6 recommonmark sphinx-rtd-theme==0.1.9 virtualenv pre-commit requests==2.9.2 LinkChecker
39-
- pip install rarfile
40+
- pip install -r $TRAVIS_BUILD_DIR/python/requirements.txt
41+
- pip install wheel sphinx==1.5.6 recommonmark sphinx-rtd-theme==0.1.9 virtualenv pre-commit LinkChecker
4042
- curl https://glide.sh/get | bash
4143
- eval "$(GIMME_GO_VERSION=1.8.3 gimme)"
44+
- go get -u github.com/alecthomas/gometalinter
45+
- gometalinter --install
4246
- |
4347
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
4448
script:

CMakeLists.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
# limitations under the License
1414

1515
cmake_minimum_required(VERSION 3.0)
16-
1716
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
18-
set(PROJ_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
19-
set(PROJ_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR})
17+
set(PADDLE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
18+
set(PADDLE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
2019

2120
include(system)
2221

@@ -37,6 +36,8 @@ include(simd)
3736
################################ Configurations #######################################
3837
option(WITH_GPU "Compile PaddlePaddle with NVIDIA GPU" ${CUDA_FOUND})
3938
option(WITH_AVX "Compile PaddlePaddle with AVX intrinsics" ${AVX_FOUND})
39+
option(WITH_MKLDNN "Compile PaddlePaddle with mkl-dnn support." ${AVX_FOUND})
40+
option(WITH_MKLML "Compile PaddlePaddle with mklml package." ${AVX_FOUND})
4041
option(WITH_DSO "Compile PaddlePaddle with dynamic linked CUDA" ON)
4142
option(WITH_TESTING "Compile PaddlePaddle with unit testing" ON)
4243
option(WITH_SWIG_PY "Compile PaddlePaddle with inference api" ON)
@@ -54,6 +55,7 @@ option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF)
5455
option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF)
5556
option(GLIDE_INSTALL "Download and install go dependencies " ON)
5657
option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF)
58+
option(USE_EIGEN_FOR_BLAS "Use matrix multiplication in Eigen" OFF)
5759

5860
# CMAKE_BUILD_TYPE
5961
if(NOT CMAKE_BUILD_TYPE)
@@ -75,6 +77,10 @@ if(ANDROID)
7577
"Disable PYTHON when cross-compiling for Android" FORCE)
7678
set(WITH_RDMA OFF CACHE STRING
7779
"Disable RDMA when cross-compiling for Android" FORCE)
80+
set(WITH_MKLDNN OFF CACHE STRING
81+
"Disable MKLDNN when cross-compiling for Android" FORCE)
82+
set(WITH_MKLML OFF CACHE STRING
83+
"Disable MKLML package when cross-compiling for Android" FORCE)
7884
endif(ANDROID)
7985

8086
set(THIRD_PARTY_PATH "${CMAKE_BINARY_DIR}/third_party" CACHE STRING
@@ -88,13 +94,15 @@ endif()
8894

8995
########################################################################################
9096

97+
include(external/mklml) # download mklml package
9198
include(external/zlib) # download, build, install zlib
9299
include(external/gflags) # download, build, install gflags
93100
include(external/glog) # download, build, install glog
94101
include(external/gtest) # download, build, install gtest
95102
include(external/protobuf) # download, build, install protobuf
96103
include(external/python) # download, build, install python
97104
include(external/openblas) # download, build, install openblas
105+
include(external/mkldnn) # download, build, install mkldnn
98106
include(external/swig) # download, build, install swig
99107
include(external/warpctc) # download, build, install warpctc
100108
include(external/any) # download libn::any
@@ -114,8 +122,8 @@ include(version) # set PADDLE_VERSION
114122
include(coveralls) # set code coverage
115123

116124

117-
include_directories("${PROJ_ROOT}")
118-
include_directories("${PROJ_ROOT}/paddle/cuda/include")
125+
include_directories("${PADDLE_SOURCE_DIR}")
126+
include_directories("${PADDLE_SOURCE_DIR}/paddle/cuda/include")
119127
include_directories("${CMAKE_CURRENT_BINARY_DIR}/proto")
120128
include_directories("${CMAKE_CURRENT_BINARY_DIR}/go/pserver/client/c")
121129
include_directories(${Boost_INCLUDE_DIRS})
@@ -130,14 +138,19 @@ set(EXTERNAL_LIBS
130138
)
131139

132140
if(WITH_GPU)
133-
list(APPEND EXTERNAL_LIB ${CUDA_LIBRARIES} ${CUDA_rt_LIBRARY})
141+
list(APPEND EXTERNAL_LIBS ${CUDA_LIBRARIES} ${CUDA_rt_LIBRARY})
134142
if(NOT WITH_DSO)
135-
list(APPEND EXTERNAL_LIB ${CUDNN_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY})
143+
list(APPEND EXTERNAL_LIBS ${CUDNN_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY})
136144
endif(NOT WITH_DSO)
137145
endif(WITH_GPU)
138146

147+
if(WITH_MKLDNN)
148+
list(APPEND EXTERNAL_LIBS ${MKLDNN_LIB} ${MKLDNN_IOMP_LIB})
149+
endif()
150+
139151
if(USE_NNPACK)
140-
list(APPEND EXTERNAL_LIBS ${NNPACK_LIB} ${PTHREADPOOL_LIB} "rt")
152+
include(external/nnpack)
153+
list(APPEND EXTERNAL_LIBS ${NNPACK_LIBS})
141154
endif(USE_NNPACK)
142155

143156
add_subdirectory(proto)
@@ -152,10 +165,12 @@ if(WITH_GOLANG)
152165
add_subdirectory(go)
153166
endif(WITH_GOLANG)
154167

168+
set(PADDLE_PYTHON_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/python/build")
155169
add_subdirectory(paddle)
156170
if(WITH_PYTHON)
157171
add_subdirectory(python)
158172
endif()
173+
159174
if(WITH_DOC)
160175
add_subdirectory(doc)
161176
endif()

Dockerfile

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,26 @@ COPY ./paddle/scripts/docker/root/ /root/
2525
RUN apt-get update && \
2626
apt-get install -y \
2727
git python-pip python-dev openssh-server bison \
28-
wget unzip tar xz-utils bzip2 gzip coreutils ntp \
28+
wget unzip unrar tar xz-utils bzip2 gzip coreutils ntp \
2929
curl sed grep graphviz libjpeg-dev zlib1g-dev \
30-
python-numpy python-matplotlib gcc g++ \
31-
automake locales clang-format-3.8 swig doxygen cmake \
30+
python-matplotlib gcc-4.8 g++-4.8 \
31+
automake locales clang-format swig doxygen cmake \
3232
liblapack-dev liblapacke-dev libboost-dev \
3333
clang-3.8 llvm-3.8 libclang-3.8-dev \
3434
net-tools && \
3535
apt-get clean -y
3636

3737
# Install Go and glide
38-
RUN wget -O go.tgz https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz && \
39-
tar -C /usr/local -xzf go.tgz && \
38+
RUN wget -qO- https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz | \
39+
tar -xz -C /usr/local && \
4040
mkdir /root/gopath && \
4141
mkdir /root/gopath/bin && \
42-
mkdir /root/gopath/src && \
43-
rm go.tgz
42+
mkdir /root/gopath/src
4443
ENV GOROOT=/usr/local/go GOPATH=/root/gopath
4544
# should not be in the same line with GOROOT definition, otherwise docker build could not find GOROOT.
4645
ENV PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
4746
# install glide
48-
RUN curl -q https://glide.sh/get | sh
47+
RUN curl -s -q https://glide.sh/get | sh
4948

5049
# git credential to skip password typing
5150
RUN git config --global credential.helper store
@@ -56,19 +55,23 @@ RUN localedef -i en_US -f UTF-8 en_US.UTF-8
5655
# FIXME: due to temporary ipykernel dependency issue, specify ipykernel jupyter
5756
# version util jupyter fixes this issue.
5857
RUN pip install --upgrade pip && \
59-
pip install -U 'protobuf==3.1.0' && \
60-
pip install -U wheel pillow BeautifulSoup && \
58+
pip install -U wheel && \
6159
pip install -U docopt PyYAML sphinx && \
62-
pip install -U sphinx-rtd-theme==0.1.9 recommonmark && \
63-
pip install pre-commit 'requests==2.9.2' 'ipython==5.3.0' && \
60+
pip install -U sphinx-rtd-theme==0.1.9 recommonmark
61+
62+
RUN pip install pre-commit 'ipython==5.3.0' && \
6463
pip install 'ipykernel==4.6.0' 'jupyter==1.0.0' && \
65-
pip install rarfile
64+
pip install opencv-python
65+
66+
COPY ./python/requirements.txt /root/
67+
RUN pip install -r /root/requirements.txt
6668

6769
# To fix https://github.com/PaddlePaddle/Paddle/issues/1954, we use
6870
# the solution in https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl-py2
6971
RUN apt-get install -y libssl-dev libffi-dev
7072
RUN pip install certifi urllib3[secure]
7173

74+
7275
# Install woboq_codebrowser to /woboq
7376
RUN git clone https://github.com/woboq/woboq_codebrowser /woboq && \
7477
(cd /woboq \

Dockerfile.android

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ RUN apt-get update && \
1414
wget curl tar unzip gcc g++ locales clang-format-3.8 swig cmake && \
1515
apt-get clean -y
1616

17+
# Install Go and glide
18+
RUN wget -O go.tgz https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz && \
19+
tar -C /usr/local -xzf go.tgz && \
20+
mkdir /root/gopath && \
21+
mkdir /root/gopath/bin && \
22+
mkdir /root/gopath/src && \
23+
rm go.tgz
24+
ENV GOROOT=/usr/local/go GOPATH=/root/gopath
25+
# should not be in the same line with GOROOT definition, otherwise docker build could not find GOROOT.
26+
ENV PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
27+
1728
# git credential to skip password typing
1829
RUN git config --global credential.helper store
1930

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ We provide [English](http://doc.paddlepaddle.org/develop/doc/) and
7272

7373
- [Deep Learning 101](http://book.paddlepaddle.org/index.html)
7474

75-
You might want to start from the this online interactive book that can run in Jupyter Notebook.
75+
You might want to start from this online interactive book that can run in Jupyter Notebook.
7676

7777
- [Distributed Training](http://doc.paddlepaddle.org/develop/doc/howto/usage/cluster/cluster_train_en.html)
7878

cmake/cblas.cmake

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,44 @@
1515

1616
set(CBLAS_FOUND OFF)
1717

18-
## Find MKL First.
19-
set(INTEL_ROOT "/opt/intel" CACHE PATH "Folder contains intel libs")
20-
set(MKL_ROOT ${INTEL_ROOT}/mkl CACHE PATH "Folder contains MKL")
18+
## Find MKLML First.
19+
if(WITH_MKLML AND MKLML_INC_DIR AND MKLML_LIB)
20+
set(CBLAS_FOUND ON)
21+
set(CBLAS_PROVIDER MKLML)
22+
set(CBLAS_INC_DIR ${MKLML_INC_DIR})
23+
set(CBLAS_LIBRARIES ${MKLML_LIB})
24+
25+
add_definitions(-DPADDLE_USE_MKLML)
26+
add_definitions(-DLAPACK_FOUND)
27+
28+
message(STATUS "Found cblas and lapack in MKLML "
29+
"(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
30+
return()
31+
endif()
32+
33+
## Then find MKL.
34+
set(INTEL_MKL_ROOT "/opt/intel/mkl" CACHE PATH "Folder contains intel mkl libs")
35+
set(MKL_ROOT $ENV{MKL_ROOT} CACHE PATH "Folder contains env MKL")
36+
37+
set(MKL_INCLUDE_SEARCH_PATHS
38+
${MKL_ROOT}/include
39+
${INTEL_MKL_ROOT}/include)
40+
set(MKL_LIB_SEARCH_PATHS
41+
${MKL_ROOT}/lib
42+
${MKL_ROOT}/lib/intel64
43+
${INTEL_MKL_ROOT}/lib
44+
${INTEL_MKL_ROOT}/lib/intel64)
2145

2246
find_path(MKL_INC_DIR mkl.h PATHS
23-
${MKL_ROOT}/include)
47+
${MKL_INCLUDE_SEARCH_PATHS})
2448
find_path(MKL_LAPACK_INC_DIR mkl_lapacke.h PATHS
25-
${MKL_ROOT}/include)
49+
${MKL_INCLUDE_SEARCH_PATHS})
2650
find_library(MKL_CORE_LIB NAMES mkl_core PATHS
27-
${MKL_ROOT}/lib
28-
${MKL_ROOT}/lib/intel64)
51+
${MKL_LIB_SEARCH_PATHS})
2952
find_library(MKL_SEQUENTIAL_LIB NAMES mkl_sequential PATHS
30-
${MKL_ROOT}/lib
31-
${MKL_ROOT}/lib/intel64)
53+
${MKL_LIB_SEARCH_PATHS})
3254
find_library(MKL_INTEL_LP64 NAMES mkl_intel_lp64 PATHS
33-
${MKL_ROOT}/lib
34-
${MKL_ROOT}/lib/intel64)
55+
${MKL_LIB_SEARCH_PATHS})
3556

3657
if(MKL_LAPACK_INC_DIR AND MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64)
3758
set(CBLAS_FOUND ON)

cmake/configure.cmake

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if(NOT WITH_TIMER)
2828
add_definitions(-DPADDLE_DISABLE_TIMER)
2929
endif(NOT WITH_TIMER)
3030

31+
if(USE_EIGEN_FOR_BLAS)
32+
add_definitions(-DPADDLE_USE_EIGEN_FOR_BLAS)
33+
endif(USE_EIGEN_FOR_BLAS)
34+
3135
if(NOT WITH_PROFILER)
3236
add_definitions(-DPADDLE_DISABLE_PROFILER)
3337
endif(NOT WITH_PROFILER)
@@ -67,6 +71,28 @@ else()
6771
include_directories(${CUDA_TOOLKIT_INCLUDE})
6872
endif(NOT WITH_GPU)
6973

74+
if(WITH_MKLDNN)
75+
add_definitions(-DPADDLE_USE_MKLDNN)
76+
if (WITH_MKLML AND MKLDNN_IOMP_DIR)
77+
message(STATUS "Enable Intel OpenMP at ${MKLDNN_IOMP_DIR}")
78+
set(OPENMP_FLAGS "-fopenmp")
79+
set(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
80+
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
81+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENMP_FLAGS}")
82+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMP_FLAGS}")
83+
else()
84+
find_package(OpenMP)
85+
if(OPENMP_FOUND)
86+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
87+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
88+
else()
89+
message(WARNING "Can not find OpenMP."
90+
"Some performance features in MKLDNN may not be available")
91+
endif()
92+
endif()
93+
94+
endif(WITH_MKLDNN)
95+
7096
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SIMD_FLAG}")
7197
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAG}")
7298

@@ -102,12 +128,19 @@ if(WITH_GOLANG)
102128
message(FATAL_ERROR "no glide executeble found: $ENV{GOPATH}/bin/glide")
103129
endif()
104130

105-
add_custom_target(go_vendor)
106-
add_custom_command(TARGET go_vendor
131+
# this command will only run when the file it depends is missing
132+
# or has changed, or the output is missing.
133+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/glide
107134
COMMAND env GOPATH=${GOPATH} ${GLIDE} install
135+
COMMAND touch ${CMAKE_BINARY_DIR}/glide
136+
DEPENDS ${PADDLE_SOURCE_DIR}/go/glide.lock
108137
WORKING_DIRECTORY "${PADDLE_IN_GOPATH}/go"
109-
)
110-
add_dependencies(go_vendor go_path)
138+
)
139+
140+
# depends on the custom command which outputs
141+
# ${CMAKE_BINARY_DIR}/glide, the custom command does not need to
142+
# run every time this target is built.
143+
add_custom_target(go_vendor DEPENDS ${CMAKE_BINARY_DIR}/glide go_path)
111144
endif()
112145

113146
endif(WITH_GOLANG)

0 commit comments

Comments
 (0)