yzhliu opened a new issue #4487: [RFC] Lower Bound for Shape Variables
URL: https://github.com/apache/incubator-tvm/issues/4487
 
 
   ## 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](https://discuss.tvm.ai/t/significant-increase-in-the-amount-of-cuda-code-gen-after-migrating-indexdiv-mod-to-floordiv-mod/)
   
   * without knowing `tindex >= 0`:  
https://gist.github.com/yzhliu/f1aa7c1f25cfd8788cda75a350c4b274
   * knowing that `tindex >= 0`: 
https://gist.github.com/yzhliu/217e997157efcfc2a34e5c27b357fcaa
   
   ## Approach
   
   * Following [the 
disucss](https://discuss.tvm.ai/t/discuss-embed-more-bound-information-into-var-or-expr/),
 we would like to introduce `AssertLowerBound`, `tvm.placeholder` and 
`tvm.compute` inserts `assert_lower_bound(i, 0)` automatically.
   
   ```cpp
   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);
   };
   ```
   
   * `ConstIntBoundAnalyzer` will recognize `AssertLowerBound` and generate the 
Bound accordingly for the variables.
   * Modify `CodeGenC` and `CodeGenLLVM` to support `AssertLowerBound` - simply 
replace with its value. (Should we insert extra assertion instructions?)
   
   Here is a draft of the implement: 
https://github.com/apache/incubator-tvm/pull/4486
   
   @tqchen @icemelon9 @reminisce 
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to