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

Method to_json

src/core/impl/graph/cg_impl_seq.cpp:602–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

600
601#if MGB_ENABLE_JSON
602std::shared_ptr<json::Value> ComputingGraphImpl::ComputingSequence::to_json() const {
603 ThinHashSet<MemAllocPlan::Chunk*> all_mem_chunk;
604 VarNodeSet all_var_node;
605 ThinHashSet<OperatorNodeBase*> all_opr_node;
606
607 auto comp_seq = json::Array::make();
608
609 for (auto i : *m_opr_seq) {
610 all_opr_node.insert(i);
611 for (auto j : i->output()) {
612 all_var_node.insert(j);
613 if (j->mem_plan().valid())
614 all_mem_chunk.insert(&j->mem_plan().chunk());
615 }
616 comp_seq->add(json::String::make(i->id_str()));
617 }
618
619 // expand opr and var nodes that do not appear in comp seq,
620 // also expand var nodes which are only used in static infer
621 {
622 VarNodeArray new_var_node;
623 auto&& mgr = m_owner_graph->static_infer_manager_impl();
624 auto check_opr_input = [&](OperatorNodeBase* opr) {
625 auto update = [&](VarNode* var) {
626 if (!(all_var_node.count(var))) {
627 all_var_node.insert(var);
628 new_var_node.push_back(var);
629 }
630 };
631 for (auto i : opr->input()) {
632 update(i);
633 }
634 for (auto&& out : opr->output()) {
635 using DepType = static_infer::DepType;
636 for (auto&& i : mgr.get_deps({out, DepType::SHAPE})) {
637 update(i.dest);
638 }
639 for (auto&& i : mgr.get_deps({out, DepType::VALUE})) {
640 update(i.dest);
641 }
642 }
643 };
644 for (auto i : all_opr_node)
645 check_opr_input(i);
646 while (!new_var_node.empty()) {
647 auto opr = new_var_node.back()->owner_opr();
648 new_var_node.pop_back();
649 all_opr_node.insert(opr);
650 for (auto i : opr->output()) {
651 all_var_node.insert(i);
652 }
653 check_opr_input(opr);
654 }
655 }
656
657 auto dump_node_coll = [](auto&& collection) {
658 auto objptr = json::Object::make();
659 auto&& obj = *objptr;

Callers 1

Calls 15

updateFunction · 0.85
get_depsMethod · 0.80
backMethod · 0.80
makeFunction · 0.70
insertMethod · 0.45
outputMethod · 0.45
validMethod · 0.45
addMethod · 0.45
id_strMethod · 0.45
countMethod · 0.45
push_backMethod · 0.45
inputMethod · 0.45

Tested by

no test coverage detected