-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[SCHEDULE] New Reduction Mode for Tensorize #727
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e386176
when there is no intrin func, using body for initialization. For issu…
kun-zh 1151fd6
Merge branch 'master' into master
kun-zh 784a0fd
Refine code per review comments, and add a test case.
kun-zh 5bbc941
Merge branch 'master' of https://github.com/kun-zh/tvm
kun-zh ab49e9f
Fix lint issues.
kun-zh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/python/unittest/test_schedule_tensorize_init_none.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import tvm | ||
|
||
def intrin_gemv(m, n): | ||
w = tvm.placeholder((m, n), name='w') | ||
x = tvm.placeholder((n,), name='x') | ||
k = tvm.reduce_axis((0, n), name='k') | ||
z = tvm.compute((m,), lambda i: | ||
tvm.sum(w[i, k] * x[k], axis=k), name='z') | ||
Wb = tvm.decl_buffer(w.shape, w.dtype, | ||
name="W", | ||
offset_factor=16, | ||
strides=[tvm.var('ldw'), 1]) | ||
def intrin_func(ins, outs): | ||
ww, xx = ins | ||
zz = outs[0] | ||
ww_ptr = ww.access_ptr("r") | ||
xx_ptr = xx.access_ptr("r") | ||
zz_ptr = zz.access_ptr("w") | ||
body = tvm.call_packed( | ||
"gemv", ww_ptr, xx_ptr, zz_ptr, n, ww.strides[0]) | ||
update = tvm.call_packed( | ||
"gemv_add", ww_ptr, xx_ptr, zz_ptr, n, ww.strides[0]) | ||
return body, None, update | ||
|
||
with tvm.build_config(data_alignment=16, | ||
offset_factor=16): | ||
return tvm.decl_tensor_intrin(z.op, intrin_func, | ||
binds={w: Wb}) | ||
|
||
|
||
def test_tensorize_matmul(): | ||
n = 1024 | ||
m = n | ||
l = n | ||
A = tvm.placeholder((n, l), name='A') | ||
B = tvm.placeholder((m, l), name='B') | ||
k = tvm.reduce_axis((0, l), name='k') | ||
C = tvm.compute((n, m), lambda i, j: | ||
tvm.sum(B[j, k] * A[i, k], axis=k), name='C') | ||
|
||
def check(factor): | ||
s = tvm.create_schedule(C.op) | ||
x, y = C.op.axis | ||
yo, yi = s[C].split(y, factor=factor) | ||
gemv = intrin_gemv(factor, l) | ||
s[C].tensorize(yi, gemv) | ||
s = s.normalize() | ||
dom_map = tvm.schedule.InferBound(s) | ||
finfer = tvm.get_global_func("test.op.InferTensorizeRegion") | ||
out_dom, in_dom = finfer(s[C], dom_map) | ||
assert tvm.ir_pass.Equal(out_dom[x].extent, 1) | ||
assert tvm.ir_pass.Equal(out_dom[y].extent, factor) | ||
assert tvm.ir_pass.Equal(out_dom[y].min, yo * factor) | ||
fmatch = tvm.get_global_func("test.op.MatchTensorizeBody") | ||
body = fmatch(s[C], out_dom, in_dom, gemv) | ||
assert tvm.ir_pass.Equal(tvm.ir_pass.CanonicalSimplify(body[0]), | ||
tvm.ir_pass.CanonicalSimplify(gemv.op.body[0])) | ||
stmt = tvm.schedule.ScheduleOps(s, dom_map) | ||
tvm.lower(s, [A, B, C]) | ||
|
||
|
||
def check_rfactor(factor, rfactor): | ||
s = tvm.create_schedule(C.op) | ||
x, y = C.op.axis | ||
rk = C.op.reduce_axis[0] | ||
yo, yi = s[C].split(y, factor=factor) | ||
ro, ri = s[C].split(rk, factor=rfactor) | ||
s[C].reorder(yo, ro, yi, ri) | ||
gemv = intrin_gemv(factor, rfactor) | ||
s[C].tensorize(yi, gemv) | ||
s = s.normalize() | ||
dom_map = tvm.schedule.InferBound(s) | ||
finfer = tvm.get_global_func("test.op.InferTensorizeRegion") | ||
out_dom, in_dom = finfer(s[C], dom_map) | ||
assert tvm.ir_pass.Equal(out_dom[x].extent, 1) | ||
assert tvm.ir_pass.Equal(out_dom[y].extent, factor) | ||
assert tvm.ir_pass.Equal(out_dom[y].min, yo * factor) | ||
fmatch = tvm.get_global_func("test.op.MatchTensorizeBody") | ||
body = fmatch(s[C], out_dom, in_dom, gemv) | ||
assert tvm.ir_pass.Equal(tvm.ir_pass.CanonicalSimplify(body[0]), | ||
tvm.ir_pass.CanonicalSimplify(gemv.op.body[0])) | ||
stmt = tvm.schedule.ScheduleOps(s, dom_map) | ||
tvm.lower(s, [A, B, C]) | ||
|
||
check(16) | ||
check_rfactor(16, 16) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_tensorize_matmul() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
move this to test_schedule_tensorize.py We can use different function name