Skip to content

Conversation

@nverke
Copy link
Contributor

@nverke nverke commented Oct 25, 2022

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.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 25, 2022

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

@nverke nverke changed the title [Hexagon] Add fix for vtcm allocation searches. [Hexagon] Add fix for vtcm allocation searches Oct 25, 2022
ptr4 = vtcm_pool->Allocate(max_bytes);
vtcm_pool->Free(ptr4, max_bytes);
}

Copy link
Contributor

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);
}

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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!

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)) {
Copy link
Contributor

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))) {

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@nverke nverke marked this pull request as ready for review October 25, 2022 21:59
ptr4 = vtcm_pool->Allocate(max_bytes);
vtcm_pool->Free(ptr4, max_bytes);
}

Copy link
Contributor

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.
Copy link
Contributor

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."

@masahi masahi merged commit 62789a6 into apache:main Oct 26, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
* [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.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [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.
@nverke nverke deleted the vtcm_alloc_fix branch January 13, 2023 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants