[SYCL] Remove redundant creation of discarded events#21571
[SYCL] Remove redundant creation of discarded events#21571sergey-semenov wants to merge 4 commits intointel:syclfrom
Conversation
Creation of discarded events introduces significant overhead, which is why the corresponding extension has been dropped in favor of sycl_ext_oneapi_enqueue_functions.
There was a problem hiding this comment.
Pull request overview
This PR removes redundant creation of “discarded” sycl::event objects (previously used when callers did not need a usable event), reducing overhead and aligning the implementation with sycl_ext_oneapi_enqueue_functions.
Changes:
- Refactor USM memory ops in
queue_implto returnEventImplPtr(nullable when the caller doesn’t need an event), and wrap intosycl::eventat thequeueAPI boundary. - Update internal submission helpers to avoid manufacturing discarded events for in-order submissions.
- Remove
event_impl::create_discarded_event().
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sycl/source/queue.cpp | Adds a small helper to wrap EventImplPtr into sycl::event for public queue memory-op APIs. |
| sycl/source/detail/queue_impl.hpp | Changes memory-op and helper submission APIs to return EventImplPtr instead of sycl::event. |
| sycl/source/detail/queue_impl.cpp | Implements nullable EventImplPtr returns and removes discarded-event creation in helper submission paths. |
| sycl/source/detail/event_impl.hpp | Removes the discarded-event factory function. |
| /// \param CallerNeedsEvent specifies if the caller expects a usable event. | ||
| /// \return an event representing fill operation. | ||
| event memset(void *Ptr, int Value, size_t Count, | ||
| const std::vector<event> &DepEvents, bool CallerNeedsEvent); | ||
| EventImplPtr memset(void *Ptr, int Value, size_t Count, | ||
| const std::vector<event> &DepEvents, | ||
| bool CallerNeedsEvent); |
There was a problem hiding this comment.
The doxygen for memset/memcpy/mem_advise still reads as if a (non-null) event is always returned, but these functions now return EventImplPtr and can return nullptr when CallerNeedsEvent is false. Please update the "\return"/API comment to explicitly document the nullptr behavior so internal callers know they must handle it.
| // TODO Avoid event creation in the first place if it's not needed | ||
| return CallerNeedsEvent ? EventImpl : nullptr; |
There was a problem hiding this comment.
In queue_impl::submit_impl(), the new "return CallerNeedsEvent ? EventImpl : nullptr" only applies to the main path; the earlier noLastEventPath branch returns finalizeHandlerInOrderNoEventsUnlocked(Handler) directly, which can still yield a non-null EventImplPtr even when CallerNeedsEvent=false. This can violate the CallerNeedsEvent contract and can trip the assert in submitWithHandler() (ReturnEvent==false but submit_impl returns a non-null pointer). Consider routing the noLastEventPath through the same tail return logic (or at least applying the same CallerNeedsEvent filtering there).
Creation of discarded events introduces significant overhead, which is why the corresponding extension has been dropped in favor of sycl_ext_oneapi_enqueue_functions.