MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / PrepareNCCLCommunicator

Method PrepareNCCLCommunicator

paddle/fluid/framework/compiled_program.cc:801–847  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

799}
800
801void CompiledProgram::PrepareNCCLCommunicator(Scope *global_scope) {
802 if (member_->build_strategy_.reduce_ ==
803 BuildStrategy::ReduceStrategy::kNoReduce) {
804 return;
805 }
806
807 if (member_->IsUseCUDA(member_->use_device_) && member_->nranks_ > 1) {
808#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
809 member_->InitOrGetNCCLCommunicator(global_scope, &member_->build_strategy_);
810
811 // Initialize device context's nccl comm, will be used by normal
812 // Operators like sync_batch_norm, and collective ops.
813 // NOTE: more than one CompiledProgram with same place, the nccl comm will
814 // be rewrite and there will be some problem.
815 // NOTE: NCCL group-calls and non-group-calls can not use the same
816 // NCCL communicator, so for ParallelGraph and Multi-Process mode, re-use
817 // same communicators.
818 auto *nccl_ctxs = member_->nccl_ctxs_->GetSyncBatchNormCtx(
819 global_scope, member_->places_);
820 auto &pool = phi::DeviceContextPool::Instance();
821 for (auto &place : member_->places_) {
822 auto *dev_ctx = static_cast<phi::GPUContext *>(pool.Get(place));
823 auto &nccl_ctx = nccl_ctxs->at(place);
824 dev_ctx->set_nccl_comm(nccl_ctx.comm());
825 }
826#else
827 PADDLE_THROW(common::errors::PreconditionNotMet("Not compiled with CUDA."));
828#endif
829 }
830 if (member_->use_device_ == p::kXPU && member_->nranks_ > 1) {
831#if defined(PADDLE_WITH_XPU_BKCL)
832 member_->InitOrGetBKCLCommunicator(global_scope, member_->build_strategy_);
833
834 auto *bkcl_ctxs = member_->bkcl_ctxs_->GetSyncBatchNormCtx(
835 global_scope, member_->places_);
836 auto &pool = phi::DeviceContextPool::Instance();
837 for (size_t dev_id = 0; dev_id < member_->places_.size(); ++dev_id) {
838 auto *dev_ctx =
839 static_cast<phi::XPUContext *>(pool.Get(member_->places_[dev_id]));
840 auto &bkcl_ctx = bkcl_ctxs->at(member_->places_[dev_id]);
841 dev_ctx->SetBkclContext(bkcl_ctx.comm());
842 }
843#else
844 PADDLE_THROW(common::errors::PreconditionNotMet("Not compiled with XPU."));
845#endif
846 }
847}
848
849std::vector<ir::Graph *> CompiledProgram::CompileGraphWithBuildStrategy(
850 ir::Graph *graph,

Callers

nothing calls this directly

Calls 11

InstanceFunction · 0.85
IsUseCUDAMethod · 0.80
set_nccl_commMethod · 0.80
GetSyncBatchNormCtxMethod · 0.45
GetMethod · 0.45
atMethod · 0.45
commMethod · 0.45
sizeMethod · 0.45
SetBkclContextMethod · 0.45

Tested by

no test coverage detected