未验证 提交 453a49b1 编写于 作者: W wopeizl 提交者: GitHub

Make ParallelExecutor support Windows GPU (#17787)

* fix the ParallelExecutor on Windows
test=develop
* restrict to use one GPU only under windows
上级 39bc8a55
...@@ -296,6 +296,11 @@ ParallelExecutor::ParallelExecutor(const std::vector<platform::Place> &places, ...@@ -296,6 +296,11 @@ ParallelExecutor::ParallelExecutor(const std::vector<platform::Place> &places,
member_->use_all_reduce_ = member_->use_all_reduce_ =
build_strategy.reduce_ == BuildStrategy::ReduceStrategy::kAllReduce; build_strategy.reduce_ == BuildStrategy::ReduceStrategy::kAllReduce;
member_->nranks_ = build_strategy.num_trainers_ * places.size(); member_->nranks_ = build_strategy.num_trainers_ * places.size();
#if defined(PADDLE_WITH_CUDA) && defined(_WIN32)
if (member_->use_cuda_) {
PADDLE_ENFORCE(places.size() == 1, "Windows can support Single GPU only.");
}
#endif
if (!member_->use_all_reduce_) { if (!member_->use_all_reduce_) {
PADDLE_ENFORCE(places.size() > 1, PADDLE_ENFORCE(places.size() > 1,
"If you set build_strategy.reduce with 'Reduce'," "If you set build_strategy.reduce with 'Reduce',"
...@@ -361,8 +366,6 @@ ParallelExecutor::ParallelExecutor(const std::vector<platform::Place> &places, ...@@ -361,8 +366,6 @@ ParallelExecutor::ParallelExecutor(const std::vector<platform::Place> &places,
member_->nccl_ctxs_.DefaultFlatCtx()->at(member_->places_[dev_id]); member_->nccl_ctxs_.DefaultFlatCtx()->at(member_->places_[dev_id]);
dev_ctx->set_nccl_comm(nccl_ctx.comm()); dev_ctx->set_nccl_comm(nccl_ctx.comm());
} }
#else
PADDLE_THROW("Not compiled with CUDA");
#endif #endif
} }
// broadcast parameters from the 0th device to others: // broadcast parameters from the 0th device to others:
...@@ -544,8 +547,6 @@ void ParallelExecutor::BCastParamsToDevices( ...@@ -544,8 +547,6 @@ void ParallelExecutor::BCastParamsToDevices(
} }
nccl_ctxs->WaitAll(); nccl_ctxs->WaitAll();
} }
#else
PADDLE_THROW("Not compiled with CUDA");
#endif #endif
} else { } else {
platform::CPUPlace cpu; platform::CPUPlace cpu;
...@@ -650,7 +651,9 @@ ParallelExecutor::~ParallelExecutor() { ...@@ -650,7 +651,9 @@ ParallelExecutor::~ParallelExecutor() {
bool ParallelExecutor::EnableParallelGraphExecution( bool ParallelExecutor::EnableParallelGraphExecution(
const ir::Graph &graph, const ExecutionStrategy &exec_strategy, const ir::Graph &graph, const ExecutionStrategy &exec_strategy,
const BuildStrategy &build_strategy) const { const BuildStrategy &build_strategy) const {
if (!FLAGS_enable_parallel_graph) return false; if (!FLAGS_enable_parallel_graph) {
return false;
}
bool enable_parallel_graph = true; bool enable_parallel_graph = true;
...@@ -670,11 +673,19 @@ bool ParallelExecutor::EnableParallelGraphExecution( ...@@ -670,11 +673,19 @@ bool ParallelExecutor::EnableParallelGraphExecution(
} }
} }
if (!member_->use_all_reduce_ || !member_->use_cuda_) if (!member_->use_all_reduce_ || !member_->use_cuda_) {
if (build_strategy.enable_sequential_execution_ || if (build_strategy.enable_sequential_execution_ ||
exec_strategy.type_ == ExecutionStrategy::ExecutorType::kExperimental) exec_strategy.type_ == ExecutionStrategy::ExecutorType::kExperimental) {
enable_parallel_graph = false; enable_parallel_graph = false;
}
}
#ifdef WIN32
VLOG(1) << "Windows has no support to parallel graph, enable_parallel_graph "
"would be forced to false.";
enable_parallel_graph = false;
#endif
return enable_parallel_graph; return enable_parallel_graph;
} }
......
...@@ -1341,6 +1341,9 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -1341,6 +1341,9 @@ All parameter, weight, gradient are variables in Paddle.
"num_trainers", "num_trainers",
[](const BuildStrategy &self) { return self.num_trainers_; }, [](const BuildStrategy &self) { return self.num_trainers_; },
[](BuildStrategy &self, int num_trainers) { [](BuildStrategy &self, int num_trainers) {
#ifdef WIN32
PADDLE_THROW("Windows has NO support to distribute mode.");
#endif
self.num_trainers_ = num_trainers; self.num_trainers_ = num_trainers;
}) })
.def_property( .def_property(
...@@ -1486,7 +1489,15 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -1486,7 +1489,15 @@ All parameter, weight, gradient are variables in Paddle.
.def_property( .def_property(
"is_distribution", "is_distribution",
[](const BuildStrategy &self) { return self.is_distribution_; }, [](const BuildStrategy &self) { return self.is_distribution_; },
[](BuildStrategy &self, bool b) { self.is_distribution_ = b; }) [](BuildStrategy &self, bool b) {
#ifdef WIN32
if (b) {
PADDLE_THROW("Windows has NO support to distribute mode.");
}
#else
self.is_distribution_ = b;
#endif
})
.def_property("async_mode", .def_property("async_mode",
[](const BuildStrategy &self) { return self.async_mode_; }, [](const BuildStrategy &self) { return self.async_mode_; },
[](BuildStrategy &self, bool b) { self.async_mode_ = b; }) [](BuildStrategy &self, bool b) { self.async_mode_ = b; })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册