Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class event_impl {
/// Clear the event state
void setStateIncomplete();

/// Set state as discarded.
void setStateDiscarded() { MState = HES_Discarded; }

/// Returns command that is associated with the event.
///
/// Scheduler mutex must be locked in read mode when this is called.
Expand Down
28 changes: 24 additions & 4 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,24 @@ event queue_impl::submit_impl(const std::function<void(handler &)> &CGF,
template <typename HandlerFuncT>
event queue_impl::submitWithHandler(const std::shared_ptr<queue_impl> &Self,
const std::vector<event> &DepEvents,
bool CallerNeedsEvent,
HandlerFuncT HandlerFunc) {
return submit(
SubmissionInfo SI{};
if (!CallerNeedsEvent && supportsDiscardingPiEvents()) {
submit_without_event(
[&](handler &CGH) {
CGH.depends_on(DepEvents);
HandlerFunc(CGH);
},
Self, SI, /*CodeLoc*/ {}, /*IsTopCodeLoc*/ true);
return createDiscardedEvent();
}
return submit_with_event(
[&](handler &CGH) {
CGH.depends_on(DepEvents);
HandlerFunc(CGH);
},
Self, /*CodeLoc*/ {}, /*SubmissionInfo*/ {}, /*IsTopCodeLoc*/ true);
Self, SI, /*CodeLoc*/ {}, /*IsTopCodeLoc*/ true);
}

template <typename HandlerFuncT, typename MemOpFuncT, typename... MemOpArgTs>
Expand Down Expand Up @@ -446,7 +457,16 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
NestedCallsTracker tracker;
MemOpFunc(MemOpArgs..., getUrEvents(ExpandedDepEvents),
/*PiEvent*/ nullptr, /*EventImplPtr*/ nullptr);
return createDiscardedEvent();

event DiscardedEvent = createDiscardedEvent();
if (isInOrder()) {
// Store the discarded event for proper in-order dependency tracking.
auto &EventToStoreIn = MGraph.expired()
? MDefaultGraphDeps.LastEventPtr
: MExtGraphDeps.LastEventPtr;
EventToStoreIn = detail::getSyclObjImpl(DiscardedEvent);
}
return DiscardedEvent;
}

event ResEvent = prepareSYCLEventAssociatedWithQueue(Self);
Expand All @@ -471,7 +491,7 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
return discard_or_return(ResEvent);
}
}
return submitWithHandler(Self, DepEvents, HandlerFunc);
return submitWithHandler(Self, DepEvents, CallerNeedsEvent, HandlerFunc);
}

void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ class queue_impl {
template <typename HandlerFuncT>
event submitWithHandler(const std::shared_ptr<queue_impl> &Self,
const std::vector<event> &DepEvents,
HandlerFuncT HandlerFunc);
bool CallerNeedsEvent, HandlerFuncT HandlerFunc);

/// Performs submission of a memory operation directly if scheduler can be
/// bypassed, or with a handler otherwise.
Expand Down
6 changes: 5 additions & 1 deletion sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking,
EnqueueResultT(EnqueueResultT::SyclEnqueueFailed, this, Res);
else {
MEvent->setEnqueued();
if (MShouldCompleteEventIfPossible &&
if (MShouldCompleteEventIfPossible && !MEvent->isDiscarded() &&
(MEvent->isHost() || MEvent->getHandle() == nullptr))
MEvent->setComplete();

Expand Down Expand Up @@ -3055,6 +3055,10 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
ur_event_handle_t *Event = DiscardUrEvent ? nullptr : &UREvent;
detail::EventImplPtr EventImpl = DiscardUrEvent ? nullptr : MEvent;

// If we are discarding the UR event, we also need to mark the result event.
if (DiscardUrEvent)
MEvent->setStateDiscarded();

switch (MCommandGroup->getType()) {

case CGType::UpdateHost: {
Expand Down
53 changes: 53 additions & 0 deletions sycl/unittests/Extensions/EnqueueFunctionsEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// Tests the behavior of enqueue free functions when events can be discarded.

#include "detail/event_impl.hpp"
#include "detail/queue_impl.hpp"
#include "sycl/platform.hpp"
#include <helpers/TestKernel.hpp>
#include <helpers/UrMock.hpp>
Expand Down Expand Up @@ -107,6 +109,13 @@ class EnqueueFunctionsEventsTests : public ::testing::Test {
queue Q;
};

inline void CheckLastEventDiscarded(sycl::queue &Q) {
auto QueueImplPtr = sycl::detail::getSyclObjImpl(Q);
event LastEvent = QueueImplPtr->getLastEvent();
auto LastEventImplPtr = sycl::detail::getSyclObjImpl(LastEvent);
ASSERT_TRUE(LastEventImplPtr->isDiscarded());
}

TEST_F(EnqueueFunctionsEventsTests, SubmitSingleTaskNoEvent) {
mock::getCallbacks().set_replace_callback("urEnqueueKernelLaunch",
&redefined_urEnqueueKernelLaunch);
Expand All @@ -116,6 +125,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitSingleTaskNoEvent) {
});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SingleTaskShortcutNoEvent) {
Expand All @@ -125,6 +136,8 @@ TEST_F(EnqueueFunctionsEventsTests, SingleTaskShortcutNoEvent) {
oneapiext::single_task<TestKernel<>>(Q, []() {});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SubmitSingleTaskKernelNoEvent) {
Expand All @@ -144,6 +157,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitSingleTaskKernelNoEvent) {
[&](handler &CGH) { oneapiext::single_task(CGH, Kernel); });

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SingleTaskShortcutKernelNoEvent) {
Expand All @@ -163,6 +178,8 @@ TEST_F(EnqueueFunctionsEventsTests, SingleTaskShortcutKernelNoEvent) {
oneapiext::single_task(Q, Kernel);

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SubmitRangeParallelForNoEvent) {
Expand All @@ -174,6 +191,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitRangeParallelForNoEvent) {
});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, RangeParallelForShortcutNoEvent) {
Expand All @@ -183,6 +202,8 @@ TEST_F(EnqueueFunctionsEventsTests, RangeParallelForShortcutNoEvent) {
oneapiext::parallel_for<TestKernel<>>(Q, range<1>{32}, [](item<1>) {});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SubmitRangeParallelForKernelNoEvent) {
Expand All @@ -203,6 +224,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitRangeParallelForKernelNoEvent) {
});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, RangeParallelForShortcutKernelNoEvent) {
Expand All @@ -222,6 +245,8 @@ TEST_F(EnqueueFunctionsEventsTests, RangeParallelForShortcutKernelNoEvent) {
oneapiext::parallel_for(Q, range<1>{32}, Kernel);

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SubmitNDLaunchNoEvent) {
Expand All @@ -234,6 +259,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitNDLaunchNoEvent) {
});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, NDLaunchShortcutNoEvent) {
Expand All @@ -244,6 +271,8 @@ TEST_F(EnqueueFunctionsEventsTests, NDLaunchShortcutNoEvent) {
[](nd_item<1>) {});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SubmitNDLaunchKernelNoEvent) {
Expand All @@ -264,6 +293,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitNDLaunchKernelNoEvent) {
});

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, NDLaunchShortcutKernelNoEvent) {
Expand All @@ -283,6 +314,8 @@ TEST_F(EnqueueFunctionsEventsTests, NDLaunchShortcutKernelNoEvent) {
oneapiext::nd_launch(Q, nd_range<1>{range<1>{32}, range<1>{32}}, Kernel);

ASSERT_EQ(counter_urEnqueueKernelLaunch, size_t{1});

CheckLastEventDiscarded(Q);
}

TEST_F(EnqueueFunctionsEventsTests, SubmitMemcpyNoEvent) {
Expand All @@ -299,6 +332,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitMemcpyNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueMemcpy, size_t{1});

CheckLastEventDiscarded(Q);

free(Src, Q);
free(Dst, Q);
}
Expand All @@ -315,6 +350,8 @@ TEST_F(EnqueueFunctionsEventsTests, MemcpyShortcutNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueMemcpy, size_t{1});

CheckLastEventDiscarded(Q);

free(Src, Q);
free(Dst, Q);
}
Expand All @@ -332,6 +369,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitCopyNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueMemcpy, size_t{1});

CheckLastEventDiscarded(Q);

free(Src, Q);
free(Dst, Q);
}
Expand All @@ -348,6 +387,8 @@ TEST_F(EnqueueFunctionsEventsTests, CopyShortcutNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueMemcpy, size_t{1});

CheckLastEventDiscarded(Q);

free(Src, Q);
free(Dst, Q);
}
Expand All @@ -365,6 +406,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitMemsetNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueFill, size_t{1});

CheckLastEventDiscarded(Q);

free(Dst, Q);
}

Expand All @@ -379,6 +422,8 @@ TEST_F(EnqueueFunctionsEventsTests, MemsetShortcutNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueFill, size_t{1});

CheckLastEventDiscarded(Q);

free(Dst, Q);
}

Expand All @@ -394,6 +439,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitPrefetchNoEvent) {

ASSERT_EQ(counter_urUSMEnqueuePrefetch, size_t{1});

CheckLastEventDiscarded(Q);

free(Dst, Q);
}

Expand All @@ -408,6 +455,8 @@ TEST_F(EnqueueFunctionsEventsTests, PrefetchShortcutNoEvent) {

ASSERT_EQ(counter_urUSMEnqueuePrefetch, size_t{1});

CheckLastEventDiscarded(Q);

free(Dst, Q);
}

Expand All @@ -424,6 +473,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitMemAdviseNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueMemAdvise, size_t{1});

CheckLastEventDiscarded(Q);

free(Dst, Q);
}

Expand All @@ -438,6 +489,8 @@ TEST_F(EnqueueFunctionsEventsTests, MemAdviseShortcutNoEvent) {

ASSERT_EQ(counter_urUSMEnqueueMemAdvise, size_t{1});

CheckLastEventDiscarded(Q);

free(Dst, Q);
}

Expand Down