Skip to content

[TIR][TVMScript] specialize#8354

Merged
tqchen merged 4 commits intoapache:mainfrom
Hzfengsy:specialize
Jul 1, 2021
Merged

[TIR][TVMScript] specialize#8354
tqchen merged 4 commits intoapache:mainfrom
Hzfengsy:specialize

Conversation

@Hzfengsy
Copy link
Copy Markdown
Member

This PR enables meta_programming for TVM Functions (usually used for TVMScript), which is useful to define only one function(TVMScript) but used in different shapes.

Example:
Mate fucntion

@tvm.script.tir
def mem_copy(a: ty.handle, b: ty.handle, m: ty.int32, n: ty.int32) -> None:
    A = tir.match_buffer(a, (m, n), "float32")
    B = tir.match_buffer(b, (m, n), "float32")

    with tir.block([m, n], "") as [vi, vj]:
        B[vi, vj] = A[vi, vj]

Instruction:

a, _, m, n = mem_copy.params
func = mem_copy.specialize({a: tir.decl_buffer((16, 16))})
# or
func = mem_copy.specialize({n: 16, m: 16})

Specialized function:

@tvm.script.tir
def mem_copy_16_16(a: ty.handle, b: ty.handle) -> None:
    A = tir.match_buffer(a, (16, 16), "float32")
    B = tir.match_buffer(b, (16, 16), "float32")

    with tir.block([16, 16], "") as [vi, vj]:
        B[vi, vj] = A[vi, vj]

cc @tqchen @junrushao1994 @MasterJH5574 @comaniac

Comment thread python/tvm/tir/function.py
Copy link
Copy Markdown
Contributor

@jcf94 jcf94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Comment thread src/tir/ir/specialize.cc
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread tests/python/unittest/test_tvmscript_meta_programming.py
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc
@tqchen
Copy link
Copy Markdown
Member

tqchen commented Jun 28, 2021

cc @vinx13 @junrushao1994 please help to take a look

Comment thread src/tir/ir/specialize.cc Outdated
Copy link
Copy Markdown
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic LGTM. One miner point: is it possible to work on param_map directly instead of one-by-one? Specifically, can we build var mapping in Specialize with several parameters so that we can run PrimFuncSpecializer::Specialize just once and make the time complexity decouple to the parameter number?

@Hzfengsy
Copy link
Copy Markdown
Member Author

Thanks, @comaniac. Just have fixed it

Comment thread src/tir/ir/specialize.cc Outdated
Comment thread src/tir/ir/specialize.cc
Comment thread tests/python/unittest/test_tvmscript_meta_programming.py
@tqchen tqchen merged commit 29e958d into apache:main Jul 1, 2021
Comment on lines +189 to +191
def test_specialize_recursive_load():
# TODO(Siyuan): add recursive Load testcase, e.g. A[C[i]]
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this TODO item today. Is it intended to leave the TODO here? Or it was because we forgot to write the unittest?

@Hzfengsy Hzfengsy deleted the specialize branch August 2, 2021 04:38
ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
zxy844288792 pushed a commit to zxy844288792/tvm that referenced this pull request Mar 4, 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.

5 participants