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

[Unity] Introduce call_dps_packed #14183

Merged
merged 7 commits into from
Mar 10, 2023
Merged

Conversation

yongwww
Copy link
Member

@yongwww yongwww commented Mar 3, 2023

Introduce call_dps_packed to call packed function instead tir via destination passing convention

@tvm-bot
Copy link
Collaborator

tvm-bot commented Mar 3, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@yongwww yongwww marked this pull request as ready for review March 3, 2023 01:23
@slyubomirsky
Copy link
Contributor

Do we have any way to enforce that the function passed to call_tir is a PrimFunc? I believe making call_tir more specific was discussed before. (Should we still permit passing a PrimFunc to call_dps_packed?)

@psrivas2
Copy link
Contributor

psrivas2 commented Mar 3, 2023

Do we have any way to enforce that the function passed to call_tir is a PrimFunc? I believe making call_tir more specific was discussed before. (Should we still permit passing a PrimFunc to call_dps_packed?)

We can enforce it in MakeCallTIR and MakeCallDPSPacked.
For now I don't see a reason to allow call_dps_packed to call Primfunc.
cc @tqchen

@slyubomirsky
Copy link
Contributor

Do we have any way to enforce that the function passed to call_tir is a PrimFunc? I believe making call_tir more specific was discussed before. (Should we still permit passing a PrimFunc to call_dps_packed?)

We can enforce it in MakeCallTIR and MakeCallDPSPacked. For now I don't see a reason to allow call_dps_packed to call Primfunc. cc @tqchen

It would have to be in the implementation as well, since you can do something like assign a TIR function to a local var and pass that local var elsewhere. In a higher-order function, we wouldn't be able to detect that at compile time unless we make TIR functions part of the type system (though that could be an option).

@tqchen
Copy link
Member

tqchen commented Mar 4, 2023

We can have wellformess to enforce such invariant

@tqchen
Copy link
Member

tqchen commented Mar 5, 2023

please run the following commend to update to latest change

git rebase --onto upstream/unity upstream/unity-rebase-backup-2023-03-05 

@slyubomirsky
Copy link
Contributor

slyubomirsky commented Mar 7, 2023

It would not always be possible to check statically that the operand to call_tir is a PrimFunc. Here is a case where it wouldn't work:

@R.function
def higher_order(f: R.Object) -> R.Object:
    return R.call_tir(f, ...)

@R.function
def g() -> R.Object:
    if some_condition:
        y = some_packed_func
    else:
        y = some_primfunc
    return higher_order(y)

We would not be able to determine statically that the call to higher_order in g will result in a non-PrimFunc being passed to call_tir. If we care about enforcing the distinction, we would have to check for such cases dynamically.

Edit: Otherwise, we could ask for only global vars to be the arguments to call_tir, which I don't think would be the worst thing in the world, but this limits the extent to which PrimFuncs and PackedFuncs are first class. (I don't think they really need to be first class, but in past discussions, we've said that that was desirable.)

@yongwww
Copy link
Member Author

yongwww commented Mar 7, 2023

Have updated well-form check to just allow GlobalVar as the first argument of call_tir. Actually current inline PrimFunc was disallowed in Relax IR, y = some_primfunc in the example has to be y = global_var_of_some_primfunc. I guess we won't run into issues at this moment, correct me if i am wrong

@slyubomirsky
Copy link
Contributor

slyubomirsky commented Mar 7, 2023

Yes, the RHS of that assignment would have to be a global var; we do not permit inline PrimFunc definitions. Perhaps we should get wider agreement if we want to have a restriction of using only global vars for call_tir or call_dps_packed? I can update the spec to reflect whatever we decide.

src/relax/op/op.cc Outdated Show resolved Hide resolved
Co-authored-by: Steven S. Lyubomirsky <[email protected]>
Copy link
Contributor

@slyubomirsky slyubomirsky left a comment

Choose a reason for hiding this comment

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

My concerns have been addressed and everything seems to be reasonable.

Copy link
Contributor

@psrivas2 psrivas2 left a comment

Choose a reason for hiding this comment

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

@@ -33,7 +33,7 @@ namespace relax {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we rename this file and pass to reflect that it handles both call_dps_packed and call_tir?

Copy link
Member Author

@yongwww yongwww Mar 9, 2023

Choose a reason for hiding this comment

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

I was thinking about this, but don't have a better name, any suggestions? if we change this, then the pass name CallTIRRewrite needs to be updated accordingly. We can keep it untouched for now if we don't have an alternative names,

Copy link
Contributor

Choose a reason for hiding this comment

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

DPSRewrite would be my choice but we can discuss and change it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! We can discuss it later, it might need to get wider agreement for pass renaming.

src/script/printer/relax/call.cc Outdated Show resolved Hide resolved
@yongwww
Copy link
Member Author

yongwww commented Mar 9, 2023

Overall LGTM! Thanks! Just some minor nits which can be handled in follow up PRs

legalize_ops would throw a warning for call_dps_packed

Would there be follow up PRs for cleaning up transform/backend passes which earlier checked if call_tir is calling an extern func such as

Have updated for all passes, thanks a lot for pointing them out!!!

@slyubomirsky slyubomirsky merged commit 9ea3f88 into apache:unity Mar 10, 2023
tqchen pushed a commit that referenced this pull request Mar 13, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
tqchen pushed a commit that referenced this pull request Mar 13, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
tqchen pushed a commit that referenced this pull request Mar 13, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
tqchen pushed a commit that referenced this pull request Mar 13, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
tqchen pushed a commit that referenced this pull request Mar 20, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
@yongwww yongwww deleted the call_dps_packed branch March 23, 2023 23:45
tqchen pushed a commit that referenced this pull request Apr 1, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
tqchen pushed a commit that referenced this pull request Apr 1, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
tqchen pushed a commit that referenced this pull request Apr 1, 2023
Introduce call_dps_packed to call packed functions in destination-passing style, reserving call_tir for TIR PrimFuncs instead.

* [Unity] Introduce call_dps_packed

* fix lint

* Fix comments

* Remove well_form update, enforce in InferStructInfoCallTIR

* Update src/relax/op/op.cc

* Update description of call_tir

* Remove unnecessary check in passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants