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

Method CompiledProgram

paddle/fluid/framework/compiled_program.cc:472–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470}
471
472CompiledProgram::CompiledProgram(const std::vector<phi::Place> &places,
473 const std::vector<std::string> &bcast_vars,
474 const std::string &loss_var_name,
475 Scope *scope,
476 const std::vector<Scope *> &local_scopes,
477 const BuildStrategy &build_strategy,
478 ir::Graph *graph)
479 : member_(new CompiledProgramPrivate(places, scope)) {
480 PADDLE_ENFORCE_EQ(
481 !places.empty(),
482 true,
483 common::errors::Unavailable("NPU is not supported in CompiledProgram."));
484 InitP2P(places);
485 InitReaderQueueDeviceCount(
486 graph, *(member_->global_scope_), member_->places_.size());
487 // Initialize necessary info of member_ with strategy.
488 InitProgramPrivateMemberInfo(build_strategy, places.size());
489
490 // Step 1. Create local scopes and Clone graph into multi device
491 CreateLocalScopes(scope, local_scopes, /*create_new*/ true);
492 std::vector<ir::Graph *> graphs = CloneGraphToMultiDevices(graph);
493 PrepareNCCLCommunicator(scope);
494
495 // broadcast parameters from the 0th device to others:
496 auto need_broadcast = [&]() -> bool {
497 if (member_->build_strategy_.num_trainers_ > 1) { // NOLINT
498 // 1. num_tariners would be grater than 1 for nccl distributed training.
499 return true;
500 } else if (member_->local_scopes_.size() != 1 && local_scopes.empty()) {
501 // 2. Only one trainer process, but CompiledProgram hold multiple
502 // devices.
503 return true;
504 }
505 return false;
506 };
507 if (need_broadcast()) {
508 BCastParamsToDevices(bcast_vars, member_->build_strategy_.trainer_id_);
509 }
510
511 // Step 2. Convert main_program to SSA form and dependency graph. Also, insert
512 // ncclOp
513 std::vector<ir::Graph *> async_graphs =
514 CompileGraphWithBuildStrategy(graph, &graphs, loss_var_name);
515 graph = member_->ApplyMemoryOptimizePass(graph);
516}
517
518void CompiledProgram::BCastParamsToDevices(const std::vector<std::string> &vars,
519 int trainer_id) const {

Callers 15

quant_awareFunction · 0.80
_minimize_implMethod · 0.80
add_build_strategy_forFunction · 0.80
run_trainerMethod · 0.80

Calls 4

InitP2PFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 15

run_trainerMethod · 0.64
test_static_unaryMethod · 0.64
_test_ir_passMethod · 0.64
run_mainMethod · 0.64
check_networkMethod · 0.64