Skip to content

Commit 76dd39e

Browse files
[NFC][SYCL] Pass queue_impl by raw ptr/ref in event_impl.hpp
Part of the ongoing refactoring to prefer raw ptr/ref for SYCL RT objects by default with explicit `shared_from_this` when lifetimes need to be extended.
1 parent acbabef commit 76dd39e

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
248248
// queue is available with the wait events. We check to see if the
249249
// TraceEvent is available in the Queue object.
250250
void *TraceEvent = nullptr;
251-
if (QueueImplPtr Queue = MQueue.lock()) {
251+
if (auto Queue = MQueue.lock()) {
252252
TraceEvent = Queue->getTraceEvent();
253253
WaitEvent =
254254
(TraceEvent ? static_cast<xpti_td *>(TraceEvent) : GSYCLGraphEvent);
@@ -317,7 +317,7 @@ void event_impl::wait_and_throw(
317317
std::shared_ptr<sycl::detail::event_impl> Self) {
318318
wait(Self);
319319

320-
if (QueueImplPtr SubmittedQueue = MSubmittedQueue.lock())
320+
if (auto SubmittedQueue = MSubmittedQueue.lock())
321321
SubmittedQueue->throw_asynchronous();
322322
}
323323

@@ -462,7 +462,7 @@ event_impl::get_backend_info<info::platform::version>() const {
462462
"the info::platform::version info descriptor can "
463463
"only be queried with an OpenCL backend");
464464
}
465-
if (QueueImplPtr Queue = MQueue.lock()) {
465+
if (auto Queue = MQueue.lock()) {
466466
return Queue->getDeviceImpl()
467467
.get_platform()
468468
.get_info<info::platform::version>();
@@ -485,7 +485,7 @@ event_impl::get_backend_info<info::device::version>() const {
485485
"the info::device::version info descriptor can only "
486486
"be queried with an OpenCL backend");
487487
}
488-
if (QueueImplPtr Queue = MQueue.lock()) {
488+
if (auto Queue = MQueue.lock()) {
489489
return Queue->getDeviceImpl().get_info<info::device::version>();
490490
}
491491
return ""; // If the queue has been released, no device will be associated so
@@ -552,21 +552,21 @@ std::vector<EventImplPtr> event_impl::getWaitList() {
552552
return Result;
553553
}
554554

555-
void event_impl::flushIfNeeded(const QueueImplPtr &UserQueue) {
555+
void event_impl::flushIfNeeded(queue_impl *UserQueue) {
556556
// Some events might not have a native handle underneath even at this point,
557557
// e.g. those produced by memset with 0 size (no UR call is made).
558558
auto Handle = this->getHandle();
559559
if (MIsFlushed || !Handle)
560560
return;
561561

562-
QueueImplPtr Queue = MQueue.lock();
562+
auto Queue = MQueue.lock();
563563
// If the queue has been released, all of the commands have already been
564564
// implicitly flushed by urQueueRelease.
565565
if (!Queue) {
566566
MIsFlushed = true;
567567
return;
568568
}
569-
if (Queue == UserQueue)
569+
if (Queue.get() == UserQueue)
570570
return;
571571

572572
// Check if the task for this event has already been submitted.
@@ -604,9 +604,8 @@ void event_impl::setSubmissionTime() {
604604
if (!MIsProfilingEnabled && !MProfilingTagEvent)
605605
return;
606606

607-
std::weak_ptr<queue_impl> Queue = isHost() ? MSubmittedQueue : MQueue;
608-
if (QueueImplPtr QueuePtr = Queue.lock()) {
609-
device_impl &Device = QueuePtr->getDeviceImpl();
607+
if (auto Queue = isHost() ? MSubmittedQueue.lock() : MQueue.lock()) {
608+
device_impl &Device = Queue->getDeviceImpl();
610609
MSubmitTime = getTimestamp(&Device);
611610
}
612611
}

sycl/source/detail/event_impl.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class Adapter;
3131
class context_impl;
3232
using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;
3333
class queue_impl;
34-
using QueueImplPtr = std::shared_ptr<sycl::detail::queue_impl>;
3534
class event_impl;
3635
using EventImplPtr = std::shared_ptr<sycl::detail::event_impl>;
3736

@@ -242,7 +241,7 @@ class event_impl : public std::enable_shared_from_this<event_impl> {
242241
/// Performs a flush on the queue associated with this event if the user queue
243242
/// is different and the task associated with this event hasn't been submitted
244243
/// to the device yet.
245-
void flushIfNeeded(const QueueImplPtr &UserQueue);
244+
void flushIfNeeded(queue_impl *UserQueue);
246245

247246
/// Cleans dependencies of this event_impl.
248247
void cleanupDependencyEvents();
@@ -262,7 +261,9 @@ class event_impl : public std::enable_shared_from_this<event_impl> {
262261
///
263262
/// @return shared_ptr to MWorkerQueue, please be aware it can be empty
264263
/// pointer
265-
QueueImplPtr getWorkerQueue() { return MWorkerQueue.lock(); };
264+
std::shared_ptr<sycl::detail::queue_impl> getWorkerQueue() {
265+
return MWorkerQueue.lock();
266+
};
266267

267268
/// Sets worker queue for command.
268269
///
@@ -289,7 +290,9 @@ class event_impl : public std::enable_shared_from_this<event_impl> {
289290
/// @return Submission time for command associated with this event
290291
uint64_t getSubmissionTime();
291292

292-
QueueImplPtr getSubmittedQueue() const { return MSubmittedQueue.lock(); };
293+
std::shared_ptr<sycl::detail::queue_impl> getSubmittedQueue() const {
294+
return MSubmittedQueue.lock();
295+
};
293296

294297
/// Checks if this event is complete.
295298
///

sycl/source/detail/scheduler/commands.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,6 @@ bool Command::isFusable() const {
323323
}
324324
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
325325

326-
static void flushCrossQueueDeps(const std::vector<EventImplPtr> &EventImpls,
327-
const QueueImplPtr &Queue) {
328-
for (auto &EventImpl : EventImpls) {
329-
EventImpl->flushIfNeeded(Queue);
330-
}
331-
}
332-
333326
namespace {
334327

335328
struct EnqueueNativeCommandData {
@@ -553,7 +546,7 @@ void Command::waitForEvents(QueueImplPtr Queue,
553546
}
554547
} else {
555548
std::vector<ur_event_handle_t> RawEvents = getUrEvents(EventImpls);
556-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
549+
flushCrossQueueDeps(EventImpls);
557550
const AdapterPtr &Adapter = Queue->getAdapter();
558551

559552
Adapter->call<UrApiKind::urEnqueueEventsWait>(
@@ -1397,7 +1390,7 @@ ur_result_t MapMemObject::enqueueImp() {
13971390
waitForPreparedHostEvents();
13981391
std::vector<EventImplPtr> EventImpls = MPreparedDepsEvents;
13991392
std::vector<ur_event_handle_t> RawEvents = getUrEvents(EventImpls);
1400-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
1393+
flushCrossQueueDeps(EventImpls);
14011394

14021395
ur_event_handle_t UREvent = nullptr;
14031396
if (auto Result = callMemOpHelperRet(
@@ -1480,7 +1473,7 @@ ur_result_t UnMapMemObject::enqueueImp() {
14801473
waitForPreparedHostEvents();
14811474
std::vector<EventImplPtr> EventImpls = MPreparedDepsEvents;
14821475
std::vector<ur_event_handle_t> RawEvents = getUrEvents(EventImpls);
1483-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
1476+
flushCrossQueueDeps(EventImpls);
14841477

14851478
ur_event_handle_t UREvent = nullptr;
14861479
if (auto Result =
@@ -1590,7 +1583,7 @@ ur_result_t MemCpyCommand::enqueueImp() {
15901583
ur_event_handle_t UREvent = nullptr;
15911584

15921585
auto RawEvents = getUrEvents(EventImpls);
1593-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
1586+
flushCrossQueueDeps(EventImpls);
15941587

15951588
if (auto Result = callMemOpHelper(
15961589
MemoryManager::copy, MSrcAllocaCmd->getSYCLMemObj(),
@@ -1751,7 +1744,7 @@ ur_result_t MemCpyCommandHost::enqueueImp() {
17511744
return UR_RESULT_SUCCESS;
17521745
}
17531746

1754-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
1747+
flushCrossQueueDeps(EventImpls);
17551748

17561749
if (auto Result = callMemOpHelper(
17571750
MemoryManager::copy, MSrcAllocaCmd->getSYCLMemObj(),
@@ -2850,7 +2843,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() {
28502843
// submissions of the command buffer itself will not receive dependencies on
28512844
// them, e.g. initial copies from host to device
28522845
std::vector<EventImplPtr> EventImpls = MPreparedDepsEvents;
2853-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
2846+
flushCrossQueueDeps(EventImpls);
28542847
std::vector<ur_event_handle_t> RawEvents = getUrEvents(EventImpls);
28552848
if (!RawEvents.empty()) {
28562849
MQueue->getAdapter()->call<UrApiKind::urEventWait>(RawEvents.size(),
@@ -3130,7 +3123,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
31303123
waitForPreparedHostEvents();
31313124
std::vector<EventImplPtr> EventImpls = MPreparedDepsEvents;
31323125
auto RawEvents = getUrEvents(EventImpls);
3133-
flushCrossQueueDeps(EventImpls, MWorkerQueue);
3126+
flushCrossQueueDeps(EventImpls);
31343127

31353128
// We can omit creating a UR event and create a "discarded" event if the
31363129
// command has been explicitly marked as not needing an event, e.g. if the

sycl/source/detail/scheduler/commands.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ class Command {
272272

273273
void waitForPreparedHostEvents() const;
274274

275+
void flushCrossQueueDeps(const std::vector<EventImplPtr> &EventImpls) {
276+
for (auto &EventImpl : EventImpls) {
277+
EventImpl->flushIfNeeded(MWorkerQueue.get());
278+
}
279+
}
280+
275281
/// Perform glueing of events from different contexts
276282
/// \param DepEvent event this commands should depend on
277283
/// \param Dep optional DepDesc to perform connection of events properly

0 commit comments

Comments
 (0)