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] StmtFunctor RenewDefs #10843

Merged
merged 6 commits into from
Apr 21, 2022
Merged

[TIR] StmtFunctor RenewDefs #10843

merged 6 commits into from
Apr 21, 2022

Conversation

Hzfengsy
Copy link
Member

In this PR, I introduce a StmtFunctor ReGenerateDef for deep copy all definition nodes in PrimFunc (including Var, Buffer, and IterVar). This functor can create a new PrimFunc with the same behavior as the old one but contains different Nodes.

This Functor may help TIR fusion or inline multiple PrimFuncs

cc @tqchen @jinhongyii

@github-actions github-actions bot requested a review from tqchen March 31, 2022 08:12
@tqchen
Copy link
Member

tqchen commented Mar 31, 2022

cc @junrushao1994 @vinx13 @jinhongyii @MasterJH5574 please help to review

src/tir/transforms/regenerate_def.cc Outdated Show resolved Hide resolved
src/tir/transforms/regenerate_def.cc Outdated Show resolved Hide resolved
tests/python/unittest/test_tir_transform_regenerate_def.py Outdated Show resolved Hide resolved
Copy link
Contributor

@MasterJH5574 MasterJH5574 left a comment

Choose a reason for hiding this comment

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

“Regenerate” itself is already a word. So I suggest we using “RegenerateDef” instead of “ReGenerateDef” 🤔

In this PR, I introduce a StmtFunctor `RenewDefs` for deep copy all definition nodes in PrimFunc (including Var, Buffer, and IterVar). This functor can create a new PrimFunc with the same behavior as the old one but contains different Nodes.

This Functor may help TIR fusion or inline multiple PrimFuncs
@Hzfengsy
Copy link
Member Author

Hzfengsy commented Apr 2, 2022

Please take another look @tqchen @jinhongyii @junrushao1994 @MasterJH5574

@tqchen
Copy link
Member

tqchen commented Apr 2, 2022

Some additional ideas for possible regressions

Symbolic shape case that needs remap

Symbolic vars needs to be mapped to the same one

def fn(a: T.handle, b: T.handle, n: T.int32)
   m = T.var("int32")
   A =  match_buffer((n, m), a)
   B = match_bufer((n, m*2), b) 

Copy link
Member

@tqchen tqchen left a comment

Choose a reason for hiding this comment

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

Some high level comments, no correctness issue but would be good to add test coverage.

src/tir/transforms/renew_defs.cc Show resolved Hide resolved
@junrushao
Copy link
Member

Some additional ideas for possible regressions

Symbolic shape case that needs remap

Symbolic vars needs to be mapped to the same one

def fn(a: T.handle, b: T.handle, n: T.int32)
   m = T.var("int32")
   A =  match_buffer((n, m), a)
   B = match_bufer((n, m*2), b) 

Thanks for this interesting case!

As a further step, there might be usecases where buffers are declared as divisible by power-of-2, for example:

def fn(a: T.handle):
    m = T.var("int32")
    A = match_buffer(a, (m * 8, ), "float32")

@tqchen do you think this is a case we want to support?

@tqchen
Copy link
Member

tqchen commented Apr 3, 2022

@junrushao1994 what you are describing is not a case we support right now, but can be something we want to support in the future and indeed an useful case

@junrushao
Copy link
Member

Any updates?

@Hzfengsy Hzfengsy changed the title [TIR] StmtFunctor ReGenerateDef [TIR] StmtFunctor RenewDefs Apr 19, 2022
@Hzfengsy
Copy link
Member Author

@junrushao1994 @tqchen please take another look at it.
also cc @spectrometerHBH @wrongtest @jinhongyii @MasterJH5574

@vinx13 vinx13 merged commit 876e253 into apache:main Apr 21, 2022
shtinsa pushed a commit to Deelvin/tvm that referenced this pull request May 17, 2022
* [TIR] StmtFunctor RenewDefs

In this PR, I introduce a StmtFunctor `RenewDefs` for deep copy all definition nodes in PrimFunc (including Var, Buffer, and IterVar). This functor can create a new PrimFunc with the same behavior as the old one but contains different Nodes.

This Functor may help TIR fusion or inline multiple PrimFuncs

* add ut

* address comments

* address comments

* lint

* lint
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.

7 participants