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

Method add_opr

src/gopt/impl/framework.cpp:861–924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

859/* ================ ConstVarPropogateBase ================ */
860
861ConstVarPropogate::AddOprResult ConstVarPropogate::add_opr(OperatorNodeBase* opr) {
862 using ProfFlag = OperatorNodeBase::NodeProp::Flag;
863 auto&& info = m_oprinfo[opr];
864 if (info.processed)
865 return info.result;
866 info.processed = true;
867
868#if MGB_ENABLE_JSON
869 (*opr->to_json_extra_json)["gopt::cvprop"] = json::Bool::make(false);
870#endif
871
872 AddOprResult ret{false, false, false};
873 auto make_ret = [&ret, &info]() {
874 info.result = ret;
875 return ret;
876 };
877
878 if (is_const_var(m_const_var_type, opr)) {
879 auto sz = var_mem_size(opr->output(0));
880 mgb_assert(
881 sz || opr->output(0)->contain_flag(VarNode::Flag::ALLOW_EMPTY_SHAPE));
882 info.is_const = true;
883 info.max_size = sz;
884 return make_ret();
885 }
886
887 if (opr->input().empty())
888 return make_ret();
889
890 if (opr->node_prop().contain(
891 ProfFlag::FORCE_UPDATE_INPUT_VAR | ProfFlag::IMPURE_FUNC)) {
892 return make_ret();
893 }
894
895 size_t max_input_size = 0;
896 ret.all_const_inp = true;
897 for (auto i : opr->input()) {
898 auto io = i->owner_opr();
899 auto iter = m_oprinfo.find(io);
900 if (iter == m_oprinfo.end()) {
901 add_opr(io);
902 iter = m_oprinfo.find(io);
903 mgb_assert(iter != m_oprinfo.end());
904 }
905 auto&& src = iter->second;
906 if (src.is_const) {
907 update_max(max_input_size, src.max_size);
908 ret.has_const_inp = true;
909 if (!is_const_var(m_const_var_type, i->owner_opr())) {
910 ret.has_midconst_inp = true;
911 }
912 } else {
913 ret.all_const_inp = false;
914 }
915 }
916 if (ret.all_const_inp) {
917#if MGB_ENABLE_JSON
918 (*opr->to_json_extra_json)["gopt::cvprop"] = json::Bool::make(true);

Callers 7

detect_replaceMethod · 0.45
ImplMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
profileMethod · 0.45
on_opr_visitedMethod · 0.45

Calls 11

is_const_varFunction · 0.85
update_maxFunction · 0.85
makeFunction · 0.50
outputMethod · 0.45
contain_flagMethod · 0.45
emptyMethod · 0.45
inputMethod · 0.45
containMethod · 0.45
owner_oprMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected