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

Method update_graph

src/jit/impl/fusion_pass.cpp:166–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166void JITFusionPass::Impl::update_graph() {
167 auto process = [this](OperatorNodeBase* opr) {
168 if (!Compiler::is_supported_device(opr->output(0)->comp_node().device_type()))
169 return;
170
171 auto fuse_varnode = [this](VarNode* var) {
172 auto ig_gen_iter = m_var2igraph_gen.find(var);
173 if (ig_gen_iter == m_var2igraph_gen.end()) {
174 return;
175 }
176 auto ig_gen = ig_gen_iter->second;
177 if (m_endpoint_set.count(var) != 0 && ig_gen->opr_set().size() >= 2) {
178 auto igraph = ig_gen->generate();
179 auto&& inputs = ig_gen->orig_inps();
180 if (m_after_grad || nr_non_const_vars(inputs) == 1) {
181 // in the forward pass, only fuse oprs with one non-const
182 // inp
183 VarNodeArray rewritten_inputs;
184 for (auto&& input : inputs) {
185 auto new_input = m_rewriter.get_var(input);
186 rewritten_inputs.push_back(new_input);
187 }
188 auto fusion_op = JITExecutor::make(igraph, rewritten_inputs);
189 m_rewriter.replace_var(
190 var, fusion_op.node(),
191 mgb_ssprintf_log(
192 "fuse endpoint: %s", var->owner_opr()->cname())
193 .c_str());
194 }
195 }
196 };
197
198 for (auto i : opr->input()) {
199 if (!m_rewriter.has_manual_replace(i)) {
200 // if input i is a endpoint, and number of oprs in this subgraph
201 // is greater than 2
202 m_opt_state.call_with_opr(i->owner_opr(), [&] { fuse_varnode(i); });
203 }
204 }
205 m_rewriter.auto_replace_outputs(opr);
206 if (m_opt_state.graph().endpoint_contain(opr->output(0))) {
207 // process final endpoint
208 fuse_varnode(opr->output(0));
209 }
210 };
211 m_opt_state.graph().iter(process);
212 m_rewriter.apply_inplace();
213}
214
215bool JITFusionPass::Impl::test_all_readers_in_the_graph(
216 VarNode* var, InternalGraphGenerator* ig_gen) {

Callers

nothing calls this directly

Calls 15

has_manual_replaceMethod · 0.80
call_with_oprMethod · 0.80
endpoint_containMethod · 0.80
apply_inplaceMethod · 0.80
makeFunction · 0.50
device_typeMethod · 0.45
comp_nodeMethod · 0.45
outputMethod · 0.45
findMethod · 0.45
endMethod · 0.45
countMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected