| 89 | /* ================== GraphPartition =================*/ |
| 90 | #if MGB_ENABLE_JSON |
| 91 | std::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 | |
| 129 | std::pair<VarNodeArray, VarNodeArray> GraphPartition::replace_graph_by_placeholder() |