| 28 | } |
| 29 | |
| 30 | InternalGraphPtr 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 |
no test coverage detected