Skip to content

Commit 252b37f

Browse files
[NFC][SYCL] Remove Self from event_impl::wait* (#19376)
1 parent 373a81c commit 252b37f

14 files changed

+36
-46
lines changed

sycl/source/detail/accessor_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void AccessorImplHost::resize(size_t GlobalSize) {
3636
void addHostAccessorAndWait(Requirement *Req) {
3737
detail::EventImplPtr Event =
3838
detail::Scheduler::getInstance().addHostAccessor(Req);
39-
Event->wait(Event);
39+
Event->wait();
4040
}
4141

4242
void addHostUnsampledImageAccessorAndWait(UnsampledImageAccessorImplHost *Req) {

sycl/source/detail/event_impl.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ void event_impl::waitInternal(bool *Success) {
8585

8686
// Wait for connected events(e.g. streams prints)
8787
for (const EventImplPtr &Event : MPostCompleteEvents)
88-
Event->wait(Event);
88+
Event->wait();
8989
for (const std::weak_ptr<event_impl> &WeakEventPtr :
9090
MWeakPostCompleteEvents) {
9191
if (EventImplPtr Event = WeakEventPtr.lock())
92-
Event->wait(Event);
92+
Event->wait();
9393
}
9494
}
9595

@@ -278,8 +278,7 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,
278278
#endif
279279
}
280280

281-
void event_impl::wait(std::shared_ptr<sycl::detail::event_impl> Self,
282-
bool *Success) {
281+
void event_impl::wait(bool *Success) {
283282
if (MState == HES_Discarded)
284283
throw sycl::exception(make_error_code(errc::invalid),
285284
"wait method cannot be used for a discarded event.");
@@ -304,16 +303,15 @@ void event_impl::wait(std::shared_ptr<sycl::detail::event_impl> Self,
304303
// need to go via the slow path event waiting in the scheduler
305304
waitInternal(Success);
306305
else if (MCommand)
307-
detail::Scheduler::getInstance().waitForEvent(Self, Success);
306+
detail::Scheduler::getInstance().waitForEvent(*this, Success);
308307

309308
#ifdef XPTI_ENABLE_INSTRUMENTATION
310309
instrumentationEpilog(TelemetryEvent, Name, StreamID, IId);
311310
#endif
312311
}
313312

314-
void event_impl::wait_and_throw(
315-
std::shared_ptr<sycl::detail::event_impl> Self) {
316-
wait(Self);
313+
void event_impl::wait_and_throw() {
314+
wait();
317315

318316
if (std::shared_ptr<queue_impl> SubmittedQueue = MSubmittedQueue.lock())
319317
SubmittedQueue->throw_asynchronous();

sycl/source/detail/event_impl.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,19 @@ class event_impl {
110110

111111
/// Waits for the event.
112112
///
113-
/// Self is needed in order to pass shared_ptr to Scheduler.
114-
///
115-
/// \param Self is a pointer to this event.
116113
/// \param Success is an optional parameter that, when set to a non-null
117114
/// pointer, indicates that failure is a valid outcome for this wait
118115
/// (e.g., in case of a non-blocking read from a pipe), and the value
119116
/// it's pointing to is then set according to the outcome.
120-
void wait(std::shared_ptr<sycl::detail::event_impl> Self,
121-
bool *Success = nullptr);
117+
void wait(bool *Success = nullptr);
122118

123119
/// Waits for the event.
124120
///
125121
/// If any uncaught asynchronous errors occurred on the context that the
126122
/// event is waiting on executions from, then call that context's
127123
/// asynchronous error handler with those errors. Self is needed in order to
128124
/// pass shared_ptr to Scheduler.
129-
///
130-
/// \param Self is a pointer to this event.
131-
void wait_and_throw(std::shared_ptr<sycl::detail::event_impl> Self);
125+
void wait_and_throw();
132126

133127
/// Queries this event for profiling information.
134128
///

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ void exec_graph_impl::update(
14901490
// needed because HostTask nodes (and all the nodes that depend on
14911491
// HostTasks), are scheduled using a separate thread. This wait call
14921492
// acts as a synchronization point for that thread.
1493-
UpdateEvent->wait(UpdateEvent);
1493+
UpdateEvent->wait();
14941494
}
14951495
} else {
14961496
// For each partition in the executable graph, call UR update on the

sycl/source/detail/pipes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ pipe_base::get_pipe_name_impl(const void *HostPipePtr) {
2929

3030
__SYCL_EXPORT bool pipe_base::wait_non_blocking(const event &E) {
3131
bool Success = false;
32-
std::shared_ptr<sycl::detail::event_impl> EImpl =
33-
sycl::detail::getSyclObjImpl(E);
34-
EImpl->wait(EImpl, &Success);
32+
sycl::detail::event_impl &EImpl = *sycl::detail::getSyclObjImpl(E);
33+
EImpl.wait(&Success);
3534
return Success;
3635
}
3736

sycl/source/detail/queue_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
626626
LastEvent = MDefaultGraphDeps.LastEventPtr;
627627
}
628628
if (LastEvent) {
629-
LastEvent->wait(LastEvent);
629+
LastEvent->wait();
630630
}
631631
} else if (!isInOrder()) {
632632
std::vector<std::weak_ptr<event_impl>> WeakEvents;
@@ -651,7 +651,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
651651
// A nullptr UR event indicates that urQueueFinish will not cover it,
652652
// either because it's a host task event or an unenqueued one.
653653
if (nullptr == EventImplSharedPtr->getHandle()) {
654-
EventImplSharedPtr->wait(EventImplSharedPtr);
654+
EventImplSharedPtr->wait();
655655
}
656656
}
657657
}
@@ -666,7 +666,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
666666
StreamsServiceEvents.swap(MStreamsServiceEvents);
667667
}
668668
for (const EventImplPtr &Event : StreamsServiceEvents)
669-
Event->wait(Event);
669+
Event->wait();
670670
}
671671

672672
#ifdef XPTI_ENABLE_INSTRUMENTATION

sycl/source/detail/scheduler/graph_processor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ namespace sycl {
1717
inline namespace _V1 {
1818
namespace detail {
1919

20-
void Scheduler::GraphProcessor::waitForEvent(const EventImplPtr &Event,
20+
void Scheduler::GraphProcessor::waitForEvent(event_impl &Event,
2121
ReadLockT &GraphReadLock,
2222
std::vector<Command *> &ToCleanUp,
2323
bool LockTheLock, bool *Success) {
24-
Command *Cmd = Event->getCommand();
24+
Command *Cmd = Event.getCommand();
2525
// Command can be nullptr if user creates sycl::event explicitly or the
2626
// event has been waited on by another thread
2727
if (!Cmd)
@@ -34,10 +34,10 @@ void Scheduler::GraphProcessor::waitForEvent(const EventImplPtr &Event,
3434
// TODO: Reschedule commands.
3535
throw exception(make_error_code(errc::runtime), "Enqueue process failed.");
3636

37-
assert(Cmd->getEvent() == Event);
37+
assert(Cmd->getEvent().get() == &Event);
3838

3939
GraphReadLock.unlock();
40-
Event->waitInternal(Success);
40+
Event.waitInternal(Success);
4141

4242
if (LockTheLock)
4343
GraphReadLock.lock();

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record,
6767
// Capture the dependencies
6868
DepCommands.insert(Cmd);
6969
#endif
70-
GraphProcessor::waitForEvent(Cmd->getEvent(), GraphReadLock, ToCleanUp);
70+
GraphProcessor::waitForEvent(*Cmd->getEvent(), GraphReadLock, ToCleanUp);
7171
}
7272
for (Command *Cmd : Record->MWriteLeaves) {
7373
if (Cmd->MEnqueueStatus == EnqueueResultT::SyclEnqueueFailed)
@@ -82,7 +82,7 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record,
8282
#ifdef XPTI_ENABLE_INSTRUMENTATION
8383
DepCommands.insert(Cmd);
8484
#endif
85-
GraphProcessor::waitForEvent(Cmd->getEvent(), GraphReadLock, ToCleanUp);
85+
GraphProcessor::waitForEvent(*Cmd->getEvent(), GraphReadLock, ToCleanUp);
8686
}
8787
for (AllocaCommandBase *AllocaCmd : Record->MAllocaCommands) {
8888
Command *ReleaseCmd = AllocaCmd->getReleaseCmd();
@@ -97,7 +97,7 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record,
9797
// reported as edges
9898
ReleaseCmd->resolveReleaseDependencies(DepCommands);
9999
#endif
100-
GraphProcessor::waitForEvent(ReleaseCmd->getEvent(), GraphReadLock,
100+
GraphProcessor::waitForEvent(*ReleaseCmd->getEvent(), GraphReadLock,
101101
ToCleanUp);
102102
}
103103
}
@@ -278,12 +278,12 @@ bool Scheduler::isInstanceAlive() {
278278
return GlobalHandler::instance().isSchedulerAlive();
279279
}
280280

281-
void Scheduler::waitForEvent(const EventImplPtr &Event, bool *Success) {
281+
void Scheduler::waitForEvent(event_impl &Event, bool *Success) {
282282
ReadLockT Lock = acquireReadLock();
283283
// It's fine to leave the lock unlocked upon return from waitForEvent as
284284
// there's no more actions to do here with graph
285285
std::vector<Command *> ToCleanUp;
286-
GraphProcessor::waitForEvent(std::move(Event), Lock, ToCleanUp,
286+
GraphProcessor::waitForEvent(Event, Lock, ToCleanUp,
287287
/*LockTheLock=*/false, Success);
288288
cleanupCommands(ToCleanUp);
289289
}

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class Scheduler {
404404
/// (e.g., in case of a non-blocking read from a pipe), and the value
405405
/// it's pointing to is then set according to the outcome.
406406

407-
void waitForEvent(const EventImplPtr &Event, bool *Success = nullptr);
407+
void waitForEvent(event_impl &Event, bool *Success = nullptr);
408408

409409
/// Removes buffer from the graph.
410410
///
@@ -831,8 +831,7 @@ class Scheduler {
831831
///
832832
/// The function may unlock and lock GraphReadLock as needed. Upon return
833833
/// the lock is left in locked state if and only if LockTheLock is true.
834-
static void waitForEvent(const EventImplPtr &Event,
835-
ReadLockT &GraphReadLock,
834+
static void waitForEvent(event_impl &Event, ReadLockT &GraphReadLock,
836835
std::vector<Command *> &ToCleanUp,
837836
bool LockTheLock = true, bool *Success = nullptr);
838837

sycl/source/detail/sycl_mem_obj_t.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void SYCLMemObjT::updateHostMemory(void *const Ptr) {
137137

138138
EventImplPtr Event = Scheduler::getInstance().addCopyBack(&Req);
139139
if (Event)
140-
Event->wait(Event);
140+
Event->wait();
141141
}
142142

143143
void SYCLMemObjT::updateHostMemory() {

0 commit comments

Comments
 (0)