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][TVMScript] specialize #8354

Merged
merged 4 commits into from
Jul 1, 2021
Merged

[TIR][TVMScript] specialize #8354

merged 4 commits into from
Jul 1, 2021

Conversation

Hzfengsy
Copy link
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

Copy link
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!

src/tir/ir/specialize.cc Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
tests/python/unittest/test_tvmscript_meta_programming.py Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Jun 28, 2021

cc @vinx13 @junrushao1994 please help to take a look

src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
Copy link
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
Member Author

Thanks, @comaniac. Just have fixed it

src/tir/ir/specialize.cc Outdated Show resolved Hide resolved
src/tir/ir/specialize.cc Show resolved Hide resolved
tests/python/unittest/test_tvmscript_meta_programming.py Outdated Show resolved Hide resolved
@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
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