Skip to content

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

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” 🤔

@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
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.

@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
@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