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

[Arith] Support integer BufferLoad in IntervalSetEvaluator #10327

Merged

Conversation

MasterJH5574
Copy link
Contributor

@MasterJH5574 MasterJH5574 commented Feb 20, 2022

This PR introduces the support of integer BufferLoadNodes in arith::IntervalSetEvaluator as well as a unittest.

Prior to this PR, the evaluator always return IntervalSet::Everything() (that is [-∞, +∞]) once it encounters a BufferLoad. However, as long as 1) the buffer data is of type integer and 2) the indices of the BufferLoad contain no variable that needs to be relaxed during evaluation, we can keep the BufferLoad as it is.

Besides, we're considering introducing assume_in_range for buffers for the use of range/region analysis. With assume_in_range, even when the indices of BufferLoad contain some variables to be relaxed, we can just return the asserted range, which is more compact, instead of the universe.

cc @yzh119 @Hzfengsy @spectrometerHBH @junrushao1994 @tqchen

T.reads(
A_indptr[i],
A_indptr[i + 1],
A_data[A_indptr[i] + 0 : A_indptr[i] + (A_indptr[i + 1] - A_indptr[i])],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
A_data[A_indptr[i] + 0 : A_indptr[i] + (A_indptr[i + 1] - A_indptr[i])],
A_data[A_indptr[i] : A_indptr[i + 1]],

Copy link
Contributor Author

@MasterJH5574 MasterJH5574 Feb 20, 2022

Choose a reason for hiding this comment

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

Due to some parser issue we're not allowed to simplify the expression for now:

error: Unsupported index type, expected int or tvm.tir.PrimExpr, but got <class 'tvm.script.tir.node.BufferSlice'>
 --> tensorir.py:431:44
     |  
 431 |              T.reads(A_indptr[vi : vi + 1], A_data[A_indptr[vi]: A_indptr[vi + 1]])
     |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
note: run with `TVM_BACKTRACE=1` environment variable to display a backtrace.

I suppose this is some bug that can be easily fixed, though I didn't get enough time to take a deeper look into the parser.

Copy link
Member

Choose a reason for hiding this comment

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

One problem with this analysis is that we cannot assume A_indptr[i+1] >= A_indptr[i].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I never thought of this before. Is it okay by specifying assume_in_range(A_indptr[i + 1] - A_indptr[i], [0, 127]) in the future? (not pretty sure)

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think so, but we merge this one first.

@MasterJH5574 MasterJH5574 force-pushed the feature/2022-02-20-evaluator-buffferload branch from 97c8d56 to 4fe1bb4 Compare February 21, 2022 00:38
@Hzfengsy Hzfengsy merged commit d65ff65 into apache:main Feb 21, 2022
junrushao pushed a commit that referenced this pull request Feb 25, 2022
…nge/loop start and end (#10370)

A quick fix of the parser issue mentioned in #10327 .
Ranges and loops require `start` and `stop` to be PrimExpr, however, `BufferSlice` is not always scalar so it's not a `PrimExpr`.
This PR performs the transformation.
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
)

* Deal with BufferLoad

* Test for BufferLoad

* Fix comments and CI
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
…nge/loop start and end (apache#10370)

A quick fix of the parser issue mentioned in apache#10327 .
Ranges and loops require `start` and `stop` to be PrimExpr, however, `BufferSlice` is not always scalar so it's not a `PrimExpr`.
This PR performs the transformation.
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.

4 participants