-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[TIR] Make compact buffer and get access region aware of conditions #9372
[TIR] Make compact buffer and get access region aware of conditions #9372
Conversation
Thanks, @wrongtest. Will review it tomorrow. |
14c8af1
to
74a1425
Compare
74a1425
to
57e17b4
Compare
Thanks @wrongtest in this case we might not rely on the difference(because the sets can be overly relaxed). Instead, we know that for this case the size won't go over the original size, so CompactBuffer should reall infer the bound and then intersect with the original allocated bound of B, which should still give us size of 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks @wrongtest again.
…pache#9372) * Support condition bound awareness in compact buffer and get block access region * remove intset difference usage * fix to visit match buffer's access region * change method to distinguish annotated opaque access regions
…pache#9372) * Support condition bound awareness in compact buffer and get block access region * remove intset difference usage * fix to visit match buffer's access region * change method to distinguish annotated opaque access regions
…pache#9372) * Support condition bound awareness in compact buffer and get block access region * remove intset difference usage * fix to visit match buffer's access region * change method to distinguish annotated opaque access regions
…pache#9372) * Support condition bound awareness in compact buffer and get block access region * remove intset difference usage * fix to visit match buffer's access region * change method to distinguish annotated opaque access regions
…pache#9372) * Support condition bound awareness in compact buffer and get block access region * remove intset difference usage * fix to visit match buffer's access region * change method to distinguish annotated opaque access regions
Hi there~ This PR aims to enhance the
CompactBufferRegion
andGetBlockAccessRegion
for conditional buffer accesses.Currently, they are not aware of conditions, thus may produce non-tight region bound. Take crop as an example:
The compact buffer pass would infer that the accessed region of B is B[-2:18] and re-allocate new buffer with size=18-(-2)=20, since it do not know B is only accessed if i in [2, 18).
To take conditions into consideration, the PR make several changes as described below:
Relax the buffer region just at the access point
If consider conditions, the domain map used to relax the buffer accesses is no longer uniform. Thus we can not simply collect all inner buffer accesses at block visit point and relax them all with
iter_dom_map_on_post_order_
.As a workaround, the PR instead record the allocation point (index into
ancestor_loops_
) for each buffer, thus at buffer access visit point, it can know which loop vars should not relax (generally loops out of allocation scope). The functionVisitBufferAccess()
do not need to record the access onto stack, but relax and union the access region immediately, with a global maintaineddom_map_
aware of condition bounds.iter_dom_map_on_post_order_
)dom_map_
, take extra cost to exclude non-relaxed loop vars from dom_map_) -> ... -> (3) visit block endImplement visit logic of
tir.IfThenElse
andtir.if_then_else()
call, and update var bounds deduced from condition in different branches.Implement intset difference util func. If the global intset is A and deduced intset is B on condition, then the bounded intset on true branch is
Intersect(A, B)
and the bounded intset on false branch isDifference(A, B)
.Clear read/write annotation for non-opaque block in pass
ConvertBlocksToOpaque
(maybe illness)ConvertBlocksToOpaque
is the pass beforeCompactBufferRegion
. Since block read/write annotations are non-conditional, the conditional access info will get lost when block with point access is converted.For a buffer allocated out of block scope, the compact buffer pass currently do not look into detailed access in block scope but use block's annotations, thus still try to relax B[i - 2] without condition awareness. The PR try to overcome this problem by differentiate two circumstances: