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

[TIR][Schedule] Relax reorder primitive's affine binding check #10887

Merged

Conversation

wrongtest-intellif
Copy link
Contributor

Hi there, this pr aims to make some workload schedulable with reorder primitive. We can find a nice description for similar workloads in ethosu's cascade scheduler work: https://github.com/apache/tvm-rfcs/blob/main/rfcs/0037-arm-ethosu-cascading-scheduler.md.

https://github.com/apache/tvm-rfcs/raw/main/resources/cascading-diagram.png

Generally, if we have consecutive ops like conv and pooling, tiling the last one, and compute_at others under the outer loops, we then create cascade tiles simultaneously. The block binding for sub-blocks (except last) are not affine, since they have overlapped tile regions, due to non-trivial strides and window size.

Under current check, we can not reorder each sub-block's inner loops to perform subsequent optimizations, since a global affine binding is required. But note that if we fix outer loops, the block binding wrt inner loops generally keep affineness. The pr try to allow reorder in this situation.

The example script below builds two consecutive pooling op from te and schedule them with tir:

from tvm import topi
x = tvm.te.placeholder(shape=[1, 16, 112, 112], name="x")
y1 = topi.nn.pool2d(x, [3, 3], [1, 1], [1, 1], [0, 0, 0, 0], pool_type="max")
y2 = topi.nn.pool2d(y1, [3, 3], [1, 1], [1, 1], [0, 0, 0, 0], pool_type="max")
f = tvm.te.create_prim_func([x, y2])
s = tvm.tir.schedule.Schedule(f)
n, c, h, w, kh, kw = s.get_loops(s.get_block("tensor_1"))
ho, hi = s.split(h, factors=[None, 4])
s.compute_at(s.get_block("tensor"), ho)
v2, v3 = s.get_loops(s.get_block("tensor"))[-2:]
s.reorder(v2, v3)  # affine check failure!

@Hzfengsy
Copy link
Member

Hzfengsy commented Apr 3, 2022

cc @spectrometerHBH

@junrushao
Copy link
Member

@spectrometerHBH any updates?

@spectrometerHBH spectrometerHBH merged commit 00c830e into apache:main Apr 7, 2022
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Apr 11, 2022
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
qsqqsqqsq-intellif pushed a commit to qsqqsqqsq-intellif/tvm that referenced this pull request Apr 29, 2022
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