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

Method to_json

src/gopt/impl/global_layout_transform/subgraph_extractor.cpp:91–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89/* ================== GraphPartition =================*/
90#if MGB_ENABLE_JSON
91std::shared_ptr<json::Value> GraphPartition::to_json() const {
92 auto replaced_outputs = std::get<1>(replace_graph_by_placeholder());
93
94 ThinHashSet<VarNode*> all_var_node;
95 ThinHashSet<OperatorNodeBase*> all_opr_node;
96 auto comp_seq = json::Array::make();
97
98 auto cb = [&](OperatorNodeBase* opr) {
99 comp_seq->add(json::String::make(opr->id_str()));
100 for (const auto& i : opr->input()) {
101 if (all_var_node.count(i) == 0) {
102 all_var_node.insert(i);
103 }
104 }
105 all_opr_node.insert(opr);
106 for (const auto& o : opr->output()) {
107 all_var_node.insert(o);
108 }
109 };
110 cg::DepOprIter iter{cb};
111 for (const auto& o : replaced_outputs)
112 iter.add(o->owner_opr());
113
114 auto dump_node_coll = [](auto&& collection) {
115 auto objptr = json::Object::make();
116 auto&& obj = *objptr;
117 for (auto&& i : collection)
118 obj[i->id_str()] = i->to_json();
119 return objptr;
120 };
121
122 return json::Object::make(
123 {{"operator", dump_node_coll(all_opr_node)},
124 {"var", dump_node_coll(all_var_node)},
125 {"comp_seq", comp_seq}});
126}
127#endif
128
129std::pair<VarNodeArray, VarNodeArray> GraphPartition::replace_graph_by_placeholder()

Callers 6

TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 8

makeFunction · 0.50
addMethod · 0.45
id_strMethod · 0.45
inputMethod · 0.45
countMethod · 0.45
insertMethod · 0.45
outputMethod · 0.45
owner_oprMethod · 0.45

Tested by 6

TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36