Skip to content

Commit 31f598f

Browse files
committed
Merge branch 'develop' of github.com:PaddlePaddle/Paddle into improve_concat_split_op
2 parents e0e5453 + 74492d5 commit 31f598f

File tree

110 files changed

+2806
-1118
lines changed

Some content is hidden

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

110 files changed

+2806
-1118
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
paddle/operators/check_t.save
2+
paddle/operators/check_tensor.ls
3+
paddle/operators/tensor.save
4+
python/paddle/v2/fluid/tests/book/image_classification_resnet.inference.model/
5+
python/paddle/v2/fluid/tests/book/image_classification_vgg.inference.model/
6+
python/paddle/v2/fluid/tests/book/label_semantic_roles.inference.model/
17
*.DS_Store
28
build/
39
build_doc/

cmake/cuda.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
181181
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
182182
list(APPEND CUDA_NVCC_FLAGS ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
183183
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
184-
list(APPEND CUDA_NVCC_FLAGS ${CMAKE_CXX_FLAGS_MINSIZEREL})
184+
# nvcc 9 does not support -Os. Use Release flags instead
185+
list(APPEND CUDA_NVCC_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
185186
endif()
186187

187188
mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD)

cmake/generic.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,24 @@ function(cc_library TARGET_NAME)
179179
set(oneValueArgs "")
180180
set(multiValueArgs SRCS DEPS)
181181
cmake_parse_arguments(cc_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
182-
if (cc_library_SRCS)
183-
if (cc_library_SHARED OR cc_library_shared) # build *.so
182+
if(cc_library_SRCS)
183+
if(cc_library_SHARED OR cc_library_shared) # build *.so
184184
add_library(${TARGET_NAME} SHARED ${cc_library_SRCS})
185185
else()
186186
add_library(${TARGET_NAME} STATIC ${cc_library_SRCS})
187187
endif()
188-
if (cc_library_DEPS)
188+
if(cc_library_DEPS)
189189
# Don't need link libwarpctc.so
190-
if ("${cc_library_DEPS};" MATCHES "warpctc;")
190+
if("${cc_library_DEPS};" MATCHES "warpctc;")
191191
list(REMOVE_ITEM cc_library_DEPS warpctc)
192192
add_dependencies(${TARGET_NAME} warpctc)
193193
endif()
194+
# Support linking flags: --whole-archive (Linux) / -force_load (MacOS)
195+
target_circle_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
196+
if("${cc_library_DEPS}" MATCHES "ARCHIVE_START")
197+
list(REMOVE_ITEM cc_library_DEPS ARCHIVE_START ARCHIVE_END)
198+
endif()
194199
add_dependencies(${TARGET_NAME} ${cc_library_DEPS})
195-
target_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
196200
endif()
197201

198202
# cpplint code style

doc/api/v2/fluid/layers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ batch_norm
323323
.. autofunction:: paddle.v2.fluid.layers.batch_norm
324324
:noindex:
325325

326+
layer_norm
327+
----------
328+
329+
.. autofunction:: paddle.v2.fluid.layers.layer_norm
330+
:noindex:
331+
326332
beam_search_decode
327333
------------------
328334

doc/howto/rnn/index_cn.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RNN相关模型
1+
RNN模型
22
===========
33

44
.. toctree::

doc/index_cn.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ PaddlePaddle 文档
88
build_and_install/index_cn.rst
99
howto/index_cn.rst
1010
dev/index_cn.rst
11-
api/index_cn.rst
1211
faq/index_cn.rst

doc/index_en.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ PaddlePaddle Documentation
88
build_and_install/index_en.rst
99
howto/index_en.rst
1010
dev/index_en.rst
11-
api/index_en.rst

paddle/framework/block_desc.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ BlockDesc::BlockDesc(const BlockDesc &other, proto::BlockDesc *desc,
162162
: prog_(prog), desc_(desc) {
163163
need_update_ = true;
164164
for (auto &op : other.ops_) {
165-
ops_.emplace_back(new OpDesc(*op, this));
165+
ops_.emplace_back(new OpDesc(*op->Proto(), prog, this));
166166
}
167-
168167
for (auto &it : other.vars_) {
169168
auto *var = new VarDesc(*it.second);
170169
vars_[it.first].reset(var);

paddle/framework/channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
1+
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

paddle/framework/channel_test.cc

Lines changed: 75 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
1+
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -25,6 +25,26 @@ using paddle::framework::CloseChannel;
2525
using paddle::framework::details::Buffered;
2626
using paddle::framework::details::UnBuffered;
2727

28+
void RecevingOrderEqualToSendingOrder(Channel<int> *ch) {
29+
unsigned sum_send = 0;
30+
std::thread t([&]() {
31+
for (int i = 0; i < 5; i++) {
32+
EXPECT_EQ(ch->Send(&i), true);
33+
sum_send += i;
34+
}
35+
});
36+
for (int i = 0; i < 5; i++) {
37+
int recv;
38+
EXPECT_EQ(ch->Receive(&recv), true);
39+
EXPECT_EQ(recv, i);
40+
}
41+
42+
CloseChannel(ch);
43+
t.join();
44+
EXPECT_EQ(sum_send, 10U);
45+
delete ch;
46+
}
47+
2848
TEST(Channel, MakeAndClose) {
2949
using paddle::framework::details::Buffered;
3050
using paddle::framework::details::UnBuffered;
@@ -137,9 +157,7 @@ TEST(Channel, ReceiveFromBufferedChannelReturnResidualValuesTest) {
137157

138158
for (size_t i = 0; i < buffer_size; ++i) {
139159
EXPECT_EQ(ch->Receive(&out),
140-
false); // after receiving residual values, return zeros.
141-
// Note: we cannot check EXPECT_EQ(out, 0), because C++ doesn't
142-
// define zero values like Go does.
160+
false); // receiving on closed channel should return false
143161
}
144162
delete ch;
145163
}
@@ -158,39 +176,25 @@ TEST(Channel, ConcurrentSendNonConcurrentReceiveWithSufficientBufferSize) {
158176
sum += i;
159177
}
160178
});
161-
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait 0.5 sec
179+
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait 0.1 sec
162180
EXPECT_EQ(sum, 45U);
163181

164182
CloseChannel(ch);
165183
t.join();
166184
delete ch;
167185
}
168186

169-
TEST(Channel, SimpleUnbufferedChannelTest) {
187+
TEST(Channel, RecevingOrderEqualToSendingOrderWithUnBufferedChannel) {
170188
auto ch = MakeChannel<int>(0);
171-
unsigned sum_send = 0;
172-
std::thread t([&]() {
173-
for (int i = 0; i < 5; i++) {
174-
EXPECT_EQ(ch->Send(&i), true);
175-
sum_send += i;
176-
}
177-
});
178-
for (int i = 0; i < 5; i++) {
179-
int recv;
180-
EXPECT_EQ(ch->Receive(&recv), true);
181-
EXPECT_EQ(recv, i);
182-
}
189+
RecevingOrderEqualToSendingOrder(ch);
190+
}
183191

184-
CloseChannel(ch);
185-
t.join();
186-
EXPECT_EQ(sum_send, 10U);
187-
delete ch;
192+
TEST(Channel, RecevingOrderEqualToSendingOrderWithBufferedChannel) {
193+
auto ch = MakeChannel<int>(10);
194+
RecevingOrderEqualToSendingOrder(ch);
188195
}
189196

190-
// This tests that closing a buffered channel also unblocks
191-
// any receivers waiting on the channel
192-
TEST(Channel, BufferedChannelCloseUnblocksReceiversTest) {
193-
auto ch = MakeChannel<int>(1);
197+
void ChannelCloseUnblocksReceiversTest(Channel<int> *ch) {
194198
size_t num_threads = 5;
195199
std::thread t[num_threads];
196200
bool thread_ended[num_threads];
@@ -201,15 +205,14 @@ TEST(Channel, BufferedChannelCloseUnblocksReceiversTest) {
201205
t[i] = std::thread(
202206
[&](bool *p) {
203207
int data;
204-
// All reads should return false
205208
EXPECT_EQ(ch->Receive(&data), false);
206209
*p = true;
207210
},
208211
&thread_ended[i]);
209212
}
210-
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait
213+
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait 0.1 sec
211214

212-
// Verify that all threads are blocked
215+
// Verify that all the threads are blocked
213216
for (size_t i = 0; i < num_threads; i++) {
214217
EXPECT_EQ(thread_ended[i], false);
215218
}
@@ -218,21 +221,20 @@ TEST(Channel, BufferedChannelCloseUnblocksReceiversTest) {
218221
// This should unblock all receivers
219222
CloseChannel(ch);
220223

221-
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // wait
224+
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait 0.1 sec
222225

223226
// Verify that all threads got unblocked
224227
for (size_t i = 0; i < num_threads; i++) {
225228
EXPECT_EQ(thread_ended[i], true);
226229
}
227230

228231
for (size_t i = 0; i < num_threads; i++) t[i].join();
229-
delete ch;
230232
}
231233

232-
// This tests that closing a buffered channel also unblocks
233-
// any senders waiting for channel to have write space
234-
TEST(Channel, BufferedChannelCloseUnblocksSendersTest) {
235-
auto ch = MakeChannel<int>(1);
234+
void ChannelCloseUnblocksSendersTest(Channel<int> *ch) {
235+
using paddle::framework::details::Buffered;
236+
using paddle::framework::details::UnBuffered;
237+
236238
size_t num_threads = 5;
237239
std::thread t[num_threads];
238240
bool thread_ended[num_threads];
@@ -252,116 +254,72 @@ TEST(Channel, BufferedChannelCloseUnblocksSendersTest) {
252254
}
253255
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait
254256

255-
// Verify that atleast 4 threads are blocked
256-
int ct = 0;
257-
for (size_t i = 0; i < num_threads; i++) {
258-
if (thread_ended[i] == false) ct++;
257+
if (dynamic_cast<Buffered<int> *>(ch)) {
258+
// If ch is Buffered, atleast 4 threads must be blocked.
259+
int ct = 0;
260+
for (size_t i = 0; i < num_threads; i++) {
261+
if (!thread_ended[i]) ct++;
262+
}
263+
EXPECT_GE(ct, 4);
264+
} else {
265+
// If ch is UnBuffered, all the threads should be blocked.
266+
for (size_t i = 0; i < num_threads; i++) {
267+
EXPECT_EQ(thread_ended[i], false);
268+
}
259269
}
260-
// Atleast 4 threads must be blocked
261-
EXPECT_GE(ct, 4);
262-
263270
// Explicitly close the thread
264271
// This should unblock all senders
265272
CloseChannel(ch);
266273

267-
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // wait
274+
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait
268275

269276
// Verify that all threads got unblocked
270277
for (size_t i = 0; i < num_threads; i++) {
271278
EXPECT_EQ(thread_ended[i], true);
272279
}
273280

274-
// Verify that only 1 send was successful
275-
ct = 0;
276-
for (size_t i = 0; i < num_threads; i++) {
277-
if (send_success[i]) ct++;
281+
if (dynamic_cast<Buffered<int> *>(ch)) {
282+
// Verify that only 1 send was successful
283+
int ct = 0;
284+
for (size_t i = 0; i < num_threads; i++) {
285+
if (send_success[i]) ct++;
286+
}
287+
// Only 1 send must be successful
288+
EXPECT_EQ(ct, 1);
278289
}
279-
// Only 1 send must be successful
280-
EXPECT_EQ(ct, 1);
281290

282291
for (size_t i = 0; i < num_threads; i++) t[i].join();
292+
}
293+
294+
// This tests that closing a buffered channel also unblocks
295+
// any receivers waiting on the channel
296+
TEST(Channel, BufferedChannelCloseUnblocksReceiversTest) {
297+
auto ch = MakeChannel<int>(1);
298+
ChannelCloseUnblocksReceiversTest(ch);
299+
delete ch;
300+
}
301+
302+
// This tests that closing a buffered channel also unblocks
303+
// any senders waiting for channel to have write space
304+
TEST(Channel, BufferedChannelCloseUnblocksSendersTest) {
305+
auto ch = MakeChannel<int>(1);
306+
ChannelCloseUnblocksSendersTest(ch);
283307
delete ch;
284308
}
285309

286310
// This tests that closing an unbuffered channel also unblocks
287311
// unblocks any receivers waiting for senders
288312
TEST(Channel, UnbufferedChannelCloseUnblocksReceiversTest) {
289313
auto ch = MakeChannel<int>(0);
290-
size_t num_threads = 5;
291-
std::thread t[num_threads];
292-
bool thread_ended[num_threads];
293-
294-
// Launches threads that try to read and are blocked becausew of no writers
295-
for (size_t i = 0; i < num_threads; i++) {
296-
thread_ended[i] = false;
297-
t[i] = std::thread(
298-
[&](bool *p) {
299-
int data;
300-
EXPECT_EQ(ch->Receive(&data), false);
301-
*p = true;
302-
},
303-
&thread_ended[i]);
304-
}
305-
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait 0.5 sec
306-
307-
// Verify that all the threads are blocked
308-
for (size_t i = 0; i < num_threads; i++) {
309-
EXPECT_EQ(thread_ended[i], false);
310-
}
311-
312-
// Explicitly close the thread
313-
// This should unblock all receivers
314-
CloseChannel(ch);
315-
316-
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait 0.5 sec
317-
318-
// Verify that all threads got unblocked
319-
for (size_t i = 0; i < num_threads; i++) {
320-
EXPECT_EQ(thread_ended[i], true);
321-
}
322-
323-
for (size_t i = 0; i < num_threads; i++) t[i].join();
314+
ChannelCloseUnblocksReceiversTest(ch);
324315
delete ch;
325316
}
326317

327318
// This tests that closing an unbuffered channel also unblocks
328319
// unblocks any senders waiting for senders
329320
TEST(Channel, UnbufferedChannelCloseUnblocksSendersTest) {
330321
auto ch = MakeChannel<int>(0);
331-
size_t num_threads = 5;
332-
std::thread t[num_threads];
333-
bool thread_ended[num_threads];
334-
335-
// Launches threads that try to read and are blocked becausew of no writers
336-
for (size_t i = 0; i < num_threads; i++) {
337-
thread_ended[i] = false;
338-
t[i] = std::thread(
339-
[&](bool *p) {
340-
int data = 10;
341-
EXPECT_EQ(ch->Send(&data), false);
342-
*p = true;
343-
},
344-
&thread_ended[i]);
345-
}
346-
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait 0.5 sec
347-
348-
// Verify that all the threads are blocked
349-
for (size_t i = 0; i < num_threads; i++) {
350-
EXPECT_EQ(thread_ended[i], false);
351-
}
352-
353-
// Explicitly close the thread
354-
// This should unblock all receivers
355-
CloseChannel(ch);
356-
357-
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait 0.5 sec
358-
359-
// Verify that all threads got unblocked
360-
for (size_t i = 0; i < num_threads; i++) {
361-
EXPECT_EQ(thread_ended[i], true);
362-
}
363-
364-
for (size_t i = 0; i < num_threads; i++) t[i].join();
322+
ChannelCloseUnblocksReceiversTest(ch);
365323
delete ch;
366324
}
367325

0 commit comments

Comments
 (0)