Skip to content

Commit b762423

Browse files
authored
[SYCL][NFC] Avoid unnecessary calls to event-related functions (#20163)
Due to an inefficiency in how the event-related functions are called, there is overhead even if the events vector is empty. This is a temporary fix, to avoid the call if not needed.
1 parent 478c205 commit b762423

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

sycl/source/handler.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,15 @@ event handler::finalize() {
508508
detail::queue_impl *Queue = impl->get_queue_or_null();
509509
ext::oneapi::experimental::detail::graph_impl *Graph =
510510
impl->get_graph_or_null();
511+
512+
// TODO checking the size of the events vector and avoiding the call is more
513+
// efficient here at this point
511514
const bool KernelFastPath =
512515
(Queue && !Graph && !impl->MSubgraphNode && !Queue->hasCommandGraph() &&
513516
!impl->CGData.MRequirements.size() && !MStreamStorage.size() &&
514-
detail::Scheduler::areEventsSafeForSchedulerBypass(
515-
impl->CGData.MEvents, Queue->getContextImpl()));
517+
(impl->CGData.MEvents.size() == 0 ||
518+
detail::Scheduler::areEventsSafeForSchedulerBypass(
519+
impl->CGData.MEvents, Queue->getContextImpl())));
516520

517521
// Extract arguments from the kernel lambda, if required.
518522
// Skipping this is currently limited to simple kernels on the fast path.
@@ -634,8 +638,13 @@ event handler::finalize() {
634638
// the graph is not changed, then this faster path is used to submit
635639
// kernel bypassing scheduler and avoiding CommandGroup, Command objects
636640
// creation.
637-
std::vector<ur_event_handle_t> RawEvents = detail::Command::getUrEvents(
638-
impl->CGData.MEvents, impl->get_queue_or_null(), false);
641+
std::vector<ur_event_handle_t> RawEvents;
642+
// TODO checking the size of the events vector and avoiding the call is
643+
// more efficient here at this point
644+
if (impl->CGData.MEvents.size() > 0) {
645+
RawEvents = detail::Command::getUrEvents(
646+
impl->CGData.MEvents, impl->get_queue_or_null(), false);
647+
}
639648

640649
bool DiscardEvent =
641650
!impl->MEventNeeded && impl->get_queue().supportsDiscardingPiEvents();

0 commit comments

Comments
 (0)