Skip to content

[SYCL] [L0] Fix for event leakage when using immediate commandlists. #7546

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

Merged
merged 4 commits into from
Dec 2, 2022

Conversation

rdeodhar
Copy link
Contributor

This change properly gathers events that have been set and need to be recycled.

@rdeodhar rdeodhar requested a review from a team as a code owner November 27, 2022 05:45
Comment on lines 1042 to 1043
EventList.clear();
EventList = std::move(UnsetEventsList);
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like some redundant copying, why do you need a new UnsetEventsList at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to delete elements from EventList inside a loop which is iterating over EventList does not work. Odd things happen, like skipping elements in the original EventList. That caused the leak. It is safer to iterate over EventList, gather remaining elements in another list and then update EventList.

Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to delete elements from EventList inside a loop which is iterating over EventList does not work. Odd things happen, like skipping elements in the original EventList. That caused the leak.

Should the fix is be as simple as updating the iterator as you erase:

it = EventList.erase(it);

Copy link
Contributor

@aelovikov-intel aelovikov-intel Nov 29, 2022

Choose a reason for hiding this comment

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

Or maybe std::remove_if(begin, end, predicate/lambda) ? Or std::list::remove_if if that's the container being used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A combination of the suggestions was used. The additional list has been eliminated and deletions from EventList are done in-place.

std::move(it, it, std::back_inserter(EventListToCleanup));
EventList.erase(it, it);
EventListToCleanup.push_back(std::move((*it)));
it = EventList.erase(it, it);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it was the last event and it now points to end iterator? Wouldn't it++ of it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even a removal at the end of the list works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

My question wasn't about the removal but about the it++ executed along the loop backedge after said removal is done. Is that ok as 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.

It was not OK to simply update the iterator.
Further digging revealed why in an earlier version of the code some events in the incoming list were skipped during examining for being reset. Now, the for-loop does not increment the iterator. If an event is removed the iterator is set to the element after the one being removed, and if the event is not erased then the iterator is incremented. This avoid the double ++ that was occurring before, whenever an event was removed.

@againull
Copy link
Contributor

againull commented Dec 2, 2022

SYCL :: AtomicRef/max_local.cpp is being tracked in #7604

@againull againull merged commit 5b021a2 into intel:sycl Dec 2, 2022
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