-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Relax] Implement R.ensure_zero_offset and update memory planning for R.view #17145
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 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2f5d036
[Relax] Implement R.ensure_aligned and update memory planning for R.view
vinx13 59fada7
Rename to ensure_zero_offset and LowerRuntimeBuiltin
vinx13 c742a07
lint
vinx13 c4e1f29
Add warnings
vinx13 d1a3243
Apply format
vinx13 c931b45
Check kAllocAlignment
vinx13 25cc462
update LegalizeView to no op
vinx13 7ed6b38
Make SupportsDevicePointerArithmetics virutal
vinx13 cd553b6
fix
vinx13 0abe71d
lint
vinx13 a07aa4f
apply eric's patch
vinx13 d5b1588
fix
vinx13 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 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
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
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
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 |
|---|---|---|
|
|
@@ -286,8 +286,13 @@ class TokenAllocator1D { | |
| std::vector<StorageToken> full_pool_; | ||
| }; | ||
|
|
||
| /*! \brief Check if the input op is "relax.reshape". */ | ||
| bool IsReshape(const Expr& op) { return op.same_as(Op::Get("relax.reshape")); } | ||
| /*! \brief Check if the input op is a memory op that may return the same buffer. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you on the updated docstring. As I'm looking at it, we may want to add this as another operator attribute (e.g. |
||
| bool IsInplaceMemoryOp(const Expr& op) { | ||
| static const Op& reshape_op = Op::Get("relax.reshape"); | ||
| static const Op& view_op = Op::Get("relax.memory.view"); | ||
| static const Op& ensure_zero_offset_op = Op::Get("relax.memory.ensure_zero_offset"); | ||
| return op.same_as(reshape_op) || op.same_as(view_op) || op.same_as(ensure_zero_offset_op); | ||
| } | ||
|
|
||
| /*! \brief The base class for the storage allocation visitor. */ | ||
| class StorageAllocatorBaseVisitor : public ExprVisitor { | ||
|
|
@@ -498,7 +503,7 @@ class StorageAllocatorInit : public StorageAllocatorBaseVisitor { | |
| // Create a storage token for builtin alloc_tensor. | ||
| this->CreateToken(call); | ||
| return; | ||
| } else if (IsReshape(call->op)) { | ||
| } else if (IsInplaceMemoryOp(call->op)) { | ||
| // Reuse the input's token for builtin reshape. | ||
| SetTokens(call, GetTokens(call->args[0])); | ||
| return; | ||
|
|
@@ -751,7 +756,7 @@ class StorageAllocator : public StorageAllocatorBaseVisitor { | |
| block_tokens.push_back(new_token.get()); | ||
| } | ||
| return; | ||
| } else if (IsReshape(call->op)) { | ||
| } else if (IsInplaceMemoryOp(call->op)) { | ||
| Tokens tokens = GetTokens(call->args[0]); | ||
| ICHECK(!tokens.IsNested()); | ||
| if (tokens.IsLeaf()) { | ||
|
|
||
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
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.