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

Function expand_executor_opr

src/jit/impl/internal_graph.cpp:30–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30InternalGraphPtr expand_executor_opr(const InternalGraphPtr& prev_igraph) {
31 bool has_jit_executor = false;
32 SymbolVarArray endpoints{SymbolVar{prev_igraph->output()}};
33 SubGraph sub_graph{endpoints};
34 SubGraph::Rewriter rewriter{&sub_graph};
35
36 auto on_opr = [&](OperatorNodeBase* opr) {
37 if (auto jit_exctor = try_cast_as_op<JITExecutor>(opr)) {
38 has_jit_executor = true;
39 auto& igraph = jit_exctor->internal_graph();
40 mgb_assert(igraph.output());
41
42 ThinHashMap<VarNode*, VarNode*> old2new;
43 for (size_t i = 0; i < opr->input().size(); ++i) {
44 auto inp = rewriter.get_var(opr->input(i));
45 auto ph = igraph.placeholders().at(i)->output(0);
46 auto iter = old2new.emplace(ph, inp);
47 if (!iter.second) {
48 mgb_assert(iter.first->second == inp);
49 }
50 }
51 recursive_replace(old2new, igraph.output()->owner_opr());
52
53 rewriter.replace_var(
54 opr->output(0), old2new[igraph.output()],
55 mgb_cstr_log("update internal graph"));
56 } else {
57 rewriter.auto_replace_outputs(opr);
58 }
59 };
60 sub_graph.iter(on_opr);
61 if (!has_jit_executor)
62 return prev_igraph;
63 rewriter.apply_inplace();
64
65 return std::make_shared<InternalGraph>(
66 rewriter.get_var(prev_igraph->output()),
67 rewriter.get_var(prev_igraph->shape_infer()),
68 rewriter.get_var(prev_igraph->value_infer()), prev_igraph->placeholders());
69}
70
71} // namespace
72

Callers 1

generateMethod · 0.85

Calls 14

recursive_replaceFunction · 0.85
apply_inplaceMethod · 0.80
shape_inferMethod · 0.80
value_inferMethod · 0.80
outputMethod · 0.45
sizeMethod · 0.45
inputMethod · 0.45
get_varMethod · 0.45
atMethod · 0.45
emplaceMethod · 0.45
owner_oprMethod · 0.45
replace_varMethod · 0.45

Tested by

no test coverage detected