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

[onert] Introduce capabilities to find operands which can share memory #14228

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mbencer
Copy link
Contributor

@mbencer mbencer commented Oct 16, 2024

This commit adds capabilities to find operands linked which Tensors which can share memory buffers. It's applicable for ops like Reshape, Squeeze and ExpandsDims (where only shape is changed and data is not modified).

ONE-DCO-1.0-Signed-off-by: Mateusz Bencer m.bencer@partner.samsung.com

Draft: #14057

This commit adds capabilities to find operands linked which Tensors
which can share memory buffers. It's applicable for ops like Reshape, Squeeze and ExpandsDims
(where only shape is changed and data is not modified).

ONE-DCO-1.0-Signed-off-by: Mateusz Bencer m.bencer@partner.samsung.com
Comment on lines 83 to 85
{
shared_memory_operand_map[op.getOutputs().at(0)] = op.getInputs().at(0);
}
Copy link
Contributor

@zetwhite zetwhite Oct 24, 2024

Choose a reason for hiding this comment

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

(optional) How about adding assertions here to check is_memory_sharing_allowed only captures single input - single output operation?

Before reading line 53 (ops_with_possible_memory_sharing), I didn't notice that it targets single input, single output operation.

Suggested change
{
shared_memory_operand_map[op.getOutputs().at(0)] = op.getInputs().at(0);
}
{
assert(op.getInputs().size() == 1);
assert(op.getOutputs().size() == 1);
shared_memory_operand_map[op.getOutputs().at(0)] = op.getInputs().at(0);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added (note that for Reshape/ExpandDims number of inputs is 2)

Comment on lines +33 to +46
for (auto [shared_ind, source_ind] : shared_memory_operand_map)
{
bool other_source_found = false;
auto it = std::end(shared_memory_operand_map);
while ((it = shared_memory_operand_map.find(source_ind)) != std::end(shared_memory_operand_map))
{
source_ind = shared_memory_operand_map[source_ind];
other_source_found = true;
}
if (other_source_found)
{
shared_memory_operand_map[shared_ind] = source_ind;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If shared_memory_operand_map = {{1, 2}, {2, 3}, {2, 4}} is given, is this works well..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand 2 cannot indicate other operand two times. (I've made some experiments about this implementation here - https://godbolt.org/z/11KKr9xqY)

@mbencer mbencer requested a review from zetwhite October 25, 2024 15:49
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.

2 participants