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

[Relax] Update GlobalVar name in AttachGlobalSymbol #17202

Merged
merged 4 commits into from
Sep 6, 2024

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, the relax.transform.AttachGlobalSymbol pass could produce a PrimFunc whose "global_symbol" attribute does not match the name of the GlobalVar. As a result, the PackedFunc that is provided by the compiled module (defined by the "global_symbol") does not match the PackedFunc that is required by the Relax VM (defined by the GlobalVar name).

This commit updates AttachGlobalSymbol to replace the GlobalVar of any function whose "global_symbol" is updated.

Closes #17176

Prior to this commit, the `relax.transform.DeadCodeElimination` only
considered calls from Relax to TIR when identifying unused functions.
This would erroneously remove TIR functions that are called
indirectly.

This commit adds a new utility `tvm.ir.analysis.collect_call_map`,
which can collect the call map of an `IRModule` across both Relax and
TIR, using it in Relax's `DeadCodeElimination` transform.
Prior to this commit, the `relax.transform.AttachGlobalSymbol` pass
could produce a PrimFunc whose `"global_symbol"` attribute does not
match the name of the `GlobalVar`.  As a result, the PackedFunc that
is provided by the compiled module (defined by the `"global_symbol"`)
does not match the PackedFunc that is required by the Relax
VM (defined by the `GlobalVar` name).

This commit updates `AttachGlobalSymbol` to replace the `GlobalVar` of
any function whose `"global_symbol"` is updated.

Closes apache#17176
@Lunderberg Lunderberg requested a review from sunggg July 29, 2024 18:40
@tqchen tqchen merged commit f432ebd into apache:main Sep 6, 2024
18 checks passed
@Lunderberg Lunderberg deleted the replace_global_var_on_rename branch September 6, 2024 13:34
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Sep 10, 2024
This is a follow-up PR to apache#17202,
which added a general utility to replace `GlobalVar` instances across
all TVM IR types.  This PR exposes this new utility through the Python
API, and explicitly tests its functionality.
Lunderberg added a commit that referenced this pull request Sep 12, 2024
* [IR] Expose ReplaceGlobalVars utility in the Python API

This is a follow-up PR to #17202,
which added a general utility to replace `GlobalVar` instances across
all TVM IR types.  This PR exposes this new utility through the Python
API, and explicitly tests its functionality.

* Lint fix
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.

[Relax][Bug] Cannot find PackedFunc tir_zeros
2 participants