-
Notifications
You must be signed in to change notification settings - Fork 159
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
[onert/cpu] [Reshape, ExpandDims] Avoid copying memory if possible #14229
[onert/cpu] [Reshape, ExpandDims] Avoid copying memory if possible #14229
Conversation
This commit copying memory only if output buffer is different from input buffer. It they are equal it means that input and output tensors share the same memory. It is applicable for Reshape and ExpandDims operations. ONE-DCO-1.0-Signed-off-by: Mateusz Bencer [email protected]
size_t count = _input->total_size(); | ||
memcpy(_output->buffer(), _input->buffer(), count); | ||
// output buffer equals to input buffer means that copy is not needed | ||
if (_output->buffer() != _input->buffer()) |
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 have a question.
Did you have a case that input and output buffer are same?
For memcpy(), src and dest memory area must not overlap, otherwise, its behavior is undefined.
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.
Note that this change is a part of bigger issue implemented in #14057. In this draft I am changing tensor allocation mechanism to share memory memory between input and output tensors of Reshape/ExpandDims/Squeeze. In other words different tensors can indicate the same buffers (it requires additional handing of such memory management).
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've followed the draft and issue and understood.
Thanks for the explanation :)
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.
LGTM
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.
LGTM
I'll merge this because it is too delayed. |
This commit copying memory only if output buffer is different from input buffer. It they are equal it means that input and output tensors share the same memory. It is applicable for Reshape and ExpandDims operations.
ONE-DCO-1.0-Signed-off-by: Mateusz Bencer [email protected]
Draft: #14057