@@ -461,12 +461,44 @@ detail::EventImplPtr queue_impl::submit_kernel_direct_impl(
461461 std::vector<detail::ArgDesc> Args;
462462 bool DiscardEvent = !CallerNeedsEvent && supportsDiscardingPiEvents ();
463463
464- bool SchedulerBypass = detail::Scheduler::areEventsSafeForSchedulerBypass (
465- CGData.MEvents , getContextImpl ());
464+ bool SchedulerBypass = std::all_of (CGData.MEvents .begin (), CGData.MEvents .end (),
465+ [&](EventImplPtr &Event) {
466+ // Events that don't have an initialized context are throwaway events that
467+ // don't represent actual dependencies. Calling getContextImpl() would set
468+ // their context, which we wish to avoid as it is expensive.
469+ // NOP events also don't represent actual dependencies.
470+ if (Event->isDefaultConstructed () || Event->isNOP ())
471+ return true ;
472+
473+ if (Event->isHost ())
474+ return Event->isCompleted ();
475+
476+ // Cross-context dependencies can't be passed to the backend directly.
477+ if (&Event->getContextImpl () != &getContextImpl ())
478+ return false ;
479+
480+ // A nullptr here means that the commmand does not produce a UR event or it
481+ // hasn't been enqueued yet.
482+ return Event->getHandle () != nullptr ;
483+ });
466484
467485 if (SchedulerBypass) {
468- std::vector<ur_event_handle_t > RawEvents =
469- detail::Command::getUrEvents (CGData.MEvents , this , false );
486+ std::vector<ur_event_handle_t > RawEvents;
487+
488+ for (EventImplPtr &Event : CGData.MEvents ) {
489+ auto Handle = Event->getHandle ();
490+ if (Handle == nullptr )
491+ continue ;
492+
493+ // Do not add redundant event dependencies for in-order queues.
494+ // At this stage dependency is definitely ur task and need to check if
495+ // current one is a host task. In this case we should not skip ur event due
496+ // to different sync mechanisms for different task types on in-order queue.
497+ if (Event->getWorkerQueue ().get () == this && isInOrder ())
498+ continue ;
499+
500+ RawEvents.push_back (Handle);
501+ }
470502
471503 std::shared_ptr<detail::event_impl> ResultEvent =
472504 DiscardEvent ? nullptr
0 commit comments