MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / compile_prepare

Method compile_prepare

src/core/impl/graph/cg_impl.cpp:493–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491}
492
493ComputingGraphImpl::CompileState ComputingGraphImpl::compile_prepare(
494 const OutputSpec& out_spec) {
495 auto&& cmpnt = components();
496 mgb_throw_if(
497 m_recorded_seq_level2_dtor_chk, GraphError,
498 "graphs with comp_node_seq_record_level==2 can only be "
499 "compiled once");
500
501 mgb_throw_if(
502 out_spec.empty(), GraphError,
503 "empty output spec given to ComputingGraph::compile");
504 // topo sorter may have modified opr properties; restore them before this
505 // new compiling
506 topo_sorter().restore_opr_prop();
507 cmpnt.seq_comp_node_opt.restore_comp_nodes();
508
509 SpecialOprStat sopr_stat;
510 auto dest_vars = get_dest_vars_from_out_spec(out_spec, sopr_stat);
511
512#if MGB_ENABLE_SUBLINEAR
513 if (options().enable_sublinear_memory_opt) {
514 mgb_assert(!options().enable_dtr_memory_opt);
515 if (!sopr_stat.has_virtual_grad) {
516 mgb_log_debug(
517 "no virtual grad var; sublinear memory may produce "
518 "unsatisfying result");
519 }
520 seq_modifier_for_sublinear_memory().set_priority_before_opt(dest_vars);
521 }
522#else
523 mgb_assert(!options().enable_sublinear_memory_opt);
524#endif // MGB_ENABLE_SUBLINEAR
525
526#if MGB_ENABLE_DTR
527 if (options().enable_dtr_memory_opt) {
528 mgb_assert(!options().enable_sublinear_memory_opt);
529 seq_modifier_for_dtr().set_priority_before_opt(dest_vars);
530 }
531#else
532 mgb_assert(!options().enable_dtr_memory_opt);
533#endif // MGB_ENABLE_DTR
534
535#if !MGB_BUILD_SLIM_SERVING
536 mgb_assert(
537 !options().eager_evaluation, "attempt to compile eager_evaluation graph");
538
539 {
540 bool need_opt = std::abs(options().graph_opt_level) >= 2;
541 gopt::GraphOptimizer optimizer;
542 optimizer.verbosity(options().log_level);
543 optimizer.enable_check_result(options().graph_opt_level < 0);
544 if (sopr_stat.has_virtual_grad) {
545 if (need_opt) {
546#if MGB_ENABLE_OPR_MM
547 optimizer.add_pass<gopt::PackAllReduceScanPass>();
548#endif
549 optimizer.add_preset_passes(false, nullptr, &options());
550 }

Callers 1

concat_and_prepareMethod · 0.80

Calls 15

restore_opr_propMethod · 0.80
restore_comp_nodesMethod · 0.80
verbosityMethod · 0.80
apply_inplaceMethod · 0.80
optimize_comp_nodesMethod · 0.80
get_comp_seqMethod · 0.80
sanity_checkMethod · 0.80
makeFunction · 0.70
absFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected