Skip to content
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

Add memory tracking for RTree ranges. #5029

Merged
merged 13 commits into from
Jun 21, 2024
Merged

Add memory tracking for RTree ranges. #5029

merged 13 commits into from
Jun 21, 2024

Conversation

teo-tsirpanis
Copy link
Member

SC-46801

This PR enables memory tracking for RTree ranges. The first part consists of updating the range class to be backed by a tdb::pmr::pmr_vector1 instead of an std::vector which allows users to specify a custom allocator that tracks memory, in an opt-in basis. The second part is updating the RTree class to use these allocators when creating the ranges.

Validated locally. Let me know what kind of testing to add.


TYPE: NO_HISTORY

Footnotes

  1. We are not using tdb::pmr::vector, because it is not copy or move constructible, which would break other uses of ranges. Only ranges created by RTrees will be tracked in this PR.

for (unsigned d = 0; d < dim_num; ++d) {
auto dim{domain->dimension_ptr(d)};
if (!dim->var_size()) { // Fixed-sized
auto r_size = 2 * dim->coord_size();
auto data = deserializer.get_ptr<void>(r_size);
levels_[l][m][d] = Range(data, r_size);
// NDRange is not yet a pmr vector, so we need to explicitly pass the
Copy link
Member Author

Choose a reason for hiding this comment

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

Making NDRange a tdb::pmr::pmr_vector would require changing many files that use std::vector<Range> to use NDRange. I can change them, but am wary about expanding the PR's scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's file a follow up story here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@teo-tsirpanis teo-tsirpanis changed the title Teo/rtree pmr Add memory tracking for RTree ranges. May 31, 2024
@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review May 31, 2024 01:38
@@ -61,14 +62,28 @@ class Range {
* The range is stored as a sequence of bytes with manual memory layout. The
* memory layout is different for fixed-size and variable-size types.
*
* The type is tdb::pmr::pmr_vector<uint8_t> instead of
Copy link
Contributor

@KiterLuc KiterLuc May 31, 2024

Choose a reason for hiding this comment

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

@davisp Are there any reasons we disabled the copy constructors in tdb::pmr::vector? Are we worried the copy constructor that doesn't take a memory tracker will not do the right thing and we might have some allocator mixup or are we worries that someone can initialize a vector that we want tracked with a vector that's not tracked? If it's the later, could we throw in the copy constructor if the vector passed in doesn't have an allocator?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are two copy constructors. One takes an allocator and one doesn't. The one that takes an allocator is available for use.

The copy constructor that doesn't take an allocator is disabled. That choice was so that as we changed from std::vector to std::pmr::vector, we'd not miss any place where we used copy constructors because the compiler would catch the issue and force us to update those call sites with the allocator argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

  • I restored the move constructor and move-assign operator in tdb::pmr::vector.
  • I manually implemented the copy constructor and copy-assign operator in Range to avoid breaking other uses.

for (unsigned d = 0; d < dim_num; ++d) {
auto dim{domain->dimension_ptr(d)};
if (!dim->var_size()) { // Fixed-sized
auto r_size = 2 * dim->coord_size();
auto data = deserializer.get_ptr<void>(r_size);
levels_[l][m][d] = Range(data, r_size);
// NDRange is not yet a pmr vector, so we need to explicitly pass the
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's file a follow up story here.

: pmr_vector<Tp>(init, alloc) {
}
};
using vector = std::vector<Tp, polymorphic_allocator<Tp>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that is the change I think I want to make... Let me ponder on it for a little while longer. This is blocked on me now.

@KiterLuc KiterLuc merged commit f2cb107 into dev Jun 21, 2024
61 checks passed
@KiterLuc KiterLuc deleted the teo/rtree-pmr branch June 21, 2024 09:19
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.

None yet

3 participants