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] Cleanup of MakePackedAPI #14989

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, the RequiresPackedAPI function checked whether a function needed the packed func API. This was used both to generate a list of call-sites to update, and as part of the updates to PrimFunc signatures. However, the function that updates the PrimFunc signature could still return the original function unmodified, breaking internal method calls. This occurred for functions with a kTarget attribute without a host.

This commit updates MakePackedAPI to first update all PrimFunc signatures that require the packed func API, then use the result to determine which call-sites must be updated. This resolves the discrepancy for host-less target annotations, and removes the possibility of similar discrepancies in the future.

This resolves an issue introduced by the combination of
apache#14918 and
apache#14945.  The bug occurred for
targets that do not require device-side codegen, but do require a
`device_type` other than `kDLCPU`.  It wasn't caught by CI, as the
issue only occurred with the combination of both PRs.

1. apache#14918 updated `SplitHostDevice` to only modify the `"target"`
   attribute when a device-side function has been extracted.

2. For VTA, there is no device-side function, as everything is done
   through host-side API calls.

3. From (1) and (2), the VTA examples kept the target
   `T.target("ext_dev", host="llvm")` after the `SplitHostDevice`
   pass, instead of being updated to `T.target("llvm")`.

4. apache#14945 restricted CombineContextCall to only apply to host-side
   passes.

5. From (4) and (5), the `CombineContextCall` pass was no longer
   applied to the VTA context calls.

This PR fixes `SplitHostDevice`, updating the target from
`T.target("ext_dev", host="llvm")` to `T.target("llvm")`, even if no
device sections have been extracted from the function.
This simplifies the logic used in MakePackedAPI, that it the last user
of the host parameter in a function's target.  After MakePackedAPI,
every PrimFunc has a "target" attribute without a "host".
Prior to this commit, the `RequiresPackedAPI` function checked whether
a function needed the packed func API.  This was used both to generate
a list of call-sites to update, and as part of the updates to
`PrimFunc` signatures.  However, the function that updates the
`PrimFunc` signature could still return the original function
unmodified, breaking internal method calls.  This occurred for
functions with a `kTarget` attribute without a host.

This commit updates `MakePackedAPI` to first update all `PrimFunc`
signatures that require the packed func API, then use the result to
determine which call-sites must be updated.  This resolves the
discrepancy for host-less target annotations, and removes the
possibility of similar discrepancies in the future.
@tvm-bot
Copy link
Collaborator

tvm-bot commented May 30, 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

@Lunderberg
Copy link
Contributor Author

CI failures require #14986 to resolve. Merging that dev branch into this one to run CI, and changing to draft PR as this shouldn't be merged until after #14986 lands.

@Lunderberg Lunderberg marked this pull request as draft June 2, 2023 18:59
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.

None yet

2 participants