refactor getAllocationDomainsAndContiguity#4792
Conversation
|
Review updated until commit 3a06741 Description
Changes walkthrough 📝
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
!test --diff |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the getAllocationDomainsAndContiguity function by extracting helper functions into an anonymous namespace to improve code organization and readability. The refactoring breaks down the complex logic into smaller, more focused functions without changing the overall functionality.
Key changes:
- Extract helper functions into anonymous namespace for better organization
- Improve code structure by separating concerns into dedicated functions
- Minor formatting improvements for comments and code alignment
Comments suppressed due to low confidence (2)
csrc/device_lower/pass/allocation.cpp:166
- [nitpick] Function name should follow camelCase convention. Consider renaming to 'canUsePresetAllocationDomain' or use snake_case if that's the project convention.
bool canUsePresetAllocationDomain(TensorView * tv) {
csrc/device_lower/pass/allocation.cpp:227
- [nitpick] Function name suggests a boolean return but returns a pointer. Consider renaming to 'getExcludedAllocationDomain' or 'findExcludedAllocationDomain' to better reflect the actual return type.
IterDomain* shouldExcludeAllocationDomain(
|
!test --diff |
1 similar comment
|
!test --diff |
040e349 to
3a06741
Compare
|
!test --diff |
|
code diff is ptx register names |
| usePresetAllocationDomain( | ||
| TensorView* tv, | ||
| const std::vector<ForLoop*>& for_loops) { | ||
| if (tv->getMemoryType() == MemoryType::Global) { |
There was a problem hiding this comment.
Is my understanding correct that only changes made to the logic is inside usePresetAllocationDomain?
There was a problem hiding this comment.
I can use a quick context / high level description on what's the motivation behind the refactor.
There was a problem hiding this comment.
Is my understanding correct that only changes made to the logic is inside
usePresetAllocationDomain?
Yes, the logic in usePresetAllocationDomain will be changed in a following PR, see #4791.
This current PR is just a refactor, it didn't change the logic.
There was a problem hiding this comment.
I can use a quick context / high level description on what's the motivation behind the refactor.
The previous function became too large and difficult to maintain. It includes logic to determine whether the preset allocation domain can be reused, how to reuse it if possible, and how to set a new allocation domain if not. The code contains many deeply nested if-else branches, making it hard to follow and maintain.
There was a problem hiding this comment.
This current PR is just a refactor, it didn't change the logic.
Thanks a lot for confirming that. I thought we have changed the logic in usePresetAllocationDomain, but looks like we are just moving some utils around.
jjsjann123
left a comment
There was a problem hiding this comment.
stamp for code restructure.
🙇
| usePresetAllocationDomain( | ||
| TensorView* tv, | ||
| const std::vector<ForLoop*>& for_loops) { | ||
| if (tv->getMemoryType() == MemoryType::Global) { |
There was a problem hiding this comment.
This current PR is just a refactor, it didn't change the logic.
Thanks a lot for confirming that. I thought we have changed the logic in usePresetAllocationDomain, but looks like we are just moving some utils around.
**Changes:**
Refactor `getAllocationDomainsAndContiguity`
- Extracted function `canUsePresetAllocationDomain`
- Extracted function `usePresetAllocationDomain`
**Motivations:**
`getAllocationDomainsAndContiguity`mainly does 3 things:
- Determine whether the preset allocation domain can be reused
- Check how to reuse it if possible
- set a new allocation domain if can't use the preset domain
Each section contains many deeply nested if-else branches, making it
hard to follow and maintain.
This refactor abstracts the first two tasks into two helper functions.
After refactor, the logic of `getAllocationDomainsAndContiguity` is:
```
if(canUsePresetAllocationDomain()){
return usePresetAllocationDomain()
}
Derive domains that should be allocated from loop domain & allocation position.
```
Changes:
Refactor
getAllocationDomainsAndContiguitycanUsePresetAllocationDomainusePresetAllocationDomainMotivations:
getAllocationDomainsAndContiguitymainly does 3 things:Each section contains many deeply nested if-else branches, making it hard to follow and maintain.
This refactor abstracts the first two tasks into two helper functions.
After refactor, the logic of
getAllocationDomainsAndContiguityis: