Skip to content

[TIR] StmtFunctor RenewDefs#10843

Merged
vinx13 merged 6 commits intoapache:mainfrom
Hzfengsy:regenerate-def-tir
Apr 21, 2022
Merged

[TIR] StmtFunctor RenewDefs#10843
vinx13 merged 6 commits intoapache:mainfrom
Hzfengsy:regenerate-def-tir

Conversation

@Hzfengsy
Copy link
Copy Markdown
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
Copy Markdown
Member

tqchen commented Mar 31, 2022

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

Comment thread include/tvm/tir/stmt_functor.h Outdated
Comment thread tests/python/unittest/test_tir_transform_regenerate_def.py Outdated
Comment thread tests/python/unittest/test_tir_transform_regenerate_def.py Outdated
Comment thread tests/python/unittest/test_tir_transform_regenerate_def.py Outdated
Comment thread src/tir/transforms/regenerate_def.cc Outdated
Comment thread src/tir/transforms/regenerate_def.cc Outdated
Comment thread tests/python/unittest/test_tir_transform_regenerate_def.py Outdated
Comment thread python/tvm/tir/stmt_functor.py Outdated
Copy link
Copy Markdown
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” 🤔

Comment thread include/tvm/tir/stmt_functor.h Outdated
@Hzfengsy Hzfengsy force-pushed the regenerate-def-tir branch from 7d0e66a to 9e03820 Compare April 2, 2022 11:24
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 Hzfengsy force-pushed the regenerate-def-tir branch from 9e03820 to 445d36e Compare April 2, 2022 11:39
@Hzfengsy
Copy link
Copy Markdown
Member Author

Hzfengsy commented Apr 2, 2022

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

Comment thread src/tir/transforms/renew_defs.cc
Comment thread tests/python/unittest/test_tir_renew_defs.py
Comment thread tests/python/unittest/test_tir_renew_defs.py
@tqchen
Copy link
Copy Markdown
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) 

Comment thread include/tvm/tir/stmt_functor.h Outdated
Comment thread src/tir/transforms/renew_defs.cc Outdated
Copy link
Copy Markdown
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.

Comment thread src/tir/transforms/renew_defs.cc
@junrushao
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Any updates?

@Hzfengsy Hzfengsy changed the title [TIR] StmtFunctor ReGenerateDef [TIR] StmtFunctor RenewDefs Apr 19, 2022
@Hzfengsy
Copy link
Copy Markdown
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
@Hzfengsy Hzfengsy deleted the regenerate-def-tir branch June 17, 2025 13:16
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