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

Method CPUDispatchChecker

src/plugin/impl/cpu_dispatch_checker.cpp:8–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using namespace mgb;
7
8CPUDispatchChecker::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
43void CPUDispatchChecker::record(CompNode cn) {
44 auto num = CompNodeEnv::from_comp_node(cn)

Callers

nothing calls this directly

Calls 4

emplace_backMethod · 0.80
checkFunction · 0.50
device_typeMethod · 0.45
dispatch_on_comp_nodeMethod · 0.45

Tested by

no test coverage detected