-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Labels
Description
Motivation
As we have replaced truncdiv/truncmod by floordiv/floormod in most places, there's a large demand for simplification to know the sign of the expression. For example, knowing the tensor shape bound can help reduce the if/else conditions significantly.
Here's an example of generated cuda code for the tvm program posted in this troubleshooting
- without knowing
tindex >= 0: https://gist.github.com/yzhliu/f1aa7c1f25cfd8788cda75a350c4b274 - knowing that
tindex >= 0: https://gist.github.com/yzhliu/217e997157efcfc2a34e5c27b357fcaa
Approach
- Following the disucss, we would like to introduce
AssertLowerBound,tvm.placeholderandtvm.computeinsertsassert_lower_bound(i, 0)automatically.
class AssertLowerBound : public ExprNode {
public:
Expr value;
Expr bound;
void VisitAttrs(AttrVisitor* v) {
v->Visit("value", &value);
v->Visit("bound", &bound);
}
TVM_DLL static Expr make(Expr value, Expr bound);
static constexpr const char* _type_key = "AssertLowerBound";
TVM_DECLARE_NODE_TYPE_INFO(AssertLowerBound, ExprNode);
};ConstIntBoundAnalyzerwill recognizeAssertLowerBoundand generate the Bound accordingly for the variables.- Modify
CodeGenCandCodeGenLLVMto supportAssertLowerBound- simply replace with its value. (Should we insert extra assertion instructions?)
Here is a draft of the implement: #4486
@tqchen @icemelon9 @reminisce