File tree Expand file tree Collapse file tree 6 files changed +31
-16
lines changed Expand file tree Collapse file tree 6 files changed +31
-16
lines changed Original file line number Diff line number Diff line change @@ -571,6 +571,9 @@ class __SYCL_EXPORT handler {
571
571
// / object destruction.
572
572
// /
573
573
// / \return a SYCL event object representing the command group
574
+ // /
575
+ // / Note: in preview mode, handler.finalize() is expected to return
576
+ // / nullptr if the event is not needed (discarded).
574
577
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
575
578
detail::EventImplPtr finalize ();
576
579
#else
Original file line number Diff line number Diff line change @@ -712,7 +712,11 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
712
712
}
713
713
714
714
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
715
- #define parseEvent (arg ) (arg)
715
+ inline const detail::EventImplPtr &
716
+ parseEvent (const detail::EventImplPtr &Event) {
717
+ assert (!Event || !Event->isDiscarded ());
718
+ return Event;
719
+ }
716
720
#else
717
721
inline detail::EventImplPtr parseEvent (const event &Event) {
718
722
const detail::EventImplPtr &EventImpl = getSyclObjImpl (Event);
Original file line number Diff line number Diff line change @@ -3122,22 +3122,17 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3122
3122
auto RawEvents = getUrEvents (EventImpls);
3123
3123
flushCrossQueueDeps (EventImpls);
3124
3124
3125
- // We can omit creating a UR event and create a "discarded" event if the
3126
- // command has been explicitly marked as not needing an event, e.g. if the
3127
- // user did not ask for one, and there are no requirements.
3128
- bool DiscardUrEvent = MQueue && !MEventNeeded &&
3129
- MQueue->supportsDiscardingPiEvents () &&
3130
- MCommandGroup->getRequirements ().size () == 0 ;
3131
-
3132
3125
ur_event_handle_t UREvent = nullptr ;
3133
- ur_event_handle_t *Event = DiscardUrEvent ? nullptr : &UREvent;
3134
- detail::event_impl *EventImpl = DiscardUrEvent ? nullptr : MEvent.get ();
3126
+ ur_event_handle_t *Event = !MEventNeeded ? nullptr : &UREvent;
3127
+ detail::event_impl *EventImpl = !MEventNeeded ? nullptr : MEvent.get ();
3135
3128
3136
3129
auto SetEventHandleOrDiscard = [&]() {
3137
- if (Event)
3130
+ if (!MEventNeeded) {
3131
+ assert (MEvent->isDiscarded ());
3132
+ } else {
3133
+ assert (!MEvent->isDiscarded ());
3138
3134
MEvent->setHandle (*Event);
3139
- else
3140
- MEvent->setStateDiscarded ();
3135
+ }
3141
3136
};
3142
3137
3143
3138
switch (MCommandGroup->getType ()) {
Original file line number Diff line number Diff line change @@ -133,6 +133,14 @@ EventImplPtr Scheduler::addCG(
133
133
}
134
134
NewEvent = NewCmd->getEvent ();
135
135
NewEvent->setSubmissionTime ();
136
+
137
+ // This is the last moment we can mark the event as discarded.
138
+ // Doing this during command execution would lead to incorrect
139
+ // event handling (as event would change it's state from non-discarded
140
+ // to discarded).
141
+ if (!EventNeeded) {
142
+ NewEvent->setStateDiscarded ();
143
+ }
136
144
}
137
145
138
146
enqueueCommandForCG (NewEvent, AuxiliaryCmds);
Original file line number Diff line number Diff line change @@ -376,7 +376,8 @@ class Scheduler {
376
376
// / directly to the queue.
377
377
// / \param Dependencies Optional list of dependency
378
378
// / sync points when enqueuing to a command buffer.
379
- // / \return an event object to wait on for command group completion.
379
+ // / \return an event object to wait on for command group completion. It can
380
+ // / be a discarded event.
380
381
EventImplPtr addCG (
381
382
std::unique_ptr<detail::CG> CommandGroup, const QueueImplPtr &Queue,
382
383
bool EventNeeded, ur_exp_command_buffer_handle_t CommandBuffer = nullptr ,
Original file line number Diff line number Diff line change @@ -894,11 +894,15 @@ event handler::finalize() {
894
894
#endif
895
895
}
896
896
897
+ bool DiscardEvent = !impl->MEventNeeded && Queue &&
898
+ Queue->supportsDiscardingPiEvents () &&
899
+ CommandGroup->getRequirements ().size () == 0 ;
900
+
897
901
detail::EventImplPtr Event = detail::Scheduler::getInstance ().addCG (
898
- std::move (CommandGroup), Queue->shared_from_this (), impl-> MEventNeeded );
902
+ std::move (CommandGroup), Queue->shared_from_this (), !DiscardEvent );
899
903
900
904
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
901
- MLastEvent = Event;
905
+ MLastEvent = DiscardEvent ? nullptr : Event;
902
906
#else
903
907
MLastEvent = detail::createSyclObjFromImpl<event>(Event);
904
908
#endif
You can’t perform that action at this time.
0 commit comments