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

Function can_prove_imply

src/opr/impl/cond.cpp:15–49  ·  view source on GitHub ↗

return whether ``lhs -> rhs`` can be proved

Source from the content-addressed store, hash-verified

13
14//! return whether ``lhs -> rhs`` can be proved
15bool can_prove_imply(cg::ExecutionMask* lhs, cg::ExecutionMask* rhs) {
16 // this function is neither sound nor complete (and it can never be due
17 // to the NP-completeness of SAT); here we only handle the most common
18 // cases
19
20 if (rhs == lhs->parent()) {
21 // nested cond exec oprs
22 return true;
23 }
24
25 using Mode = CondExecPredLogical::Mode;
26 auto is_pred_logical = [](cg::OperatorNodeBase* opr, Mode mode) {
27 auto as_p = opr->try_cast_final<CondExecPredLogical>();
28 return as_p && as_p->param().mode == mode;
29 };
30
31 auto opr = rhs->owner()->owner_opr();
32
33 if (is_pred_logical(opr, Mode::AND) && opr->input().size() == 1) {
34 // cross-cn copy of predicate
35 opr = opr->input(0)->owner_opr();
36 }
37
38 if (is_pred_logical(opr, Mode::OR)) {
39 // in the grad of SUM_COND_OUT CondExecMerge
40 auto lvar = lhs->owner();
41 for (auto i : opr->input()) {
42 if (lvar == i) {
43 return true;
44 }
45 }
46 return false;
47 }
48 return false;
49}
50
51VarNode* proxy_var_from_mask(cg::ExecutionMask* mask) {
52 auto var = mask->owner();

Callers 1

on_new_oprMethod · 0.85

Calls 6

parentMethod · 0.45
paramMethod · 0.45
owner_oprMethod · 0.45
ownerMethod · 0.45
sizeMethod · 0.45
inputMethod · 0.45

Tested by

no test coverage detected