-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Hexagon] Add fix for vtcm allocation searches #13197
Conversation
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment. Generated by tvm-bot |
2f9b770
to
8991ca1
Compare
ptr4 = vtcm_pool->Allocate(max_bytes); | ||
vtcm_pool->Free(ptr4, max_bytes); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest:
TEST_F(HexagonVtcmPoolTest, find_allocation) {
void* ptr1;
void* ptr2;
void* ptr3;
ptr1 = vtcm_pool->Allocate(two_k_block);
ptr2 = vtcm_pool->Allocate(two_k_block);
vtcm_pool->Free(ptr1, two_k_block);
ptr3 = vtcm_pool->Allocate(four_k_block);
vtcm_pool->Free(ptr2, two_k_block);
vtcm_pool->Free(ptr3, four_k_block);
// Make sure at the end we have the full amount available again
ptr1 = vtcm_pool->Allocate(max_bytes);
vtcm_pool->Free(ptr1, max_bytes);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed this fails without the fix, works great with the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great - I like the new test cases!
@@ -85,7 +85,7 @@ void* HexagonVtcmPool::Allocate(size_t nbytes) { | |||
|
|||
auto entry_to_allocate = free_.begin(); | |||
for (auto it = free_.begin(); it != free_.end(); it++) { | |||
if ((it->second < entry_to_allocate->second) && (it->second >= nbytes)) { | |||
if (((entry_to_allocate->second < nbytes) || (it->second < entry_to_allocate->second)) && (it->second >= nbytes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The groups should be slightly adjusted:
if ((entry_to_allocate->second < nbytes) || ((it->second < entry_to_allocate->second) && (it->second >= nbytes))) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesnt this lead to us updating entry_to_allocate for iterator values that may not fit the desired allocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, that's ok because it will still find a free block that works if there is one. But on reflection, I like your grouping better - I think it makes it more clear for future editors.
ptr4 = vtcm_pool->Allocate(max_bytes); | ||
vtcm_pool->Free(ptr4, max_bytes); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great - I like the new test cases!
vtcm_pool->Free(ptr1, two_k_block); | ||
|
||
// Allocate a new larger block to initiate search and ensure | ||
// it succeeds despite there not being a matching block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "despite there not being a match in the first free block."
* [Hexagon] Add fix for VTCM allocation search and new test case to cover the issue. * Add another test for a specific case. * [Hexagon] Fix tests. * Remove unused var * Change to comments to make more clear.
* [Hexagon] Add fix for VTCM allocation search and new test case to cover the issue. * Add another test for a specific case. * [Hexagon] Fix tests. * Remove unused var * Change to comments to make more clear.
Previously we were failing allocations in an attempt to find the smallest allocation possible but were failing to find an allocation that worked if it was available.