-
Notifications
You must be signed in to change notification settings - Fork 450
[Testing] Add Memory Leak Test #1516
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fa9b83b
fix TL_ENABLE_PTXAS_VERBOSE_OUTPUT is not print in tvm-ffi
kurisu6912 6c88395
add memory leak test in tvm-ffi
kurisu6912 a686f1b
fix lint error
kurisu6912 28acf47
Merge branch 'main' of https://github.com/tile-ai/tilelang into fix-p…
kurisu6912 dd9603e
fix typos
kurisu6912 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import tvm_ffi | ||
| import tilelang | ||
| import tilelang.language as T | ||
| import tilelang.testing | ||
| import torch | ||
| import weakref | ||
| import gc | ||
|
|
||
|
|
||
| def test_tilelang_globals_leak(): | ||
| @tilelang.jit( | ||
| pass_configs={ | ||
| tilelang.PassConfigKey.TL_DISABLE_TMA_LOWER: True, | ||
| tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True, | ||
| }, | ||
| ) | ||
| def get_dummy_kernel(): | ||
| @T.prim_func | ||
| def dummy_kernel( | ||
| a: T.Tensor[(1,), T.float32], | ||
| ): | ||
| with T.Kernel(1) as _: | ||
| a[0] = 1 | ||
|
|
||
| return dummy_kernel | ||
|
|
||
| a = torch.randn(1, 1024) | ||
| a_weak = weakref.ref(a) | ||
| _kernel = get_dummy_kernel() | ||
| del a | ||
| torch.cuda.empty_cache() | ||
| gc.collect() | ||
| torch.cuda.empty_cache() | ||
| a_upgrade = a_weak() | ||
| assert a_upgrade is None, "A is not garbage collected" | ||
|
|
||
| # use objgraph to debug | ||
| # if a_upgrade is not None: | ||
| # objgraph.show_backrefs([a_upgrade], max_depth=5) | ||
|
|
||
|
|
||
| def test_error_no_cyclic_reference() -> None: | ||
| # This test case ensures that when an error is raised from C++ side, | ||
| # there is no cyclic reference that slows down the garbage collection. | ||
| # Please see `_with_append_backtrace` in error.py | ||
|
|
||
| # temporarily disable gc | ||
| gc.disable() | ||
|
|
||
| try: | ||
| # We should create a class as a probe to detect gc activity | ||
| # because weakref doesn't support list, dict or other trivial types | ||
| class SampleObject: ... | ||
|
|
||
| # trigger a C++ side KeyError by accessing a non-existent key | ||
| def trigger_cpp_side_error() -> None: | ||
| try: | ||
| tmp_map = tvm_ffi.Map(dict()) | ||
| tmp_map["a"] | ||
| except KeyError: | ||
| pass | ||
|
|
||
| def may_create_cyclic_reference() -> weakref.ReferenceType: | ||
| obj = SampleObject() | ||
| trigger_cpp_side_error() | ||
| return weakref.ref(obj) | ||
|
|
||
| wref = may_create_cyclic_reference() | ||
|
|
||
| # if the object is not collected, wref() will return the object | ||
| assert wref() is None, "Cyclic reference occurs inside error handling pipeline" | ||
|
|
||
| finally: | ||
| # re-enable gc whenever exception occurs | ||
| gc.enable() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| tilelang.testing.main() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.