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

Method process_chain

src/gopt/impl/basic_arith/chain.cpp:679–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

677}
678
679void ReorderArithChainPass::Impl::process_chain(VarNode* endpoint, Mode mode) {
680 if (m_cvprop.is_const(endpoint))
681 return;
682
683 auto vars = extract_chain_terms(endpoint, mode);
684 if (vars.size() == 1)
685 return;
686
687 // to ensure the same set of input terms get the same reduced var
688 // TODO: consider maintain a cache(map) of (sorted input terms -> reduced var)
689 std::sort(vars.begin(), vars.end(), [](VarNode* x, VarNode* y) {
690 return x->id() < y->id();
691 });
692 m_shp2terms.clear();
693 for (auto i : vars) {
694 auto inew = m_rewriter.get_var(i);
695 m_shp2terms[i->shape()][m_cvprop.is_const(i)].push_back(inew);
696 }
697
698 auto sum = reduce_shp2terms(mode);
699
700 if (m_rewriter.get_var(endpoint) != sum) {
701 m_rewriter.replace_var(
702 endpoint, sum,
703 mgb_ssprintf_log(
704 "reorder %zu %s terms", vars.size(),
705 megdnn::Elemwise::ModeTrait::from_mode(mode).name)
706 .c_str());
707 }
708}
709
710const char* ReorderArithChainPass::name() const {
711 return mgb_cstr_log("reorder_arith_chain");

Callers 1

on_oprMethod · 0.80

Calls 15

sortFunction · 0.85
as_elem_oprFunction · 0.85
swapFunction · 0.85
is_constMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
idMethod · 0.45
clearMethod · 0.45
get_varMethod · 0.45
push_backMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected