Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Lower Bound for Shape Variables #4487

Closed
yzhliu opened this issue Dec 10, 2019 · 5 comments
Closed

[RFC] Lower Bound for Shape Variables #4487

yzhliu opened this issue Dec 10, 2019 · 5 comments

Comments

@yzhliu
Copy link
Member

yzhliu commented Dec 10, 2019

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

Approach

  • Following the disucss, we would like to introduce AssertLowerBound, tvm.placeholder and tvm.compute inserts assert_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);
};
  • 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: #4486

@tqchen @icemelon9 @reminisce

@tqchen
Copy link
Member

tqchen commented Dec 10, 2019

I am not sure if we want to introduce this specialized assertion as a special Expr. It might be a better idea to have it as an intrinsic

@tqchen
Copy link
Member

tqchen commented Dec 10, 2019

I am also thinking about pushing a parallel change to allow IterVar as a sub-class of Var. Note that it won't solve the problem of shape var bounds, but might also help some of the situations.

@icemelon
Copy link
Member

Yes, I agree we should have a general AssertExpr instead of AssertLowerBound, and put the asserted condition in the expr..

@yzhliu
Copy link
Member Author

yzhliu commented Dec 10, 2019

Thanks @tqchen @icemelon9 I'll change to use intrinsic and make it more general.

@tqchen tqchen closed this as completed Feb 8, 2020
@tqchen
Copy link
Member

tqchen commented Feb 8, 2020

#4684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants