Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpp parallel executor #9080

Merged
merged 163 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
0621c32
init commit
Mar 13, 2018
e67325c
update readme
Mar 14, 2018
8f061e4
delete param name
Mar 14, 2018
baef112
ParallelExecutor And dependency engine
reyoung Mar 14, 2018
692a0f7
Better name
reyoung Mar 14, 2018
ae88fde
Use thread pool
reyoung Mar 15, 2018
22bb262
Remove out of date design
reyoung Mar 15, 2018
35744e7
Polish code
reyoung Mar 15, 2018
193c0a7
Handle var hazard
reyoung Mar 15, 2018
d84ddcf
Stash
reyoung Mar 15, 2018
6f0dfd8
Single GPU ParallelExecutor complete
reyoung Mar 16, 2018
8c9cd36
Polish code style
reyoung Mar 16, 2018
8b397d1
Make recordio file reader thread-safe by default
reyoung Mar 16, 2018
5e87cd7
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
reyoung Mar 16, 2018
0ef9edf
Stash
reyoung Mar 16, 2018
9fc0b59
Test more
reyoung Mar 16, 2018
d470763
Stash
reyoung Mar 16, 2018
c15d2c9
Update
reyoung Mar 16, 2018
8f0590e
Add ncclAllReduce
reyoung Mar 16, 2018
e8a7e5d
Update
reyoung Mar 16, 2018
b2c7a9b
Wait by stream
reyoung Mar 16, 2018
254d7ff
Refactor local_scopes
reyoung Mar 16, 2018
9cb8f50
Complete fetch op
reyoung Mar 19, 2018
e18a269
Add debug code
reyoung Mar 19, 2018
389ea18
Debug code
reyoung Mar 19, 2018
f8141d9
Debug
reyoung Mar 19, 2018
09935ab
Debug
reyoung Mar 19, 2018
0023c3b
Use atomic bool
reyoung Mar 19, 2018
f52714d
Debug
reyoung Mar 19, 2018
5957f28
Debug
reyoung Mar 19, 2018
36e0415
Single Thread
reyoung Mar 19, 2018
f3e983e
Memory order
reyoung Mar 19, 2018
b57b880
Debug
reyoung Mar 19, 2018
b1cb8bb
Debug
reyoung Mar 19, 2018
1f063d0
Memorder
reyoung Mar 19, 2018
515e516
Add more log
reyoung Mar 19, 2018
ea11a0a
Use volitie
reyoung Mar 19, 2018
a87ce91
Use mtx
reyoung Mar 19, 2018
a5ba704
Counter
reyoung Mar 19, 2018
d3e55fd
Guard devctx
reyoung Mar 19, 2018
866f6f1
Debug
reyoung Mar 19, 2018
7bff02b
Change to pending op
reyoung Mar 19, 2018
5fa535b
Wait all thread done
reyoung Mar 19, 2018
c7beac1
Add dummy var
reyoung Mar 19, 2018
1f53193
Use atomic code
reyoung Mar 19, 2018
3aa7051
Remove DevCtx lock
reyoung Mar 19, 2018
d7badb3
Use event to sync stream
reyoung Mar 19, 2018
29cc9f3
SetDev for nccl
reyoung Mar 19, 2018
8af5770
Only wait same device
reyoung Mar 19, 2018
071043c
Add paddle enforce
reyoung Mar 19, 2018
9824e8f
Scale loss op use event
reyoung Mar 19, 2018
4a33009
Add log
reyoung Mar 19, 2018
bade579
Wait code
reyoung Mar 19, 2018
7fd0d24
Add lgo
reyoung Mar 19, 2018
dad7bda
Add setDev
reyoung Mar 19, 2018
932364a
Sync dev
reyoung Mar 19, 2018
d55a03d
Scale loss on place
reyoung Mar 19, 2018
d26f093
Log
reyoung Mar 19, 2018
99f85a9
Set dev
reyoung Mar 19, 2018
b94ffac
SetDev
reyoung Mar 19, 2018
ee697b8
Larger model
reyoung Mar 19, 2018
48619bc
Shrink model
reyoung Mar 19, 2018
c372ce2
Add event for computational op
reyoung Mar 19, 2018
c18c2f6
Sync all computation streams at the end of run
reyoung Mar 20, 2018
d3c82c3
Wait multiple stream
reyoung Mar 20, 2018
3da4159
Add run iter
reyoung Mar 20, 2018
4137bb4
Add wait
reyoung Mar 20, 2018
d2cb379
Wait all evernts
reyoung Mar 20, 2018
8a9de67
Remove wait
reyoung Mar 20, 2018
3238ce0
Add wait
reyoung Mar 20, 2018
e025e28
Exchange wait op
reyoung Mar 20, 2018
260cfe3
Stop Wait NCCL Stream
reyoung Mar 20, 2018
feb569f
Add log
reyoung Mar 20, 2018
9b1f4d5
After nccl add event
reyoung Mar 20, 2018
631aa3d
Wait all inputs ready
reyoung Mar 20, 2018
4185dd4
Disable multi-thread
reyoung Mar 20, 2018
1dd216d
Wait bcast param
reyoung Mar 20, 2018
f251a58
Use base class manage events
reyoung Mar 20, 2018
ca4b3d2
Use 12 threads
reyoung Mar 20, 2018
7643c2c
Add flag for use event
reyoung Mar 20, 2018
fbbcedd
Fix bug
reyoung Mar 20, 2018
f8f1a96
Add debug code
reyoung Mar 20, 2018
3c9cea5
Add more log
reyoung Mar 20, 2018
a8bd7b9
Add log
reyoung Mar 20, 2018
e53b6ab
Use no thread
reyoung Mar 20, 2018
dbed123
Debug
reyoung Mar 20, 2018
4e43b71
Add wait log
reyoung Mar 20, 2018
a0494f8
Mutex lock wait
reyoung Mar 20, 2018
1c2b610
Add
reyoung Mar 20, 2018
798e690
Change mem order
reyoung Mar 20, 2018
95a0d7c
Illegal memory access
reyoung Mar 20, 2018
ed7727e
Fix bug in system allocator
reyoung Mar 20, 2018
176277b
Add log
reyoung Mar 20, 2018
1533bf1
Use event and single thread
reyoung Mar 20, 2018
ba227df
Expose num_threads
reyoung Mar 20, 2018
d42117e
Set NumThreads
reyoung Mar 20, 2018
65bc7d1
Add mtx to ncclAllReduce
reyoung Mar 20, 2018
eb0a580
Add enforce
reyoung Mar 20, 2018
82693e7
Wait nccl all reduce
reyoung Mar 20, 2018
e335f01
Add more logs
reyoung Mar 20, 2018
43e5407
Debug code
reyoung Mar 20, 2018
599f7a8
Refine code
reyoung Mar 20, 2018
7ac969b
Debug
reyoung Mar 21, 2018
90f9801
Do not wait computation stream
reyoung Mar 21, 2018
99fe83a
Move nccl helper
reyoung Mar 21, 2018
41ad632
Add NCCL Group Guard
reyoung Mar 21, 2018
f2685be
Clean code
reyoung Mar 21, 2018
a478a11
NCCL Guard for bcast
reyoung Mar 21, 2018
6ebc6bf
ReorganizeCode
reyoung Mar 21, 2018
fe7ed28
Extract NCCLCtxMap
reyoung Mar 21, 2018
5368e50
Reorganize code
reyoung Mar 21, 2018
15f5f10
AddInput/AddOutput for OpHandle
reyoung Mar 21, 2018
5c333e4
Add dctor for dev_ctx
reyoung Mar 21, 2018
f28ae6e
Reorganize Code
reyoung Mar 21, 2018
3181501
Rerange code
reyoung Mar 21, 2018
8dec4ad
Use int not Place for vars
reyoung Mar 21, 2018
64d7a30
Extract SSAGraph
reyoung Mar 21, 2018
79989c9
Add SSA builder
reyoung Mar 21, 2018
dd73d18
Extract SSAGraph
reyoung Mar 22, 2018
b123e43
extract multi devices graph builder
reyoung Mar 24, 2018
4c3361c
Extract GraphExecutor
reyoung Mar 24, 2018
c70b60d
Make executor steal graph inside
reyoung Mar 24, 2018
e314439
Extract Executors to indie modules
reyoung Mar 24, 2018
a7b0d5b
Clean code
reyoung Mar 24, 2018
edfd741
Add simple python wrapper for ParallelExecutor
reyoung Mar 24, 2018
5c7a523
Add Graphviz output
reyoung Mar 26, 2018
50e7e25
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
reyoung Mar 26, 2018
54bd17f
Complete Flowers
reyoung Mar 26, 2018
02aaecc
Fix CPU compile
reyoung Mar 26, 2018
3aa2a8f
Follow comments
reyoung Mar 26, 2018
ee97687
Fix compile
reyoung Mar 26, 2018
cb40c33
Update unittest
reyoung Mar 26, 2018
9dd64d8
WMT Model
reyoung Mar 26, 2018
aba46f0
Disable P2P
reyoung Mar 27, 2018
833e522
Enhance drop kids
reyoung Mar 27, 2018
f385228
Add Paddle Enforce
reyoung Mar 27, 2018
5a02739
Throw error
reyoung Mar 27, 2018
55e2cc3
FetchOp Force sync
reyoung Mar 27, 2018
b6ca371
Get error
reyoung Mar 27, 2018
76570c2
Wait fetch op
reyoung Mar 27, 2018
2227632
Change fetch op
reyoung Mar 27, 2018
9af8708
Use heap variables
reyoung Mar 27, 2018
dfb8680
Early drop fetch op
reyoung Mar 27, 2018
52dd8ff
Force sync dev
reyoung Mar 27, 2018
5b92dd4
Remove dev sync
reyoung Mar 27, 2018
c42c4a6
Add performance tests
reyoung Mar 27, 2018
3f88fad
Fix merge op
reyoung Mar 27, 2018
c0c2e15
NCCL AllReduce
reyoung Mar 27, 2018
7dcb217
Refine allreduce op
reyoung Mar 27, 2018
50f71f5
Using blocking queue
reyoung Mar 27, 2018
dcf7bd2
Add initP2P
reyoung Mar 27, 2018
201f79d
Use Extend method
reyoung Mar 27, 2018
5408854
Disable model evaluation in unittests
reyoung Mar 28, 2018
9f4a98f
Add design doc
reyoung Mar 28, 2018
084cdd1
Rename code
reyoung Mar 28, 2018
f2d29be
Disable transformer
reyoung Mar 28, 2018
f707a83
Add link
reyoung Mar 28, 2018
b077558
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
reyoung Mar 28, 2018
7da1ea0
Use PopAll
reyoung Mar 28, 2018
ce2f096
Merge branch 'cpp_parallel_executor' of github.com:reyoung/Paddle int…
reyoung Mar 28, 2018
38b53b3
Remove Pop method
reyoung Mar 28, 2018
e868950
Add comments
reyoung Mar 29, 2018
af230d9
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
reyoung Mar 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ include(external/cares)
include(external/grpc)
include(external/snappy) # download snappy
include(external/snappystream)
include(external/threadpool)

include(cudnn) # set cudnn libraries, must before configure
include(cupti)
Expand Down
30 changes: 30 additions & 0 deletions cmake/external/threadpool.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
INCLUDE(ExternalProject)

SET(THREADPOOL_SOURCE_DIR ${THIRD_PARTY_PATH}/threadpool)
SET(THREADPOOL_INCLUDE_DIR ${THREADPOOL_SOURCE_DIR}/src/extern_threadpool)
INCLUDE_DIRECTORIES(${THREADPOOL_INCLUDE_DIR})

ExternalProject_Add(
extern_threadpool
${EXTERNAL_PROJECT_LOG_ARGS}
GIT_REPOSITORY "https://github.com/progschj/ThreadPool.git"
GIT_TAG 9a42ec1329f259a5f4881a291db1dcb8f2ad9040
PREFIX ${THREADPOOL_SOURCE_DIR}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

if (${CMAKE_VERSION} VERSION_LESS "3.3.0")
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/threadpool_dummy.c)
file(WRITE ${dummyfile} "const char *dummy_threadpool = \"${dummyfile}\";")
add_library(simple_threadpool STATIC ${dummyfile})
else()
add_library(simple_threadpool INTERFACE)
endif()

add_dependencies(simple_threadpool extern_threadpool)

LIST(APPEND external_project_dependencies simple_threadpool)
2 changes: 2 additions & 0 deletions paddle/fluid/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ cc_library(feed_fetch_method SRCS feed_fetch_method.cc DEPS lod_tensor scope glo

cc_library(executor SRCS executor.cc DEPS op_registry device_context scope
framework_proto backward glog lod_rank_table feed_fetch_method)
cc_library(parallel_executor SRCS parallel_executor.cc DEPS op_registry device_context scope
framework_proto backward glog lod_rank_table feed_fetch_method executor simple_threadpool concat)

cc_library(prune SRCS prune.cc DEPS framework_proto)
cc_test(prune_test SRCS prune_test.cc DEPS op_info prune recurrent_op device_context)
Expand Down
21 changes: 17 additions & 4 deletions paddle/fluid/framework/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct ExecutorPrepareContext {

Executor::Executor(const platform::Place& place) : place_(place) {}

static void CreateTensor(Variable* var, proto::VarType::Type var_type) {
void InitializeVariable(Variable* var, proto::VarType::Type var_type) {
if (var_type == proto::VarType::LOD_TENSOR) {
var->GetMutable<LoDTensor>();
} else if (var_type == proto::VarType::SELECTED_ROWS) {
Expand Down Expand Up @@ -292,31 +292,44 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,

if (var->Persistable()) {
auto* ptr = scope->Var(var->Name());
CreateTensor(ptr, var->GetType());
InitializeVariable(ptr, var->GetType());
VLOG(3) << "Create Variable " << var->Name()
<< " global, which pointer is " << ptr;
} else {
auto* ptr = local_scope->Var(var->Name());
CreateTensor(ptr, var->GetType());
InitializeVariable(ptr, var->GetType());
VLOG(3) << "Create Variable " << var->Name()
<< " locally, which pointer is " << ptr;
}
}
} else {
for (auto& var : block.AllVars()) {
auto* ptr = local_scope->Var(var->Name());
CreateTensor(ptr, var->GetType());
InitializeVariable(ptr, var->GetType());
VLOG(3) << "Create variable " << var->Name() << ", which pointer is "
<< ptr;
}
} // if (create_local_scope)
} // if (create_vars)

for (auto& op : ctx->ops_) {
// TODO(ty):
// e.g. sgd should wait for allreduce to be finished
// if op's input is params' grad:
// sync with allreduce stream
// SyncMultipleStreams(op);

VLOG(4) << place_ << " " << op->DebugStringEx(local_scope);
op->Run(*local_scope, place_);
VLOG(3) << place_ << " " << op->DebugStringEx(local_scope);

// TODO(ty):
// e.g. allreduce shoudl wait for fc_grad to be finished.
// if op's output is params' grad:
// sync with computation stream
// apply allreduce on allreduce stream
// SyncMultipleStreams(op);

if (FLAGS_benchmark) {
VLOG(2) << "Memory used after operator " + op->Type() + " running: "
<< memory::memory_usage(place_);
Expand Down
3 changes: 3 additions & 0 deletions paddle/fluid/framework/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Executor {
const std::string& feed_holder_name = "feed",
const std::string& fetch_holder_name = "fetch");

private:
static ExecutorPrepareContext* Prepare(const ProgramDesc& program,
int block_id);

Expand All @@ -58,5 +59,7 @@ class Executor {
const platform::Place place_;
};

extern void InitializeVariable(Variable* var, proto::VarType::Type var_type);

} // namespace framework
} // namespace paddle
Loading