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

[Relay] Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. #9542

Merged
merged 2 commits into from
Nov 23, 2021

Conversation

mbs-octoml
Copy link
Contributor

@mbs-octoml mbs-octoml commented Nov 20, 2021

As part of #9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

Note that some unit tests assume DCE eliminates dead writes to references. The
previous implementation certainly did that, but also eliminated all writes. To do this
soundly will require a bit of liveness analysis. Rather than doing that now I've added
an 'ignore_impurity' flag to DeadCodeElimination() to recover the (unsound) legacy
behavior.

@mbs-octoml mbs-octoml changed the title Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. [Relay] Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. Nov 20, 2021
Copy link
Member

@jroesch jroesch left a comment

Choose a reason for hiding this comment

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

It would be good to get a second set of eyes but looks good to me. Modulo my comment.

@mikepapadim
Copy link
Contributor

LGTM

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.
Copy link
Contributor

@electriclilies electriclilies left a comment

Choose a reason for hiding this comment

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

Really nice and readable! Caught a few spelling errors though.
Also, one clarifying Q

@tmoreau89 tmoreau89 merged commit 34ea319 into apache:main Nov 23, 2021
@tmoreau89
Copy link
Contributor

Thank you @mbs-octoml @mikepapadim @electriclilies @jroesch ; the PR has been merged

@mbs-octoml mbs-octoml deleted the mbs-dead-code branch November 23, 2021 17:22
dchauhan-arm pushed a commit to dchauhan-arm/tvm that referenced this pull request Nov 29, 2021
…festAlloc. (apache#9542)

* Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc.

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.

* [checkpoint] Merge Lily's suggestions.
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…festAlloc. (apache#9542)

* Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc.

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.

* [checkpoint] Merge Lily's suggestions.
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…festAlloc. (apache#9542)

* Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc.

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.

* [checkpoint] Merge Lily's suggestions.
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
…festAlloc. (apache#9542)

* Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc.

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.

* [checkpoint] Merge Lily's suggestions.
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
…festAlloc. (apache#9542)

* Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc.

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.

* [checkpoint] Merge Lily's suggestions.
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
…festAlloc. (apache#9542)

* Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc.

As part of apache#9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.

Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.

Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.

A few tests assume DCE eliminates dead reference writes. The previous
implementation certainly did that, but by eliminating *all* writes.

Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded
analysis would probably do just fine and we don't need to get hung up on alias
analysis). In the meantime, added an 'ignore_impurity' flag (default False)
and set to true just in the few unit tests which rely on the unsound impl.

* [checkpoint] Merge Lily's suggestions.
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.

5 participants