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

Method infer

src/core/impl/graph/static_infer_impl.cpp:383–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383const InpElement* StaticInferManagerImpl::TagTraitBase::infer(
384 bool recomp_mutable_srcnode, bool allow_fail) {
385 VarNode* cur_var = nullptr;
386 MGB_TRY {
387 auto ret = infer_withoutexc(&cur_var, recomp_mutable_srcnode);
388 if (!ret && !allow_fail) {
389 // find the first var that causes infer failure
390 cur_var = nullptr;
391 for (auto trait = this->as_mutable_safe();;) {
392 if (trait->deps().empty()) {
393 cur_var = trait->tag();
394 break;
395 }
396 mgb_assert(!trait->prev_infer_succeed());
397 bool found = false;
398 for (auto i : trait->deps()) {
399 auto imut = i->as_mutable();
400 if (imut && !imut->prev_infer_succeed()) {
401 found = true;
402 trait = imut;
403 break;
404 }
405 }
406 mgb_assert(found);
407 }
408 mgb_throw(
409 GraphError,
410 "failed to perform static inference for var%s\n"
411 "NOTE: this is caused by var%s",
412 cg::dump_var_info({tag()}).c_str(),
413 cg::dump_var_info({cur_var}).c_str());
414 }
415 return ret;
416 }
417 MGB_CATCH(MegBrainError & exc, {
418 if (!cur_var) {
419 cur_var = tag();

Callers 7

register_shape_inferMethod · 0.45
do_infer_shapeMethod · 0.45
do_infer_valueMethod · 0.45
updateMethod · 0.45
prepare_inp_valMethod · 0.45
updateMethod · 0.45

Calls 3

infer_withoutexcFunction · 0.85
emptyMethod · 0.45
tagMethod · 0.45

Tested by

no test coverage detected