Skip to content

Commit 1ef97fa

Browse files
committed
Merge branch 'develop' into math_function
2 parents f67275a + 84aea8a commit 1ef97fa

File tree

301 files changed

+4879
-2701
lines changed

Some content is hidden

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

301 files changed

+4879
-2701
lines changed

.travis.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ 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
10+
services:
11+
- docker
912
os:
1013
- linux
1114
env:
1215
- JOB=build_doc
1316
- JOB=check_style
17+
- JOB=build_android
1418
addons:
1519
apt:
1620
packages:
@@ -41,16 +45,18 @@ before_install:
4145
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
4246
script:
4347
- |
44-
timeout 2580 paddle/scripts/travis/${JOB}.sh # 43min timeout
45-
RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true ;else exit 1; fi;
48+
# 43min timeout
49+
if [[ "$JOB" == "build_android" ]]; then timeout 2580 docker run -it --rm -v "$TRAVIS_BUILD_DIR:/paddle" paddlepaddle/paddle:latest-dev-android;
50+
else timeout 2580 paddle/scripts/travis/${JOB}.sh; fi;
51+
RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true; else exit 1; fi;
4652
- |
4753
if [[ "$JOB" != "build_doc" ]]; then exit 0; fi;
4854
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then exit 0; fi;
4955
if [[ "$TRAVIS_BRANCH" != "develop" && ! "$TRAVIS_BRANCH" =~ ^v[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?(-\S*)?$ ]]; then exit 0; fi;
5056
export DEPLOY_DOCS_SH=https://raw.githubusercontent.com/PaddlePaddle/PaddlePaddle.org/master/scripts/deploy/deploy_docs.sh
5157
export DOCS_DIR=`pwd`
5258
cd ..
53-
curl $DEPLOY_DOCS_SH | bash -s $CONTENT_DEC_PASSWD $TRAVIS_BRANCH $DOCS_DIR $DOCS_DIR/build/doc
59+
curl $DEPLOY_DOCS_SH | bash -s $CONTENT_DEC_PASSWD $TRAVIS_BRANCH $DOCS_DIR $DOCS_DIR/build/doc/v2
5460
notifications:
5561
email:
5662
on_success: change

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| Github account | name |
22
|---|---|
3+
| abhinavarora | Abhinav Arora |
34
| backyes | Yan-Fei Wang |
45
| beckett1124 | Bin Qi |
56
| JiayiFeng | Jia-Yi Feng |

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ include(external/eigen) # download eigen3
144144
include(external/pybind11) # download pybind11
145145
include(external/cares)
146146
include(external/grpc)
147+
include(external/snappy) # download snappy
148+
include(external/snappystream)
147149

148150
include(cudnn) # set cudnn libraries, must before configure
149151
include(cupti)
@@ -166,11 +168,11 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}/proto")
166168
include_directories("${CMAKE_CURRENT_BINARY_DIR}/go/pserver/client/c")
167169

168170
set(EXTERNAL_LIBS
169-
${GFLAGS_LIBRARIES}
170-
${GLOG_LIBRARIES}
171+
gflags
172+
glog
171173
${CBLAS_LIBRARIES}
172-
${PROTOBUF_LIBRARY}
173-
${ZLIB_LIBRARIES}
174+
protobuf
175+
zlib
174176
${PYTHON_LIBRARIES}
175177
)
176178

benchmark/cluster/vgg16/vgg16_fluid.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2-
#
2+
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
6-
#
6+
#
77
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -106,10 +106,10 @@ def conv_block(input, num_filter, groups, dropouts):
106106
conv5 = conv_block(conv4, 512, 3, [0.4, 0.4, 0])
107107

108108
drop = fluid.layers.dropout(x=conv5, dropout_prob=0.5)
109-
fc1 = fluid.layers.fc(input=drop, size=512, act=None)
109+
fc1 = fluid.layers.fc(input=drop, size=4096, act=None)
110110
bn = fluid.layers.batch_norm(input=fc1, act='relu')
111111
drop2 = fluid.layers.dropout(x=bn, dropout_prob=0.5)
112-
fc2 = fluid.layers.fc(input=drop2, size=512, act=None)
112+
fc2 = fluid.layers.fc(input=drop2, size=4096, act=None)
113113
return fc2
114114

115115

@@ -138,13 +138,14 @@ def main():
138138
avg_cost = fluid.layers.mean(x=cost)
139139

140140
# Evaluator
141-
accuracy = fluid.evaluator.Accuracy(input=predict, label=label)
141+
batch_size = fluid.layers.create_tensor(dtype='int64')
142+
batch_acc = fluid.layers.accuracy(
143+
input=predict, label=label, total=batch_size)
142144

143145
# inference program
144146
inference_program = fluid.default_main_program().clone()
145147
with fluid.program_guard(inference_program):
146-
test_target = accuracy.metrics + accuracy.states
147-
inference_program = fluid.io.get_inference_program(test_target)
148+
inference_program = fluid.io.get_inference_program(batch_acc)
148149

149150
# Optimization
150151
optimizer = fluid.optimizer.Adam(learning_rate=args.learning_rate)
@@ -157,27 +158,30 @@ def main():
157158

158159
# test
159160
def test(exe):
160-
accuracy.reset(exe)
161+
test_pass_acc = fluid.average.WeightedAverage()
161162
for batch_id, data in enumerate(test_reader()):
162163
img_data = np.array(map(lambda x: x[0].reshape(data_shape),
163164
data)).astype("float32")
164165
y_data = np.array(map(lambda x: x[1], data)).astype("int64")
165166
y_data = y_data.reshape([-1, 1])
166167

167-
exe.run(inference_program,
168-
feed={"pixel": img_data,
169-
"label": y_data})
168+
outs = exe.run(inference_program,
169+
feed={"pixel": img_data,
170+
"label": y_data},
171+
fetch_list=[batch_acc, batch_size])
172+
test_pass_acc.add(value=np.array(outs[0]), weight=np.array(outs[1]))
170173

171-
return accuracy.eval(exe)
174+
return test_pass_acc.eval()
172175

173176
def train_loop(exe, trainer_prog):
174177
iters = 0
175178
ts = time.time()
179+
train_pass_acc = fluid.average.WeightedAverage()
176180
for pass_id in range(args.num_passes):
177181
# train
178182
start_time = time.time()
179183
num_samples = 0
180-
accuracy.reset(exe)
184+
train_pass_acc.reset()
181185
with profiler.profiler("CPU", 'total') as prof:
182186
for batch_id, data in enumerate(train_reader()):
183187
ts = time.time()
@@ -187,21 +191,22 @@ def train_loop(exe, trainer_prog):
187191
y_data = np.array(map(lambda x: x[1], data)).astype("int64")
188192
y_data = y_data.reshape([-1, 1])
189193

190-
loss, acc = exe.run(
194+
loss, acc, b_size = exe.run(
191195
trainer_prog,
192196
feed={"pixel": img_data,
193197
"label": y_data},
194-
fetch_list=[avg_cost] + accuracy.metrics)
198+
fetch_list=[avg_cost, batch_acc, batch_size])
195199
iters += 1
196200
num_samples += len(data)
201+
train_pass_acc.add(value=acc, weight=b_size)
197202
print(
198203
"Pass = %d, Iters = %d, Loss = %f, Accuracy = %f, Speed = %.2f img/s"
199204
% (pass_id, iters, loss, acc,
200205
len(data) / (time.time() - ts))
201206
) # The accuracy is the accumulation of batches, but not the current batch.
202207

203208
pass_elapsed = time.time() - start_time
204-
pass_train_acc = accuracy.eval(exe)
209+
pass_train_acc = train_pass_acc.eval()
205210
pass_test_acc = test(exe)
206211
print(
207212
"Pass = %d, Training performance = %f imgs/s, Train accuracy = %f, Test accuracy = %f\n"

cmake/external/snappy.cmake

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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: snappy is needed when linking with recordio
23+
24+
SET(SNAPPY_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy)
25+
SET(SNAPPY_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy)
26+
SET(SNAPPY_INCLUDE_DIR "${SNAPPY_INSTALL_DIR}/include/" CACHE PATH "snappy include directory." FORCE)
27+
28+
ExternalProject_Add(
29+
extern_snappy
30+
GIT_REPOSITORY "https://github.com/google/snappy"
31+
GIT_TAG "1.1.7"
32+
PREFIX ${SNAPPY_SOURCES_DIR}
33+
UPDATE_COMMAND ""
34+
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
35+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
36+
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
37+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
38+
-DCMAKE_INSTALL_PREFIX=${SNAPPY_INSTALL_DIR}
39+
-DCMAKE_INSTALL_LIBDIR=${SNAPPY_INSTALL_DIR}/lib
40+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
41+
-DBUILD_TESTING=OFF
42+
-DSNAPPY_BUILD_TESTS:BOOL=OFF
43+
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
44+
${EXTERNAL_OPTIONAL_ARGS}
45+
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SNAPPY_INSTALL_DIR}
46+
-DCMAKE_INSTALL_LIBDIR:PATH=${SNAPPY_INSTALL_DIR}/lib
47+
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
48+
-DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
49+
BUILD_COMMAND make -j8
50+
INSTALL_COMMAND make install
51+
)
52+
53+
add_library(snappy STATIC IMPORTED GLOBAL)
54+
set_property(TARGET snappy PROPERTY IMPORTED_LOCATION
55+
"${SNAPPY_INSTALL_DIR}/lib/libsnappy.a")
56+
57+
include_directories(${SNAPPY_INCLUDE_DIR})
58+
add_dependencies(snappy extern_snappy)

cmake/external/snappystream.cmake

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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: snappy is needed when linking with recordio
23+
24+
SET(SNAPPYSTREAM_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy_stream)
25+
SET(SNAPPYSTREAM_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy_stream)
26+
SET(SNAPPYSTREAM_INCLUDE_DIR "${SNAPPYSTREAM_INSTALL_DIR}/include/" CACHE PATH "snappy stream include directory." FORCE)
27+
28+
ExternalProject_Add(
29+
extern_snappystream
30+
GIT_REPOSITORY "https://github.com/hoxnox/snappystream.git"
31+
GIT_TAG "0.2.8"
32+
PREFIX ${SNAPPYSTREAM_SOURCES_DIR}
33+
UPDATE_COMMAND ""
34+
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
35+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
36+
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
37+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
38+
-DCMAKE_INSTALL_PREFIX=${SNAPPY_INSTALL_DIR}
39+
-DCMAKE_INSTALL_LIBDIR=${SNAPPY_INSTALL_DIR}/lib
40+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
41+
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
42+
-DSNAPPY_ROOT=${SNAPPY_INSTALL_DIR}
43+
${EXTERNAL_OPTIONAL_ARGS}
44+
CMAKE_CACHE_ARGS
45+
-DCMAKE_INSTALL_PREFIX:PATH=${SNAPPYSTREAM_INSTALL_DIR}
46+
-DCMAKE_INSTALL_LIBDIR:PATH=${SNAPPYSTREAM_INSTALL_DIR}/lib
47+
-DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
48+
BUILD_COMMAND make -j8
49+
INSTALL_COMMAND make install
50+
DEPENDS snappy
51+
)
52+
53+
add_library(snappystream STATIC IMPORTED GLOBAL)
54+
set_property(TARGET snappystream PROPERTY IMPORTED_LOCATION
55+
"${SNAPPYSTREAM_INSTALL_DIR}/lib/libsnappystream.a")
56+
57+
include_directories(${SNAPPYSTREAM_INCLUDE_DIR})
58+
add_dependencies(snappystream extern_snappystream)

cmake/external/zlib.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ENDIF(WIN32)
2828
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
2929

3030
ExternalProject_Add(
31-
zlib
31+
extern_zlib
3232
${EXTERNAL_PROJECT_LOG_ARGS}
3333
GIT_REPOSITORY "https://github.com/madler/zlib.git"
3434
GIT_TAG "v1.2.8"
@@ -49,9 +49,11 @@ ExternalProject_Add(
4949
-DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
5050
)
5151

52+
ADD_LIBRARY(zlib STATIC IMPORTED GLOBAL)
53+
SET_PROPERTY(TARGET zlib PROPERTY IMPORTED_LOCATION ${ZLIB_LIBRARIES})
54+
ADD_DEPENDENCIES(zlib extern_zlib)
55+
5256
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})
5557

5658
IF(WITH_C_API)
5759
INSTALL(DIRECTORY ${ZLIB_INCLUDE_DIR} DESTINATION third_party/zlib)

cmake/generic.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ function(merge_static_libs TARGET_NAME)
104104
foreach(lib ${libs})
105105
list(APPEND libs_deps ${${lib}_LIB_DEPENDS})
106106
endforeach()
107-
list(REMOVE_DUPLICATES libs_deps)
107+
if(libs_deps)
108+
list(REMOVE_DUPLICATES libs_deps)
109+
endif()
108110

109111
# To produce a library we need at least one source file.
110112
# It is created by add_custom_command below and will helps
@@ -191,10 +193,13 @@ function(cc_library TARGET_NAME)
191193
list(REMOVE_ITEM cc_library_DEPS warpctc)
192194
add_dependencies(${TARGET_NAME} warpctc)
193195
endif()
194-
# Support linking flags: --whole-archive (Linux) / -force_load (MacOS)
195-
target_circle_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
196196
if("${cc_library_DEPS}" MATCHES "ARCHIVE_START")
197+
# Support linking flags: --whole-archive (Linux) / -force_load (MacOS).
198+
# WARNING: Please don't use ARCHIVE_START&ARCHIVE_END if TARGET_NAME will be linked by other libraries.
199+
target_circle_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
197200
list(REMOVE_ITEM cc_library_DEPS ARCHIVE_START ARCHIVE_END)
201+
else()
202+
target_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
198203
endif()
199204
add_dependencies(${TARGET_NAME} ${cc_library_DEPS})
200205
endif()

0 commit comments

Comments
 (0)