| 6 | using namespace mgb; |
| 7 | |
| 8 | CPUDispatchChecker::CPUDispatchChecker(cg::ComputingGraph* graph) : PluginBase(graph) { |
| 9 | auto on_exec_start = [this](const cg::event::OprExecKernelStart& event) { |
| 10 | for (auto cn : cg::get_opr_comp_node_set(event.opr)) { |
| 11 | if (cn.device_type() == CompNode::DeviceType::CPU) { |
| 12 | auto callback = [this, cn]() { record(cn); }; |
| 13 | event.env->dispatch_on_comp_node(cn, callback); |
| 14 | } |
| 15 | } |
| 16 | }; |
| 17 | |
| 18 | auto on_exec_finish = [this](const cg::event::OprExecKernelEnd& event) { |
| 19 | for (auto cn : cg::get_opr_comp_node_set(event.opr)) { |
| 20 | if (cn.device_type() == CompNode::DeviceType::CPU) { |
| 21 | auto callback = [this, cn, opr = event.opr]() { check(cn, opr); }; |
| 22 | event.env->dispatch_on_comp_node(cn, callback); |
| 23 | } |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | auto on_subgraph_associated = [this](const cg::event::SubgraphAssociated& event) { |
| 28 | mgb_assert(event.par_graph == m_owner_graph); |
| 29 | auto sub = std::make_unique<CPUDispatchChecker>(event.sub_graph); |
| 30 | sub->m_failed_oprs = m_failed_oprs; |
| 31 | sub->m_failed_oprs_mtx = m_failed_oprs_mtx; |
| 32 | m_sub_graph_checkers.emplace_back(std::move(sub)); |
| 33 | }; |
| 34 | |
| 35 | add_event_handler(graph->event().register_receiver<cg::event::OprExecKernelStart>( |
| 36 | on_exec_start)); |
| 37 | add_event_handler(graph->event().register_receiver<cg::event::OprExecKernelEnd>( |
| 38 | on_exec_finish)); |
| 39 | add_event_handler(graph->event().register_receiver<cg::event::SubgraphAssociated>( |
| 40 | on_subgraph_associated)); |
| 41 | } |
| 42 | |
| 43 | void CPUDispatchChecker::record(CompNode cn) { |
| 44 | auto num = CompNodeEnv::from_comp_node(cn) |
nothing calls this directly
no test coverage detected