Skip to content

[SYCL] Reusable Events limitation for cross-context dependencies.#22639

Draft
slawekptak wants to merge 2 commits into
intel:syclfrom
slawekptak:ext_reusable_events_impl_limit_cross_context_wait
Draft

[SYCL] Reusable Events limitation for cross-context dependencies.#22639
slawekptak wants to merge 2 commits into
intel:syclfrom
slawekptak:ext_reusable_events_impl_limit_cross_context_wait

Conversation

@slawekptak

Copy link
Copy Markdown
Contributor

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.

@slawekptak
slawekptak requested a review from a team as a code owner July 15, 2026 09:08
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.
Comment thread sycl/source/reusable_events.cpp
Comment thread sycl/unittests/Extensions/ReusableEvents.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, throwing sycl::errc::invalid for 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_impl to 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.");
@slawekptak
slawekptak marked this pull request as draft July 17, 2026 09:51
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.

3 participants