| 563 | } |
| 564 | |
| 565 | Maybe<void> NNGraph::InitRuntime() { |
| 566 | CHECK_OR_RETURN(!runtime_inited_) |
| 567 | << Error::RuntimeError() << "nn.Graph runtime is already initialized"; |
| 568 | |
| 569 | auto compile_tc = std::make_unique<CostCounter<std::chrono::seconds>>(true, true); |
| 570 | NewRuntimeBuffers(); |
| 571 | |
| 572 | JUST(GetVariableRealBlobAfterSyncPlan()); |
| 573 | |
| 574 | // NOTE(strint): Do memory shrink to free cached memory in eager VM before graph runtime init. |
| 575 | JUST(vm::CurrentRankSync()); |
| 576 | auto* vm = JUST(SingletonMaybe<VirtualMachine>()); |
| 577 | JUST(vm->ShrinkAllMem()); |
| 578 | |
| 579 | if (Singleton<ResourceDesc, ForSession>::Get()->enable_debug_mode()) { |
| 580 | auto cur_rank = GlobalProcessCtx::Rank(); |
| 581 | auto plan_name = "job_" + name_ + "_plan"; |
| 582 | if (JUST(CurrentCompileMode()) != CompileMode::kNaive) { |
| 583 | plan_name += std::to_string(cur_rank); |
| 584 | } |
| 585 | if (cur_rank == 0 || JUST(CurrentCompileMode()) != CompileMode::kNaive) { |
| 586 | TeePersistentLogStream::Create(plan_name)->Write(plan_); |
| 587 | PlanUtil::ToDotFile(plan_, plan_name + ".dot"); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | runtime_.reset(new Runtime(plan_, variable_op_name2eager_blob_object_)); |
| 592 | compile_tc->Count("[GraphCompile]" + name_ + " InitRuntime", 0, true); |
| 593 | JUST(LogProgress("[GraphCompile]" + name_ + " Done", true)); |
| 594 | |
| 595 | runtime_inited_ = true; |
| 596 | return Maybe<void>::Ok(); |
| 597 | } |
| 598 | |
| 599 | Maybe<void> NNGraph::AlignStatesAfterLogicalGraphCompile() { |
| 600 | auto compile_tc = std::make_unique<CostCounter<std::chrono::seconds>>(true, true); |
nothing calls this directly
no test coverage detected