-
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
[Bug] Meta Schedule Layout Rewrite Failure #12852
Comments
I can reproduce the error, and made a simplified test script below. Playing around a bit with the shape, it looks like it only occurs when there's a dimension of size 1. #!/usr/bin/env python3
import tvm
import tvm.testing
from tvm.script import tir as T
shape = tvm.testing.parameter(
(1, 1, 256, 512),
(1, 2, 256, 512),
(2, 1, 256, 512),
(2, 2, 256, 512),
)
def test_rewrite_layout(shape):
n, c, h, w = shape
@tvm.script.ir_module
class mod:
@T.prim_func
def main(a: T.handle):
A = T.match_buffer(a, shape, "float32")
T.func_attr({"layout_free_buffers": [0]})
for ax0, ax1, ax2, ax3 in T.grid(n, c, h, w):
with T.block():
v0, v1, v2, v3 = T.axis.remap("SSSS", [ax0, ax1, ax2, ax3])
T.evaluate(A[v0, v1, v2, v3])
sch = tvm.tir.Schedule(mod)
tvm.meta_schedule.postproc.RewriteLayout().apply(sch)
if __name__ == "__main__":
tvm.testing.main() |
It looks like the bug follows the steps below:
|
Ah, I think I found the better fix. There's some copy/paste between With this change, my test script now passes. // Unpack the map to an array, maintaining the same parameter order.
Array<PrimExpr> inverse_exprs;
for (int i = 0, n = (*this)->initial_indices.size(); i < n; ++i) {
Var index = (*this)->initial_indices[i];
if (is_one(initial_ranges[i]->extent) && !inverse_exprs_map.count(index)) {
inverse_exprs.push_back(initial_ranges[i]->min);
} else {
inverse_exprs.push_back(inverse_exprs_map.at(index));
}
} |
In general, https://github.com/apache/tvm/blob/main/include/tvm/tir/index_map.h#L83 Is there any chance we can use it in |
Here is another test case that prints out a bunch of
I tested it with the commit before #12720 and still got a bunch of errors. Not sure if it is related to this. |
In principle, this should have been handled by the check on the return value of
Possibly, though I think that's unrelated to the current bug. That said, I think its use will come along for free when merging the implementations of |
The two implementations were largely identical, and had implementations that drifted apart, resulting in bugs such as apache#12852. This commit removes this duplication by writing `Inverse` in terms of `NonSurjectiveInverse`. The merged version of `NonSurjectiveInverse` contains bugfix apache#11841, that were previously present only in `Inverse`.
@tkonolige I tested it, and had the same behavior. I was able to get better error messages by changing this line from |
This is indeed an orthogonal but serious problem. @tkonolige would you like to create a separate issue and bisect to determine which commit causes this bug? |
…2904) The two implementations were largely identical, and had implementations that drifted apart, resulting in bugs such as #12852. This commit removes this duplication by writing `Inverse` in terms of `NonSurjectiveInverse`. The merged version of `NonSurjectiveInverse` contains bugfix #11841, that were previously present only in `Inverse`.
Adds a regression test for using the `layout_rewrite` post-proc on a buffer with an extent of one in at least one dimension, issue apache#12852. This bug was resolved as part of the refactor in apache#12904, but didn't have a regression test at that point.
…12916) * [TIR][MetaSchedule] Add regression test for layout_rewrite extent=1 Adds a regression test for using the `layout_rewrite` post-proc on a buffer with an extent of one in at least one dimension, issue #12852. This bug was resolved as part of the refactor in #12904, but didn't have a regression test at that point. * Identified segfault and added test case
…ache#12904) The two implementations were largely identical, and had implementations that drifted apart, resulting in bugs such as apache#12852. This commit removes this duplication by writing `Inverse` in terms of `NonSurjectiveInverse`. The merged version of `NonSurjectiveInverse` contains bugfix apache#11841, that were previously present only in `Inverse`.
…pache#12916) * [TIR][MetaSchedule] Add regression test for layout_rewrite extent=1 Adds a regression test for using the `layout_rewrite` post-proc on a buffer with an extent of one in at least one dimension, issue apache#12852. This bug was resolved as part of the refactor in apache#12904, but didn't have a regression test at that point. * Identified segfault and added test case
The original issue has been fixed now. |
After #12720 the RewriteLayout postprocessor seems to fail during tuning. An example to reproduce is here https://gist.github.com/zxybazh/6bff29ae4e7cb273d57bb30599790008. And the failing message looks like:
CC @vinx13 @junrushao @Lunderberg
The text was updated successfully, but these errors were encountered: