-
Notifications
You must be signed in to change notification settings - Fork 333
[BugFix] Use BufferRegion in tl.cumsum to infer buffer shape #1321
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
4 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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 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 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,33 @@ | ||
| import torch | ||
| import tilelang | ||
SiriusNEO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import tilelang.testing | ||
| from tilelang import language as T | ||
|
|
||
|
|
||
| @tilelang.jit( | ||
| pass_configs={ | ||
| tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True, | ||
| tilelang.PassConfigKey.TL_DISABLE_TMA_LOWER: True, | ||
SiriusNEO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| },) | ||
| def _cumsum_view_infer_layout(hidden): | ||
| num_tokens = T.dynamic('num_tokens') | ||
|
|
||
| @T.prim_func | ||
| def buggy_kernel(x: T.Tensor[(num_tokens, hidden), 'float']): | ||
| with T.Kernel(num_tokens, threads=128) as pid: | ||
| smem = T.alloc_shared((hidden,), dtype='float') | ||
| T.copy(x[pid, :], smem) | ||
| T.cumsum(T.view(smem, (1, hidden)), dim=1) | ||
|
|
||
| return buggy_kernel | ||
|
|
||
|
|
||
| def test_cumsum_view_infer_layout(): | ||
| hidden = 128 | ||
| x = torch.randn(1, hidden, device='cuda', dtype=torch.float) | ||
| kernel = _cumsum_view_infer_layout(hidden) | ||
| kernel(x) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| tilelang.testing.main() | ||
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 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| """Tilelang IR analysis & visitors.""" | ||
|
|
||
| from .ast_printer import ASTPrinter # noqa: F401 | ||
| from .nested_loop_checker import NestedLoopChecker # noqa: F401 |
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,23 @@ | ||
| from tvm import tir | ||
| from tvm.tir import PrimFunc | ||
| from tvm.tir.transform import prim_func_pass | ||
| from tvm.tir.stmt_functor import ir_transform | ||
|
|
||
|
|
||
| def ASTPrinter(): | ||
| """ | ||
| Print the AST of a given tilelang module for debugging. | ||
| """ | ||
|
|
||
| def pre_visit(statement: tir.Stmt) -> None: | ||
| """ | ||
| Pre-order visitor to print all visited statements. | ||
| """ | ||
|
|
||
| print(f"Visiting statement: {type(statement)}") | ||
|
|
||
| def pass_fn(func: PrimFunc, mod, ctx) -> PrimFunc: | ||
| new_body = ir_transform(func.body, pre_visit, None) | ||
| return func.with_body(new_body) | ||
|
|
||
| return prim_func_pass(pass_fn, opt_level=0) |
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 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
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.