Skip to content

[SYCL] Fix handling of discarded events in preview lib #19005

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

Open
wants to merge 4 commits into
base: sycl
Choose a base branch
from

Conversation

igchor
Copy link
Member

@igchor igchor commented Jun 16, 2025

The queue implementation assumed that handler.finalize() will return either a valid (non-discarded) event or nullptr (that's why parseEvent is nop in preview mode).

However, that was not always true. It was possible for scheduler to only mark an event as discarded after handler.finalize() completed (during actual command execution). This resulted in discarded event being stored in LastEventPtr in the queue and calls to wait() on that discarded event (which is not allowed) in MT scenarios.

Fix this, by modyfing addCG() to mark the event as discarded immediately and to return nullptr is the event is discarded.

@igchor igchor requested a review from a team as a code owner June 16, 2025 19:35
@igchor igchor requested a review from maarquitos14 June 16, 2025 19:35
@igchor igchor force-pushed the discard_event_fix branch from f7b6b96 to fc67f5c Compare June 16, 2025 19:37
@aelovikov-intel
Copy link
Contributor

I think the PR description has to go into inline code comments somewhere (although I might be wrong here). IMO, git log/blame is a last resort thing and all the crucial information to understand the logic of the code has to be readily available in the trunk version of the code itself.

Am I missing anything why that reasoning shouldn't apply here?

@igchor
Copy link
Member Author

igchor commented Jun 16, 2025

I think the PR description has to go into inline code comments somewhere (although I might be wrong here). IMO, git log/blame is a last resort thing and all the crucial information to understand the logic of the code has to be readily available in the trunk version of the code itself.

Am I missing anything why that reasoning shouldn't apply here?

Well, I'm not sure if it makes sense to put a comment describing a bug that has been fixed but I agree that we should describe why we need to mark the event as discarded in addCG(). Done (altough I made the description a bit more general than what I put in the PR description).

Comment on lines 906 to 907
// For preview mode, handler.finalize() is expected to return nullptr
// if the event is discarded.
Copy link
Contributor

@aelovikov-intel aelovikov-intel Jun 16, 2025

Choose a reason for hiding this comment

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

This should be moved/copied to handler.hpp, IMO.

Is there a reasonable place to assert for this as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Move to handler.hpp. Yes, we can assert that in queue, inside parseEvent(). Done.

@igchor igchor temporarily deployed to WindowsCILock June 16, 2025 21:36 — with GitHub Actions Inactive
@igchor igchor temporarily deployed to WindowsCILock June 16, 2025 21:36 — with GitHub Actions Inactive
igchor added 2 commits June 16, 2025 21:55
The queue implementation assumed that handler.finalize()
will return either a valid (non-discarded) event or nullptr
(that's why parseEvent is nop in preview mode).

However, that was not always true. It was possible for
scheduler to only mark an event as discarded after
handler.finalize() completed (during actual command
execution). This resulted in discarded event being
stored in LastEventPtr in the queue and calls to wait()
on that discarded event (which is not allowed) in MT
scenarios.

Fix this, by modyfing addCG() to mark the event as
discarded immediately. This allows handler to return
nullptr for preview mode.
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