[Fix][Relax] Scope planned storage to if branches - #20514
Open
javierdejesusda wants to merge 1 commit into
Open
javierdejesusda wants to merge 1 commit into
javierdejesusda wants to merge 1 commit into
Conversation
Fixes apache#20191. `StaticPlanBlockMemory` plans with one token pool per function, and its rewriter emits `R.memory.alloc_storage` only at the first use of a token. A token released in one `if` branch can be reused in the other branch or after the `if`, where that storage variable is not defined. The planned module is then ill-formed, and the VM segfaults for `cond=False` in the issue script. The rewriter now restores its token-to-storage-variable map when it leaves a `SeqExpr`, so a token first used in a branch gets a new `alloc_storage` wherever it is reused outside that branch. Storage allocated before the `if` is still shared with the branches. Tests: - `python -m pytest -q tests/python/relax/test_transform_static_plan_block_memory.py` (`32 passed`). Two of the three new tests fail without the change; the third pins that storage allocated before the `if` stays shared, and passes either way. - The issue script without `exec_mode="bytecode"` (`relax.build` no longer takes it), built with the default pipeline for llvm, returns `x` for `cond=True` and `cond=False`; before the change `cond=False` segfaults. - `pre-commit run --files src/relax/transform/static_plan_block_memory.cc tests/python/relax/test_transform_static_plan_block_memory.py`
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20191.
StaticPlanBlockMemoryplans with one token pool per function, and its rewriter emitsR.memory.alloc_storageonly at the first use of a token. A token released in oneifbranch can be reused in the other branch or after theif, where that storage variable is not defined. The planned module is then ill-formed, and the VM segfaults forcond=Falsein the issue script.The rewriter now restores its token-to-storage-variable map when it leaves a
SeqExpr, so a token first used in a branch gets a newalloc_storagewherever it is reused outside that branch. Storage allocated before theifis still shared with the branches.Tests:
python -m pytest -q tests/python/relax/test_transform_static_plan_block_memory.py(32 passed). Two of the three new tests fail without the change; the third pins that storage allocated before theifstays shared, and passes either way.exec_mode="bytecode"(relax.buildno longer takes it), built with the default pipeline for llvm, returnsxforcond=Trueandcond=False; before the changecond=Falsesegfaults.pre-commit run --files src/relax/transform/static_plan_block_memory.cc tests/python/relax/test_transform_static_plan_block_memory.py