-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Bugfix][TIR] Fix duplicate AllocateConst in CacheReadWrite schedule primitive #16660
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
Conversation
Lunderberg
left a comment
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.
Looks good, and thank you for the fix!
Long-term, we may want to avoid this class of bugs by changing the const Stmt& stmt argument of InsertCacheState to Stmt body. This would avoid having two almost-but-not-quite identical variables within the same scope.
tests/python/tir-schedule/test_tir_schedule_cache_read_write.py
Outdated
Show resolved
Hide resolved
Prior to this commit, the automatic `T.reads()` and `T.writes()` annotations were only generated for buffers appearing as function arguments, as `T.alloc_buffer` in a `T.block`, or as `T.match_buffer` in a `T.block`. However, inferred `T.reads()` for a buffer defined by the `"tir.BindParams"` pass would be erroneously missing. These annotations may be required for correct scheduling (see discussion in [PR#16660](apache#16660)). This commit updates the TVMScript parsing to infer `T.reads()` and `T.writes()` annotations for buffers defined with `DeclBuffer` nodes.
Prior to this commit, the automatic `T.reads()` and `T.writes()` annotations were only generated for buffers appearing as function arguments, as `T.alloc_buffer` in a `T.block`, or as `T.match_buffer` in a `T.block`. However, inferred `T.reads()` for a buffer defined by the `"tir.BindParams"` pass would be erroneously missing. These annotations may be required for correct scheduling (see discussion in [PR#16660](apache#16660)). This commit updates the TVMScript parsing to infer `T.reads()` and `T.writes()` annotations for buffers defined with `DeclBuffer` nodes.
|
@tvm-bot rerun |
Prior to this commit, the automatic `T.reads()` and `T.writes()` annotations were only generated for buffers appearing as function arguments, as `T.alloc_buffer` in a `T.block`, or as `T.match_buffer` in a `T.block`. However, inferred `T.reads()` for a buffer defined by the `"tir.BindParams"` pass would be erroneously missing. These annotations may be required for correct scheduling (see discussion in [PR#16660](#16660)). This commit updates the TVMScript parsing to infer `T.reads()` and `T.writes()` annotations for buffers defined with `DeclBuffer` nodes.
lhutton1
left a comment
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.
Thanks @Anndrey24, LGTM. Since #16663 was merged would you prefer to address the comment here or address in a follow up?
…primitive When inserting a `cache_read` / `cache_write` stage, the `tir.AllocateConst` statement would be duplicated if its body was not a `tir.SeqStmt` node (e.g. `tir.For`), leading to compilation failures. This happened because `tir.AllocateConst` and `tir.DeclBuffer` statements are always re-attached to the statement's body after the `cache_read` / `cache_write` stage is inserted in it, but the stage was being appended to the whole statement (which already contains the `tir.AllocateConst`) and not just its body, causing duplications. This commit also adds a test where the first `cache_read` stage is inserted into a statement whose body is a `tir.For`, while the second stage is added to a body that is `tir.SeqStmt` to check for regressions.
f65e24d to
7031fd5
Compare
|
Oops, I hadn't noticed the fix was already merged. I've also removed the |
|
@tvm-bot rerun |
1 similar comment
|
@tvm-bot rerun |
|
Thanks @Anndrey24 @Lunderberg! |
Prior to this commit, the automatic `T.reads()` and `T.writes()` annotations were only generated for buffers appearing as function arguments, as `T.alloc_buffer` in a `T.block`, or as `T.match_buffer` in a `T.block`. However, inferred `T.reads()` for a buffer defined by the `"tir.BindParams"` pass would be erroneously missing. These annotations may be required for correct scheduling (see discussion in [PR#16660](apache#16660)). This commit updates the TVMScript parsing to infer `T.reads()` and `T.writes()` annotations for buffers defined with `DeclBuffer` nodes.
…primitive (apache#16660) * [Bugfix][TIR] Fix duplicate AllocateConst in CacheReadWrite schedule primitive When inserting a `cache_read` / `cache_write` stage, the `tir.AllocateConst` statement would be duplicated if its body was not a `tir.SeqStmt` node (e.g. `tir.For`), leading to compilation failures. This happened because `tir.AllocateConst` and `tir.DeclBuffer` statements are always re-attached to the statement's body after the `cache_read` / `cache_write` stage is inserted in it, but the stage was being appended to the whole statement (which already contains the `tir.AllocateConst`) and not just its body, causing duplications. This commit also adds a test where the first `cache_read` stage is inserted into a statement whose body is a `tir.For`, while the second stage is added to a body that is `tir.SeqStmt` to check for regressions. * Improve PrimFunc readability * Remove redundant `T.reads()`
Prior to this commit, the automatic `T.reads()` and `T.writes()` annotations were only generated for buffers appearing as function arguments, as `T.alloc_buffer` in a `T.block`, or as `T.match_buffer` in a `T.block`. However, inferred `T.reads()` for a buffer defined by the `"tir.BindParams"` pass would be erroneously missing. These annotations may be required for correct scheduling (see discussion in [PR#16660](apache#16660)). This commit updates the TVMScript parsing to infer `T.reads()` and `T.writes()` annotations for buffers defined with `DeclBuffer` nodes.
…primitive (apache#16660) * [Bugfix][TIR] Fix duplicate AllocateConst in CacheReadWrite schedule primitive When inserting a `cache_read` / `cache_write` stage, the `tir.AllocateConst` statement would be duplicated if its body was not a `tir.SeqStmt` node (e.g. `tir.For`), leading to compilation failures. This happened because `tir.AllocateConst` and `tir.DeclBuffer` statements are always re-attached to the statement's body after the `cache_read` / `cache_write` stage is inserted in it, but the stage was being appended to the whole statement (which already contains the `tir.AllocateConst`) and not just its body, causing duplications. This commit also adds a test where the first `cache_read` stage is inserted into a statement whose body is a `tir.For`, while the second stage is added to a body that is `tir.SeqStmt` to check for regressions. * Improve PrimFunc readability * Remove redundant `T.reads()`
When inserting a
cache_read/cache_writestage, thetir.AllocateConststatement would be duplicated if its body was not atir.SeqStmtnode (e.g.tir.For), leading to compilation failures. This happened becausetir.AllocateConstandtir.DeclBufferstatements are always re-attached to the statement's body after thecache_read/cache_writestage is inserted in it, but the stage was being appended to the whole statement (which already contains thetir.AllocateConst) and not just its body, causing duplications.This commit also adds a test where the first
cache_readstage is inserted into a statement whose body is atir.For, while the second stage is added to a body that istir.SeqStmtto check for regressions.cc @Lunderberg @ekalda @lhutton1