[SYCL] Reusable Events limitation for cross-context dependencies.#22639
Draft
slawekptak wants to merge 2 commits into
Draft
[SYCL] Reusable Events limitation for cross-context dependencies.#22639slawekptak wants to merge 2 commits into
slawekptak wants to merge 2 commits into
Conversation
Currently, cross-context dependencies are not supported for the Reusable Events APIs. Cross-context dependencies use host tasks internally, so the event wait might be queued behind the host task in the runtime, which is currently not supported by the extension APIs.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the SYCL Reusable Events extension to explicitly reject cross-context dependencies for enqueue_wait_event(s), aligning behavior with the current runtime limitation that cross-context waits may be queued behind host-task machinery.
Changes:
- Add context-matching validation to
enqueue_wait_event/enqueue_wait_events, throwingsycl::errc::invalidfor cross-context waits. - Update unit tests to expect the new exception behavior for cross-context waits (single and multiple events).
- Extend the scheduler-bypass limitation enforcement in
queue_impl::submit_barrier_direct_implto cover wait-only reusable-events calls (CallerNeedsEvent == false).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| sycl/unittests/Extensions/ReusableEvents.cpp | Adjusts tests to validate that cross-context waits are rejected, and adds a multi-event variant. |
| sycl/source/reusable_events.cpp | Adds explicit runtime checks to reject cross-context waits in the reusable-events API surface. |
| sycl/source/detail/queue_impl.cpp | Updates barrier submission control flow to enforce the scheduler-bypass limitation for wait-only reusable-events calls. |
Comment on lines
+474
to
+475
| // Current limiation is that an event from different context | ||
| // cannot be used with enqueue_wait_event |
Comment on lines
+522
to
+523
| // Current limiation is that an event from different context | ||
| // cannot be used with enqueue_wait_event |
Comment on lines
62
to
+74
| detail::queue_impl &QueueImpl = *sycl::detail::getSyclObjImpl(q); | ||
| detail::event_impl &EventImpl = *sycl::detail::getSyclObjImpl(evt); | ||
|
|
||
| // Current limitation: | ||
| // The queue and an event need to be in the same context. The reason | ||
| // is, that cross-context dependencies use host tasks, and the wait | ||
| // command might be queued in the runtime. This flow is currently | ||
| // not supported by the Reusable Events APIs. | ||
| if (&QueueImpl.getContextImpl() != &EventImpl.getContextImpl()) { | ||
| throw sycl::exception( | ||
| sycl::make_error_code(errc::invalid), | ||
| "Not implemented yet. Event context must match the queue context."); | ||
| } |
Comment on lines
+85
to
+98
| // Current limitation: | ||
| // The queue and all the events need to be in the same context. The | ||
| // reason is, that cross-context dependencies use host tasks, and the | ||
| // wait command might be queued in the runtime. This flow is currently | ||
| // not supported by the Reusable Events APIs. | ||
| for (sycl::event evt : evts) { | ||
| detail::event_impl &EventImpl = *sycl::detail::getSyclObjImpl(evt); | ||
| if (&QueueImpl.getContextImpl() != &EventImpl.getContextImpl()) { | ||
| throw sycl::exception( | ||
| sycl::make_error_code(errc::invalid), | ||
| "Not implemented yet. Context of all events must match the " | ||
| "queue context."); | ||
| } | ||
| } |
Comment on lines
+618
to
631
| if (EventForReuse || !CallerNeedsEvent) { | ||
| // Current limitation: reusable events require scheduler bypass so that | ||
| // the barrier can be submitted directly to the backend with the reusable | ||
| // event's handle as the output event. Scheduler bypass is not possible | ||
| // when dependencies include host tasks or cross-context dependencies. | ||
| // | ||
| // This limitation applies to both: enqueue_signal_event and | ||
| // enqueue_wait_event(s). | ||
| // | ||
| // The !CallerNeedsEvent condition is used to detect the | ||
| // enqueue_wait_event(s) function calls. | ||
| throw sycl::exception(sycl::make_error_code(errc::invalid), | ||
| "An event cannot be enqueued for signaling behind " | ||
| "a command which is not enqueued in the backend."); |
the exception messages.
slawekptak
marked this pull request as draft
July 17, 2026 09:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, cross-context dependencies are not supported for the Reusable Events APIs.
Cross-context dependencies use host tasks internally, so the event wait might be queued behind the host task in the runtime, which is currently not supported by the extension APIs.