Skip to content

Conversation

@junrushao
Copy link
Member

@junrushao junrushao commented Nov 11, 2022

Motivation example: in the current TVMScript, the snippet below:

@T.prim_func
def func(...):
    A = T.match_buffer[(128 * 128), "float32"]
                       ^^^^^^^^^^^

is actually different from this one:

@T.prim_func
def func(...):
    A = T.match_buffer[(16384, ), "float32"]
                       ^^^^^^^^^
    ...

This is because 128 * 128 is not immediately constant-folded into 16384, but becomes an AST node: T.Mul(128, 128). This can be quite error-prone if not used carefully.

As part of effort of more formal TIR semantics, we want to more explicitly differentiate TIR AST nodes (defined in tir/expr.h) and TIR ops (defined in tir/op.h). The naming convention is that:

  • Lowercased methods, for example, tvm.tir.mul or operator *, means an TIR op, which will be eagerly constant-folded, i.e. mul(1, 2) returns 3 immediately rather than creating an AST node.
  • Capitalized callable, for example, Mul, means creating an AST node without constant folding.

This PR makes this behavior more explictly by printing T.Mul(a, b) directly when a and b are both constants, rather than sugaring it into mul(a. b) or a * b, so that the difference between an op and an AST node is clarified.

Co-authored-by: Yaxing Cai <caiyaxing666@gmail.com>

As part of effort of more formal TIR semantics, we want to more
explicitly differentiate TIR AST nodes (defined in `tir/expr.h`)
and TIR ops (defined in `tir/op.h`).

A naming convention is that:
- Lowercased methods, for example, `tvm.tir.mul`, means an TIR op, which
  will be eagerly constant-folded, i.e. `mul(1, 2)` returns `3`
  immediately rather than creating an AST node.
- Capitalized callable, for example, `Mul`, means creating an AST node
  without constant folding.

This PR makes this behavior more explictly by printing `T.Mul(a, b)`
directly when `a` and `b` are both constants, rather than sugaring it
into `mul(a. b)` or `a * b`, so that the difference between an op and
an AST node is clarified.

Co-authored-by: Yaxing Cai <caiyaxing666@gmail.com>
@tvm-bot
Copy link
Collaborator

tvm-bot commented Nov 11, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@junrushao junrushao marked this pull request as ready for review November 11, 2022 01:50
Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Hzfengsy Hzfengsy merged commit ce0e9ab into apache:main Nov 11, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
As part of effort of more formal TIR semantics, we want to more
explicitly differentiate TIR AST nodes (defined in `tir/expr.h`)
and TIR ops (defined in `tir/op.h`).

A naming convention is that:
- Lowercased methods, for example, `tvm.tir.mul`, means an TIR op, which
  will be eagerly constant-folded, i.e. `mul(1, 2)` returns `3`
  immediately rather than creating an AST node.
- Capitalized callable, for example, `Mul`, means creating an AST node
  without constant folding.

This PR makes this behavior more explictly by printing `T.Mul(a, b)`
directly when `a` and `b` are both constants, rather than sugaring it
into `mul(a. b)` or `a * b`, so that the difference between an op and
an AST node is clarified.

Co-authored-by: Yaxing Cai <caiyaxing666@gmail.com>

Co-authored-by: Yaxing Cai <caiyaxing666@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants