Skip to content

[RFC] Lower Bound for Shape Variables #4487

Description

@yzhliu

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions