Skip to content

Commit ab2a122

Browse files
[NFCI][SYCL] Prefer raw ptr/ref for queue_impl
1 parent acbabef commit ab2a122

39 files changed

+347
-367
lines changed

sycl/source/detail/cg.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,11 @@ class CGHostTask : public CG {
725725
std::shared_ptr<detail::context_impl> MContext;
726726
std::vector<ArgDesc> MArgs;
727727

728-
CGHostTask(std::shared_ptr<HostTask> HostTask,
729-
std::shared_ptr<detail::queue_impl> Queue,
728+
// TODO: ref?
729+
CGHostTask(std::shared_ptr<HostTask> HostTask, detail::queue_impl *Queue,
730730
std::shared_ptr<detail::context_impl> Context,
731731
std::vector<ArgDesc> Args, CG::StorageInitHelper CGData,
732-
CGType Type, detail::code_location loc = {})
733-
: CG(Type, std::move(CGData), std::move(loc)),
734-
MHostTask(std::move(HostTask)), MQueue(Queue), MContext(Context),
735-
MArgs(std::move(Args)) {}
732+
CGType Type, detail::code_location loc = {});
736733
};
737734

738735
} // namespace detail

sycl/source/detail/event_impl.cpp

Lines changed: 10 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,9 @@ 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 (std::shared_ptr<queue_impl> Queue =
608+
isHost() ? MSubmittedQueue.lock() : MQueue.lock()) {
609+
device_impl &Device = Queue->getDeviceImpl();
610610
MSubmitTime = getTimestamp(&Device);
611611
}
612612
}

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/graph_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ exec_graph_impl::enqueueNode(ur_exp_command_buffer_handle_t CommandBuffer,
901901

902902
sycl::detail::EventImplPtr Event =
903903
sycl::detail::Scheduler::getInstance().addCG(
904-
Node->getCGCopy(), MQueueImpl,
904+
Node->getCGCopy(), *MQueueImpl,
905905
/*EventNeeded=*/true, CommandBuffer, Deps);
906906

907907
if (MIsUpdatable) {
@@ -1120,7 +1120,7 @@ exec_graph_impl::enqueue(sycl::detail::queue_impl &Queue,
11201120
CommandBuffer, nullptr, std::move(CGData));
11211121

11221122
NewEvent = sycl::detail::Scheduler::getInstance().addCG(
1123-
std::move(CommandGroup), Queue.shared_from_this(),
1123+
std::move(CommandGroup), Queue,
11241124
/*EventNeeded=*/true);
11251125
}
11261126
NewEvent->setEventFromSubmittedExecCommandBuffer(true);
@@ -1140,7 +1140,7 @@ exec_graph_impl::enqueue(sycl::detail::queue_impl &Queue,
11401140
.MQueue = Queue.shared_from_this();
11411141

11421142
NewEvent = sycl::detail::Scheduler::getInstance().addCG(
1143-
NodeImpl->getCGCopy(), Queue.shared_from_this(),
1143+
NodeImpl->getCGCopy(), Queue,
11441144
/*EventNeeded=*/true);
11451145
}
11461146
PartitionsExecutionEvents[CurrentPartition] = NewEvent;
@@ -1422,7 +1422,7 @@ void exec_graph_impl::update(
14221422
// other scheduler commands
14231423
auto UpdateEvent =
14241424
sycl::detail::Scheduler::getInstance().addCommandGraphUpdate(
1425-
this, Nodes, MQueueImpl, std::move(UpdateRequirements),
1425+
this, Nodes, MQueueImpl.get(), std::move(UpdateRequirements),
14261426
MExecutionEvents);
14271427

14281428
MExecutionEvents.push_back(UpdateEvent);

sycl/source/detail/graph_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
288288

289289
return std::make_unique<sycl::detail::CGHostTask>(
290290
sycl::detail::CGHostTask(
291-
std::move(HostTaskSPtr), CommandGroupPtr->MQueue,
291+
std::move(HostTaskSPtr), CommandGroupPtr->MQueue.get(),
292292
CommandGroupPtr->MContext, std::move(NewArgs), std::move(Data),
293293
CommandGroupPtr->getType(), Loc));
294294
}

sycl/source/detail/helpers.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class event;
2121
namespace detail {
2222
class CGExecKernel;
2323
class queue_impl;
24-
using QueueImplPtr = std::shared_ptr<sycl::detail::queue_impl>;
2524
class RTDeviceBinaryImage;
2625

2726
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES

sycl/source/detail/memory_manager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class queue_impl;
2828
class event_impl;
2929
class context_impl;
3030

31-
using QueueImplPtr = std::shared_ptr<detail::queue_impl>;
3231
using EventImplPtr = std::shared_ptr<detail::event_impl>;
3332

3433
// The class contains methods that work with memory. All operations with

sycl/source/detail/queue_impl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ queue_impl::get_backend_info<info::device::backend_version>() const {
118118
}
119119
#endif
120120

121-
static event prepareSYCLEventAssociatedWithQueue(
122-
const std::shared_ptr<detail::queue_impl> &QueueImpl) {
123-
auto EventImpl = detail::event_impl::create_device_event(*QueueImpl);
124-
EventImpl->setContextImpl(detail::getSyclObjImpl(QueueImpl->get_context()));
121+
static event
122+
prepareSYCLEventAssociatedWithQueue(detail::queue_impl &QueueImpl) {
123+
auto EventImpl = detail::event_impl::create_device_event(QueueImpl);
124+
EventImpl->setContextImpl(QueueImpl.getContextImplPtr());
125125
EventImpl->setStateIncomplete();
126126
return detail::createSyclObjFromImpl<event>(EventImpl);
127127
}
@@ -461,7 +461,7 @@ event queue_impl::submitMemOpHelper(const std::vector<event> &DepEvents,
461461
event_impl::create_discarded_event());
462462
}
463463

464-
event ResEvent = prepareSYCLEventAssociatedWithQueue(shared_from_this());
464+
event ResEvent = prepareSYCLEventAssociatedWithQueue(*this);
465465
const auto &EventImpl = detail::getSyclObjImpl(ResEvent);
466466
{
467467
NestedCallsTracker tracker;

sycl/source/detail/queue_impl.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,12 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
650650
// for in order ones.
651651
void revisitUnenqueuedCommandsState(const EventImplPtr &CompletedHostTask);
652652

653-
static ContextImplPtr getContext(const QueueImplPtr &Queue) {
653+
static ContextImplPtr getContext(queue_impl *Queue) {
654654
return Queue ? Queue->getContextImplPtr() : nullptr;
655655
}
656+
static ContextImplPtr getContext(const std::shared_ptr<queue_impl> &Queue) {
657+
return getContext(Queue.get());
658+
}
656659

657660
// Must be called under MMutex protection
658661
void doUnenqueuedCommandCleanup(
@@ -689,7 +692,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
689692
protected:
690693
template <typename HandlerType = handler>
691694
EventImplPtr insertHelperBarrier(const HandlerType &Handler) {
692-
auto &Queue = Handler.impl->get_queue();
695+
queue_impl &Queue = Handler.impl->get_queue();
693696
auto ResEvent = detail::event_impl::create_device_event(Queue);
694697
ur_event_handle_t UREvent = nullptr;
695698
getAdapter()->call<UrApiKind::urEnqueueEventsWaitWithBarrier>(

0 commit comments

Comments
 (0)