Skip to content

Commit a1bf4c2

Browse files
committed
Update code and small fix.
2 parents 5e7e90c + 21053c1 commit a1bf4c2

File tree

90 files changed

+2602
-811
lines changed

Some content is hidden

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

90 files changed

+2602
-811
lines changed

.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ AllowAllParametersOfDeclarationOnNextLine: true
2525
BinPackParameters: false
2626
BinPackArguments: false
2727
...
28-

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ before_install:
4242
script:
4343
- |
4444
timeout 2580 paddle/scripts/travis/${JOB}.sh # 43min timeout
45-
RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true; else false; fi;
45+
RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true ;else exit 1; fi;
4646
- |
4747
if [[ "$JOB" != "build_doc" ]]; then exit 0; fi;
4848
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then exit 0; fi;

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ include(external/any) # download libn::any
133133
include(external/eigen) # download eigen3
134134
include(external/pybind11) # download pybind11
135135
include(external/nccl)
136+
include(external/cares)
137+
include(external/grpc)
136138

137139
include(cudnn) # set cudnn libraries, must before configure
138140
include(configure) # add paddle env configuration

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RUN apt-get update && \
2929
automake locales clang-format swig doxygen cmake \
3030
liblapack-dev liblapacke-dev libboost-dev \
3131
clang-3.8 llvm-3.8 libclang-3.8-dev \
32-
net-tools && \
32+
net-tools libtool && \
3333
apt-get clean -y
3434

3535
# Install Go and glide

cmake/external/cares.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
IF(MOBILE_INFERENCE)
17+
return()
18+
ENDIF()
19+
20+
include (ExternalProject)
21+
22+
# NOTE: c-ares is needed when linking with grpc.
23+
24+
SET(CARES_SOURCES_DIR ${THIRD_PARTY_PATH}/cares)
25+
SET(CARES_INSTALL_DIR ${THIRD_PARTY_PATH}/install/cares)
26+
SET(CARES_INCLUDE_DIR "${CARES_INSTALL_DIR}/include/" CACHE PATH "cares include directory." FORCE)
27+
28+
ExternalProject_Add(
29+
extern_cares
30+
GIT_REPOSITORY "https://github.com/c-ares/c-ares.git"
31+
GIT_TAG "cares-1_13_0"
32+
PREFIX ${CARES_SOURCES_DIR}
33+
UPDATE_COMMAND ""
34+
CONFIGURE_COMMAND ./buildconf && ./configure --disable-shared --prefix=${CARES_INSTALL_DIR}
35+
BUILD_IN_SOURCE 1
36+
BUILD_COMMAND make
37+
INSTALL_COMMAND make install
38+
)
39+
40+
ADD_LIBRARY(cares STATIC IMPORTED GLOBAL)
41+
SET_PROPERTY(TARGET cares PROPERTY IMPORTED_LOCATION
42+
"${CARES_INSTALL_DIR}/lib/libcares.a")
43+
44+
include_directories(${CARES_INCLUDE_DIR})
45+
ADD_DEPENDENCIES(cares extern_cares)

cmake/external/grpc.cmake

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
IF(MOBILE_INFERENCE)
17+
return()
18+
ENDIF()
19+
20+
include (ExternalProject)
21+
22+
SET(GRPC_SOURCES_DIR ${THIRD_PARTY_PATH}/grpc)
23+
SET(GRPC_INSTALL_DIR ${THIRD_PARTY_PATH}/install/grpc)
24+
SET(GRPC_INCLUDE_DIR "${GRPC_INSTALL_DIR}/include/" CACHE PATH "grpc include directory." FORCE)
25+
SET(GRPC_CPP_PLUGIN "${GRPC_INSTALL_DIR}/bin/grpc_cpp_plugin" CACHE FILEPATH "GRPC_CPP_PLUGIN" FORCE)
26+
IF(APPLE)
27+
SET(BUILD_CMD make -n | sed "s/-Werror//g" | sh)
28+
ELSE()
29+
SET(BUILD_CMD make)
30+
ENDIF()
31+
32+
ExternalProject_Add(
33+
extern_grpc
34+
DEPENDS protobuf zlib
35+
GIT_REPOSITORY "https://github.com/grpc/grpc.git"
36+
GIT_TAG "v1.7.x"
37+
PREFIX ${GRPC_SOURCES_DIR}
38+
UPDATE_COMMAND ""
39+
CONFIGURE_COMMAND ""
40+
BUILD_IN_SOURCE 1
41+
# NOTE(yuyang18):
42+
# Disable -Werror, otherwise the compile will fail in MacOS.
43+
# It seems that we cannot configure that by make command.
44+
# Just dry run make command and remove `-Werror`, then use a shell to run make commands
45+
BUILD_COMMAND ${BUILD_CMD}
46+
INSTALL_COMMAND make prefix=${GRPC_INSTALL_DIR} install
47+
)
48+
49+
# FIXME(typhoonzero): hack to get static lib path, try a better way like merge them.
50+
ADD_LIBRARY(grpc++_unsecure STATIC IMPORTED GLOBAL)
51+
SET_PROPERTY(TARGET grpc++_unsecure PROPERTY IMPORTED_LOCATION
52+
"${GRPC_INSTALL_DIR}/lib/libgrpc++_unsecure.a")
53+
54+
ADD_LIBRARY(grpc++ STATIC IMPORTED GLOBAL)
55+
SET_PROPERTY(TARGET grpc++ PROPERTY IMPORTED_LOCATION
56+
"${GRPC_INSTALL_DIR}/lib/libgrpc++.a")
57+
ADD_LIBRARY(gpr STATIC IMPORTED GLOBAL)
58+
SET_PROPERTY(TARGET gpr PROPERTY IMPORTED_LOCATION
59+
"${GRPC_INSTALL_DIR}/lib/libgpr.a")
60+
61+
ADD_LIBRARY(grpc_unsecure STATIC IMPORTED GLOBAL)
62+
SET_PROPERTY(TARGET grpc_unsecure PROPERTY IMPORTED_LOCATION
63+
"${GRPC_INSTALL_DIR}/lib/libgrpc_unsecure.a")
64+
65+
include_directories(${GRPC_INCLUDE_DIR})
66+
ADD_DEPENDENCIES(grpc++_unsecure extern_grpc)

cmake/external/protobuf.cmake

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@
1515
INCLUDE(ExternalProject)
1616
# Always invoke `FIND_PACKAGE(Protobuf)` for importing function protobuf_generate_cpp
1717
FIND_PACKAGE(Protobuf QUIET)
18-
SET(PROTOBUF_FOUND "OFF")
18+
macro(UNSET_VAR VAR_NAME)
19+
UNSET(${VAR_NAME} CACHE)
20+
UNSET(${VAR_NAME})
21+
endmacro()
22+
UNSET_VAR(PROTOBUF_INCLUDE_DIR)
23+
UNSET_VAR(PROTOBUF_FOUND)
24+
UNSET_VAR(PROTOBUF_PROTOC_EXECUTABLE)
25+
UNSET_VAR(PROTOBUF_PROTOC_LIBRARY)
26+
UNSET_VAR(PROTOBUF_LITE_LIBRARY)
27+
UNSET_VAR(PROTOBUF_LIBRARY)
28+
UNSET_VAR(PROTOBUF_INCLUDE_DIR)
29+
UNSET_VAR(Protobuf_PROTOC_EXECUTABLE)
1930

2031
if(NOT COMMAND protobuf_generate_python) # before cmake 3.4, protobuf_genrerate_python is not defined.
2132
function(protobuf_generate_python SRCS)
@@ -110,7 +121,6 @@ macro(PROMPT_PROTOBUF_LIB)
110121
# FIND_Protobuf.cmake uses `Protobuf_PROTOC_EXECUTABLE`.
111122
# make `protobuf_generate_cpp` happy.
112123
SET(Protobuf_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
113-
114124
FOREACH(dep ${protobuf_DEPS})
115125
ADD_DEPENDENCIES(protobuf ${dep})
116126
ADD_DEPENDENCIES(protobuf_lite ${dep})
@@ -128,11 +138,11 @@ endmacro()
128138

129139
set(PROTOBUF_ROOT "" CACHE PATH "Folder contains protobuf")
130140
if (NOT "${PROTOBUF_ROOT}" STREQUAL "")
131-
find_path(PROTOBUF_INCLUDE_DIR google/protobuf/message.h PATHS ${PROTOBUF_ROOT}/include)
132-
find_library(PROTOBUF_LIBRARY protobuf PATHS ${PROTOBUF_ROOT}/lib)
133-
find_library(PROTOBUF_LITE_LIBRARY protobuf-lite PATHS ${PROTOBUF_ROOT}/lib)
134-
find_library(PROTOBUF_PROTOC_LIBRARY protoc PATHS ${PROTOBUF_ROOT}/lib)
135-
find_program(PROTOBUF_PROTOC_EXECUTABLE protoc PATHS ${PROTOBUF_ROOT}/bin)
141+
find_path(PROTOBUF_INCLUDE_DIR google/protobuf/message.h PATHS ${PROTOBUF_ROOT}/include NO_DEFAULT_PATH)
142+
find_library(PROTOBUF_LIBRARY protobuf PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
143+
find_library(PROTOBUF_LITE_LIBRARY protobuf-lite PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
144+
find_library(PROTOBUF_PROTOC_LIBRARY protoc PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
145+
find_program(PROTOBUF_PROTOC_EXECUTABLE protoc PATHS ${PROTOBUF_ROOT}/bin NO_DEFAULT_PATH)
136146
if (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOBUF_LITE_LIBRARY AND PROTOBUF_PROTOC_LIBRARY AND PROTOBUF_PROTOC_EXECUTABLE)
137147
message(STATUS "Using custom protobuf library in ${PROTOBUF_ROOT}.")
138148
SET_PROTOBUF_VERSION()

cmake/external/zlib.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ ExternalProject_Add(
5050
)
5151

5252
LIST(APPEND external_project_dependencies zlib)
53+
ADD_LIBRARY(zlib_target STATIC IMPORTED GLOBAL)
54+
SET_PROPERTY(TARGET zlib_target PROPERTY IMPORTED_LOCATION ${ZLIB_LIBRARIES})
5355

5456
IF(WITH_C_API)
5557
INSTALL(DIRECTORY ${ZLIB_INCLUDE_DIR} DESTINATION third_party/zlib)

cmake/generic.cmake

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,58 @@ function(py_test TARGET_NAME)
459459
if(WITH_TESTING)
460460
set(options STATIC static SHARED shared)
461461
set(oneValueArgs "")
462-
set(multiValueArgs SRCS DEPS)
463-
cmake_parse_arguments(py_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
462+
set(multiValueArgs SRCS DEPS ARGS)
463+
cmake_parse_arguments(py_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
464464
add_test(NAME ${TARGET_NAME}
465465
COMMAND env PYTHONPATH=${PADDLE_PYTHON_BUILD_DIR}/lib-python
466-
${PYTHON_EXECUTABLE} ${py_test_SRCS}
466+
${PYTHON_EXECUTABLE} -u ${py_test_SRCS} ${py_test_ARGS}
467467
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
468468
endif()
469469
endfunction()
470+
471+
# grpc_library generate grpc code using grpc_cpp_plugin and protoc
472+
# then build the generated protobuf code and grpc code with your
473+
# implementation source codes together. Use SRCS argument for your
474+
# implementation source files and PROTO argument for your .proto
475+
# files.
476+
#
477+
# Usage: grpc_library(my_target SRCS my_client.cc PROTO my_target.proto DEPS my_dep)
478+
479+
function(grpc_library TARGET_NAME)
480+
set(oneValueArgs PROTO)
481+
set(multiValueArgs SRCS DEPS)
482+
set(options "")
483+
cmake_parse_arguments(grpc_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
484+
485+
message(STATUS "generating grpc ${grpc_library_PROTO}")
486+
487+
get_filename_component(ABS_PROTO ${grpc_library_PROTO} ABSOLUTE)
488+
get_filename_component(PROTO_WE ${grpc_library_PROTO} NAME_WE)
489+
get_filename_component(PROTO_PATH ${ABS_PROTO} PATH)
490+
491+
protobuf_generate_cpp(grpc_proto_srcs grpc_proto_hdrs "${ABS_PROTO}")
492+
set(grpc_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/${PROTO_WE}.grpc.pb.cc")
493+
set(grpc_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${PROTO_WE}.grpc.pb.h")
494+
cc_library("${TARGET_NAME}_proto" SRCS "${grpc_proto_srcs}")
495+
496+
add_custom_command(
497+
OUTPUT "${grpc_grpc_srcs}" "${grpc_grpc_hdrs}"
498+
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
499+
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" -I "${PROTO_PATH}"
500+
--plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}" "${ABS_PROTO}"
501+
DEPENDS "${ABS_PROTO}" ${PROTOBUF_PROTOC_EXECUTABLE} extern_grpc)
502+
503+
# FIXME(typhoonzero): grpc generated code do not generate virtual-dtor, mark it
504+
# as compiler warnings instead of error. Should try remove the warnings also.
505+
set_source_files_properties(
506+
${grpc_grpc_srcs}
507+
PROPERTIES
508+
COMPILE_FLAGS "-Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor")
509+
cc_library("${TARGET_NAME}_grpc" SRCS "${grpc_grpc_srcs}")
510+
511+
set_source_files_properties(
512+
${grpc_library_SRCS}
513+
PROPERTIES
514+
COMPILE_FLAGS "-Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor")
515+
cc_library("${TARGET_NAME}" SRCS "${grpc_library_SRCS}" DEPS "${TARGET_NAME}_grpc" "${TARGET_NAME}_proto" "${grpc_library_DEPS}")
516+
endfunction()

doc/api/v2/config/layer.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ img_conv
5454

5555
.. _api_v2.layer_context_projection:
5656

57-
context_projection
57+
context_projection
5858
------------------
5959
.. autoclass:: paddle.v2.layer.context_projection
6060
:noindex:
@@ -70,7 +70,7 @@ Image Pooling Layer
7070
img_pool
7171
--------
7272
.. autoclass:: paddle.v2.layer.img_pool
73-
:noindex:
73+
:noindex:
7474

7575
spp
7676
---
@@ -104,7 +104,7 @@ sum_to_one_norm
104104
---------------
105105
.. autoclass:: paddle.v2.layer.sum_to_one_norm
106106
:noindex:
107-
107+
108108
cross_channel_norm
109109
------------------
110110
.. autoclass:: paddle.v2.layer.cross_channel_norm
@@ -114,7 +114,7 @@ row_l2_norm
114114
-----------
115115
.. autoclass:: paddle.v2.layer.row_l2_norm
116116
:noindex:
117-
117+
118118
Recurrent Layers
119119
================
120120

@@ -415,6 +415,13 @@ multiplex
415415
.. autoclass:: paddle.v2.layer.multiplex
416416
:noindex:
417417

418+
Factorization Machine Layer
419+
============================
420+
421+
factorization_machine
422+
---------------------
423+
.. autoclass:: paddle.v2.layer.factorization_machine
424+
:noindex:
418425

419426
Slicing and Joining Layers
420427
==========================

0 commit comments

Comments
 (0)