-
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] Affine utility support iter lowerbound and diagnostics #9699
[TIR] Affine utility support iter lowerbound and diagnostics #9699
Conversation
1ef2e7d
to
1b1852e
Compare
Ping @spectrometerHBH |
Here are some comments.
BTW, the case shown in your description is not the same as the case you added in the testcase. I thought you'd like to support the binding after #9527, so you may want to modify the test case, IIUC? |
Many thanks to your comments!
Yes, I found that is the case. It should be my mistake on reason of failed cases.
Previous trials for me seems it require
I will change the testcase to match #9527, |
e642a84
to
21ccbf8
Compare
Hi~ @spectrometerHBH Could you kindly take another round of review for lowerbound feature? |
# h3 == 0: region is [1, 9] | ||
# 0 < h3 <= 26: region is [h3 * 8, h3 * 8 + 9] | ||
# h3 > 26: region is [h3 * 8, 223] | ||
do_test_point_access( |
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.
Would be great if we can add 3 more test cases for each case of h3 :)
src/arith/iter_affine_map.cc
Outdated
// Then, flattened form = IterSum(IterSplit(i, scale=9), | ||
// IterSplit(j, scale=2), | ||
// IterSplit(k, scale=1)) | ||
// normal form = IterSum(IterSplit(i, scale=9), |
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.
I don't think it's a good idea to rewrite i*9 + j*2 + k
into such a normal form (i*9 + (j*2 + k - 1) + 1)
.
The reason is that j*2 + k - 1
has extent 8, it's weird that the scale of i is 9. Actually i*9 + j*2 + k
with predicate 1 <= j*2 + k < 9
doesn't correspond to an iter, since the value of it is not continuous. Its value is [1, 8] \union [10, 17] \union [19, 26], ...
.
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.
cc @wrongtest
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.
What if we change this example to i*8 + j*2 + k
, j*2 + k >= 1
?
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.
Then it looks good to me.
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.
Then I think you might need to add more test cases to test the sanity.
Such as what if we try to fuse several iters all with lower bound constraints, and what if we split an iter with lower bound constraint.
BTW, I notice that negative scale is possble #9776, would we add some cases like |
Try to add these test cases, which I think might be helpful to test the sanity.
These all should be detected successfully (I think). Correct me if anything wrong :) |
…e constraints on iter
7ea21ef
to
79b7277
Compare
Rebase, add more testcases and try to fix three detected issues:
res = tvm.arith.detect_iter_map([i], var_dom([(i, 48)]), tvm.tir.all(i < 10))
assert_iter_sum_pattern(res[0], 10, 0)
res = tvm.arith.detect_iter_map(
[i, j, k],
var_dom([(i, 128), (j, 128), (k, 128)]),
tvm.tir.all(i * 16384 + j * 128 + k < 100),
) The workaround currently is that if we fail to fully match the predicate constraint, but a suffix of predicate is matched successfully, step into fallback behaviors and skip this constraint. For example, if target iter expr is Unfortunately, the originated |
For region cover problem, there are two notes:
|
Would be great if you can fix the CI :) |
src/arith/iter_affine_map.cc
Outdated
if (i == 0 && num_visited == visited.size()) { | ||
// if match failed because of iterations are used out instead of scale mismatch, | ||
// and all used iters are visited during current match round, fallback to skip the | ||
// constraint. Example: exprs = [i * 2 + j, k], i in [0, 3), j in [0, 2), k in [0, 4) |
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.
I think we should fail on such a case since there exists an unexpected predicate.
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.
cc @wrongtest
Would you mind providing the produce^buffer_shape and consume^buffer_shape calculated by the region cover check? That would be a great help. |
fd18d84
to
d71bd24
Compare
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.
Can be merged if we fail on the predicate unmatch problem.
Thanks a lot @wrongtest and @spectrometerHBH |
…9699) * Enable freevars, iter lowerbound and diagnostics in affine utility * fix lint issues and compare bug * update to use iter shift instead of itermark min for lowerbound * add testcase of fused iters sum with multiple lowerbounds * add more affine check testcases, fix bug for single iter and duplicate constraints on iter * add a newline to comment * forbidden predicate unmatch Co-authored-by: baoxinqi <[email protected]>
…9699) * Enable freevars, iter lowerbound and diagnostics in affine utility * fix lint issues and compare bug * update to use iter shift instead of itermark min for lowerbound * add testcase of fused iters sum with multiple lowerbounds * add more affine check testcases, fix bug for single iter and duplicate constraints on iter * add a newline to comment * forbidden predicate unmatch Co-authored-by: baoxinqi <[email protected]>
Hi, there. The PR originate from the issue detected in #9527, where a tiled block with both lowerbound and upperbound predicates fail to infer the
region_cover
property. Some tracing show that theDetectIterMap
fail on such cases.The PR modify affine utility in aspects below :
Free vars
For
DetectIterMap
, if the expression do not contain vars in domain map, it should be safe to not analyze affine form into it. eg,x*x + 8y + z
could pass affine analysis ifx
is not an var of iter domains. We can just putx*x
into base part of IterSumExpr. It benefit the above case sincehh_0 * 8 + ax0
is not an affine form, but outer var might be free in certain analysis procedures.Add
min
field toIterMark
classIt is zero almost all time. But when lowerbound predicate exists, it seems much hard to represent the lowerbound with only source and extent.
More flexible predicate support
Support resolve all kinds of >, >=, <, <= integer comparisions, for the expr of form like
i * 8 < 10 - j
, try refactor the expr into domain var related part and domain var free parts.Introduce
DiagnosticContext
for debug purposeReplace each fail point (
++unresolved_cnt_
) with an error message recorded into diagnostic context. Or else it would be too hard to detect what happend for beginners. However, I do not find a proper point to callRender()
of diagnostics for now.