Skip to content

[SYCL] Remove circular dependency between piEventRelease and cleanup() #6073

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

Closed
wants to merge 1 commit into from

Conversation

againull
Copy link
Contributor

Event is retained explicitely when created in createEventAndAssociateQueue()
to ensure that the event is not destroyed before it is really signalled.
Ref count is decremented in Event->cleanup() after event is singalled. This
means that if reference count for an event is zero then cleanup was already
called for this event and should not be called anymore.

Interop events and user events don't have associated command list, queue,
kernel and waitlist, so we don't need to call cleanup() for interop and user
events.

Event is retained explicitely when created in createEventAndAssociateQueue()
to ensure that the event is not destroyed before it is really signalled.
Ref count is decremented in Event->cleanup() after event is singalled. This
means that if reference count for an event is zero then cleanup was already
called for this event and should not be called anymore.

Interop events and user events don't have associated command list, queue,
kernel and waitlist, so we don't need to call cleanup() for interop and user
events.
@againull againull requested a review from a team as a code owner April 27, 2022 23:38
@@ -5544,9 +5544,6 @@ static pi_result EventRelease(pi_event Event, pi_queue LockedQueue) {
}

if (--(Event->RefCount) == 0) {
if (!Event->CleanedUp)
Copy link
Contributor

Choose a reason for hiding this comment

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

What will call the "cleanup" of an event that wasn't explicitly waited with piEventsWait?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently nothing will call cleanup in this case no matter with or without proposed change.
Per our current implementation if event is not waited then it's refcount is not zero, so we won't go through check on line 5546 in this case.

And per current implementation cleanup is supposed to be called for event which was waited. It looks like it was done intentionally to not release/reset resources like associated kernel/commandlist if event was not waited.
We can change this behavior obviously and cleanup everything even if associated work is not finished. But I am not sure if it is going to be correct,

As for me proposed change is needed anyway, this call to cleanup() under RefCount == 0 check is incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can change this behavior obviously and cleanup everything even if associated work is not finished.

That we cannot do, otherwise we might destroy some L0 resources that are still being used and result in a segfault or even worse. But we must cleanup everything after waiting for everything is completed. If we aren't cleaning up, this means we have memory leaks, right?

As for me proposed change is needed anyway, this call to cleanup() under RefCount == 0 check is incorrect.

I don't disagree to that, but want to understand better why this was needed before.

@againull
Copy link
Contributor Author

againull commented Jun 1, 2022

Merged in scope of #6179

@againull againull closed this Jun 1, 2022
@againull againull deleted the remove_circular_dep branch December 3, 2022 00:13
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