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.
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
Change TensorShape to typically not allocate heap memory #9542
Change TensorShape to typically not allocate heap memory #9542
Changes from 24 commits
59f3045
c9f916a
36d9f6a
48ab110
a9f2330
9717adb
06095c3
f7e6717
554925b
7dfff97
b1352a5
1b258ee
e7cc62d
8cace97
6828641
fe303ea
766d5f6
dfdadd6
453b725
c411d89
93ea6f9
0c7a774
8ceef80
c16631d
58aaec8
622de71
19d6b07
d22e227
7d4efe6
3524689
d7e0e64
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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: can use a new line for the function body
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.
Changed, hopefully it'll pass the build tests now.. hitting random breaks unrelated to my change.
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.
I feel that we could use std::pmr::vector with pool allocator sitting on top of the buffer with upstream new_delete. That way we perfectly simulate small value optimization with first bytes being taking from the inline buffer and bigger buffers from heap. This way we would get rid of unique_ptr and all the logic associated with it.
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.
Furthermore, we could abstract all the logic of manipulating mutable shapes inside TensorShape based on pmr and enjoy correctness and the absence of heap.
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.
We talked about it outside of github, here's a summary:
std::pmr::vector would be useful in all of the code that currently uses TensorShape::GetDimsAsVector to take advantage of a small size optimized vector. As TensorShape isn't a vector (no runtime adding/removing of elements) it's not needed there (and would take up more space).
Sadly there's no way to remove the unique_ptr member as without it there is no way to know if the memory is the small block, allocated memory, or external memory from TensorShape::FromExistingBuffer.
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.
Allocation and copy into heap buffer, the thing this PR is trying to avoid.
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.
Yeah, to fix further things we'll need to have a small block optimized vector that allows modifying, as a few lines later this code exists:
We'd need to replace all instances of code like this to use a replacement for std::vector that doesn't allocate for small sizes. This would be easy to incrementally do in a later change (by just searching for all of the GetDimsAsVector()s)