Skip to content

Commit 51ca072

Browse files
[NFC][SYCL] enable_shared_from_this for queue_impl
No need to pass an ugly `Self` in multiple methods after this. Further simplifications enabled by this change are left for subsequent PRs.
1 parent 97fed15 commit 51ca072

File tree

11 files changed

+132
-142
lines changed

11 files changed

+132
-142
lines changed

sycl/gdb/libsycl.so-gdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class SYCLQueue(SYCLValue):
432432
"""Provides information about a sycl::queue from a gdb.Value."""
433433

434434
DEVICE_TYPE_NAME = "sycl::_V1::device"
435-
IMPL_OFFSET_TO_DEVICE = 0x28
435+
IMPL_OFFSET_TO_DEVICE = 0x38
436436

437437
def __init__(self, gdb_value):
438438
super().__init__(gdb_value)

sycl/source/backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ __SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
158158
&UrQueue);
159159
// Construct the SYCL queue from UR queue.
160160
return detail::createSyclObjFromImpl<queue>(
161-
std::make_shared<queue_impl>(UrQueue, ContextImpl, Handler, PropList));
161+
queue_impl::create(UrQueue, ContextImpl, Handler, PropList));
162162
}
163163

164164
__SYCL_EXPORT event make_event(ur_native_handle_t NativeHandle,

sycl/source/detail/graph_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ exec_graph_impl::exec_graph_impl(sycl::context Context,
945945
const std::shared_ptr<graph_impl> &GraphImpl,
946946
const property_list &PropList)
947947
: MSchedule(), MGraphImpl(GraphImpl), MSyncPoints(),
948-
MQueueImpl(std::make_shared<sycl::detail::queue_impl>(
948+
MQueueImpl(sycl::detail::queue_impl::create(
949949
*sycl::detail::getSyclObjImpl(GraphImpl->getDevice()),
950950
sycl::detail::getSyclObjImpl(Context), sycl::async_handler{},
951951
sycl::property_list{})),

sycl/source/detail/queue_impl.cpp

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ queue_impl::getExtendDependencyList(const std::vector<event> &DepEvents,
151151
return MutableVec;
152152
}
153153

154-
event queue_impl::memset(const std::shared_ptr<detail::queue_impl> &Self,
155-
void *Ptr, int Value, size_t Count,
154+
event queue_impl::memset(void *Ptr, int Value, size_t Count,
156155
const std::vector<event> &DepEvents,
157156
bool CallerNeedsEvent) {
158157
#if XPTI_ENABLE_INSTRUMENTATION
@@ -180,7 +179,7 @@ event queue_impl::memset(const std::shared_ptr<detail::queue_impl> &Self,
180179
#endif
181180
const std::vector<unsigned char> Pattern{static_cast<unsigned char>(Value)};
182181
return submitMemOpHelper(
183-
Self, DepEvents, CallerNeedsEvent,
182+
DepEvents, CallerNeedsEvent,
184183
[&](handler &CGH) { CGH.memset(Ptr, Value, Count); },
185184
MemoryManager::fill_usm, Ptr, *this, Count, Pattern);
186185
}
@@ -198,8 +197,7 @@ void report(const code_location &CodeLoc) {
198197
std::cout << '\n';
199198
}
200199

201-
event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
202-
void *Dest, const void *Src, size_t Count,
200+
event queue_impl::memcpy(void *Dest, const void *Src, size_t Count,
203201
const std::vector<event> &DepEvents,
204202
bool CallerNeedsEvent, const code_location &CodeLoc) {
205203
#if XPTI_ENABLE_INSTRUMENTATION
@@ -231,28 +229,28 @@ event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
231229
"NULL pointer argument in memory copy operation.");
232230
}
233231
return submitMemOpHelper(
234-
Self, DepEvents, CallerNeedsEvent,
232+
DepEvents, CallerNeedsEvent,
235233
[&](handler &CGH) { CGH.memcpy(Dest, Src, Count); },
236234
MemoryManager::copy_usm, Src, *this, Count, Dest);
237235
}
238236

239-
event queue_impl::mem_advise(const std::shared_ptr<detail::queue_impl> &Self,
240-
const void *Ptr, size_t Length,
237+
event queue_impl::mem_advise(const void *Ptr, size_t Length,
241238
ur_usm_advice_flags_t Advice,
242239
const std::vector<event> &DepEvents,
243240
bool CallerNeedsEvent) {
244241
return submitMemOpHelper(
245-
Self, DepEvents, CallerNeedsEvent,
242+
DepEvents, CallerNeedsEvent,
246243
[&](handler &CGH) { CGH.mem_advise(Ptr, Length, Advice); },
247244
MemoryManager::advise_usm, Ptr, *this, Length, Advice);
248245
}
249246

250-
event queue_impl::memcpyToDeviceGlobal(
251-
const std::shared_ptr<detail::queue_impl> &Self, void *DeviceGlobalPtr,
252-
const void *Src, bool IsDeviceImageScope, size_t NumBytes, size_t Offset,
253-
const std::vector<event> &DepEvents, bool CallerNeedsEvent) {
247+
event queue_impl::memcpyToDeviceGlobal(void *DeviceGlobalPtr, const void *Src,
248+
bool IsDeviceImageScope, size_t NumBytes,
249+
size_t Offset,
250+
const std::vector<event> &DepEvents,
251+
bool CallerNeedsEvent) {
254252
return submitMemOpHelper(
255-
Self, DepEvents, CallerNeedsEvent,
253+
DepEvents, CallerNeedsEvent,
256254
[&](handler &CGH) {
257255
CGH.memcpyToDeviceGlobal(DeviceGlobalPtr, Src, IsDeviceImageScope,
258256
NumBytes, Offset);
@@ -261,12 +259,14 @@ event queue_impl::memcpyToDeviceGlobal(
261259
*this, NumBytes, Offset, Src);
262260
}
263261

264-
event queue_impl::memcpyFromDeviceGlobal(
265-
const std::shared_ptr<detail::queue_impl> &Self, void *Dest,
266-
const void *DeviceGlobalPtr, bool IsDeviceImageScope, size_t NumBytes,
267-
size_t Offset, const std::vector<event> &DepEvents, bool CallerNeedsEvent) {
262+
event queue_impl::memcpyFromDeviceGlobal(void *Dest,
263+
const void *DeviceGlobalPtr,
264+
bool IsDeviceImageScope,
265+
size_t NumBytes, size_t Offset,
266+
const std::vector<event> &DepEvents,
267+
bool CallerNeedsEvent) {
268268
return submitMemOpHelper(
269-
Self, DepEvents, CallerNeedsEvent,
269+
DepEvents, CallerNeedsEvent,
270270
[&](handler &CGH) {
271271
CGH.memcpyFromDeviceGlobal(Dest, DeviceGlobalPtr, IsDeviceImageScope,
272272
NumBytes, Offset);
@@ -275,8 +275,7 @@ event queue_impl::memcpyFromDeviceGlobal(
275275
IsDeviceImageScope, *this, NumBytes, Offset, Dest);
276276
}
277277

278-
sycl::detail::optional<event>
279-
queue_impl::getLastEvent(const std::shared_ptr<queue_impl> &Self) {
278+
sycl::detail::optional<event> queue_impl::getLastEvent() {
280279
// The external event is required to finish last if set, so it is considered
281280
// the last event if present.
282281
if (std::optional<event> ExternalEvent = MInOrderExternalEvent.read())
@@ -291,7 +290,7 @@ queue_impl::getLastEvent(const std::shared_ptr<queue_impl> &Self) {
291290
if (LastEvent)
292291
return detail::createSyclObjFromImpl<event>(LastEvent);
293292
// We insert a marker to represent an event at end.
294-
return detail::createSyclObjFromImpl<event>(insertMarkerEvent(Self));
293+
return detail::createSyclObjFromImpl<event>(insertMarkerEvent());
295294
}
296295

297296
void queue_impl::addEvent(const detail::EventImplPtr &EventImpl) {
@@ -307,16 +306,15 @@ void queue_impl::addEvent(const detail::EventImplPtr &EventImpl) {
307306

308307
detail::EventImplPtr
309308
queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
310-
const std::shared_ptr<queue_impl> &Self,
311309
queue_impl *SecondaryQueue, bool CallerNeedsEvent,
312310
const detail::code_location &Loc, bool IsTopCodeLoc,
313311
const v1::SubmissionInfo &SubmitInfo) {
314312
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
315313
detail::handler_impl HandlerImplVal(SecondaryQueue, CallerNeedsEvent);
316314
detail::handler_impl *HandlerImpl = &HandlerImplVal;
317-
handler Handler(HandlerImpl, Self);
315+
handler Handler(HandlerImpl, shared_from_this());
318316
#else
319-
handler Handler(Self, SecondaryQueue, CallerNeedsEvent);
317+
handler Handler(shared_from_this(), SecondaryQueue, CallerNeedsEvent);
320318
auto &HandlerImpl = detail::getSyclObjImpl(Handler);
321319
#endif
322320

@@ -398,9 +396,8 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
398396
Stream->generateFlushCommand(ServiceCGH);
399397
};
400398
detail::type_erased_cgfo_ty CGF{L};
401-
detail::EventImplPtr FlushEvent =
402-
submit_impl(CGF, Self, SecondaryQueue, /*CallerNeedsEvent*/ true, Loc,
403-
IsTopCodeLoc, {});
399+
detail::EventImplPtr FlushEvent = submit_impl(
400+
CGF, SecondaryQueue, /*CallerNeedsEvent*/ true, Loc, IsTopCodeLoc, {});
404401
if (EventImpl)
405402
EventImpl->attachEventToCompleteWeak(FlushEvent);
406403
registerStreamServiceEvent(FlushEvent);
@@ -412,19 +409,17 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
412409
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
413410
detail::EventImplPtr
414411
queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
415-
const std::shared_ptr<queue_impl> &Self,
416-
const std::shared_ptr<queue_impl> &,
412+
const std::shared_ptr<queue_impl> & /*PrimaryQueue*/,
417413
const std::shared_ptr<queue_impl> &SecondaryQueue,
418414
bool CallerNeedsEvent, const detail::code_location &Loc,
419415
bool IsTopCodeLoc, const SubmissionInfo &SubmitInfo) {
420-
return submit_impl(CGF, Self, SecondaryQueue.get(), CallerNeedsEvent, Loc,
416+
return submit_impl(CGF, SecondaryQueue.get(), CallerNeedsEvent, Loc,
421417
IsTopCodeLoc, SubmitInfo);
422418
}
423419
#endif
424420

425421
template <typename HandlerFuncT>
426-
event queue_impl::submitWithHandler(const std::shared_ptr<queue_impl> &Self,
427-
const std::vector<event> &DepEvents,
422+
event queue_impl::submitWithHandler(const std::vector<event> &DepEvents,
428423
bool CallerNeedsEvent,
429424
HandlerFuncT HandlerFunc) {
430425
v1::SubmissionInfo SI{};
@@ -435,17 +430,16 @@ event queue_impl::submitWithHandler(const std::shared_ptr<queue_impl> &Self,
435430
detail::type_erased_cgfo_ty CGF{L};
436431

437432
if (!CallerNeedsEvent && supportsDiscardingPiEvents()) {
438-
submit_without_event(CGF, Self, SI,
433+
submit_without_event(CGF, SI,
439434
/*CodeLoc*/ {}, /*IsTopCodeLoc*/ true);
440435
return createDiscardedEvent();
441436
}
442-
return submit_with_event(CGF, Self, SI,
437+
return submit_with_event(CGF, SI,
443438
/*CodeLoc*/ {}, /*IsTopCodeLoc*/ true);
444439
}
445440

446441
template <typename HandlerFuncT, typename MemOpFuncT, typename... MemOpArgTs>
447-
event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
448-
const std::vector<event> &DepEvents,
442+
event queue_impl::submitMemOpHelper(const std::vector<event> &DepEvents,
449443
bool CallerNeedsEvent,
450444
HandlerFuncT HandlerFunc,
451445
MemOpFuncT MemOpFunc,
@@ -475,7 +469,7 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
475469
return createDiscardedEvent();
476470
}
477471

478-
event ResEvent = prepareSYCLEventAssociatedWithQueue(Self);
472+
event ResEvent = prepareSYCLEventAssociatedWithQueue(shared_from_this());
479473
const auto &EventImpl = detail::getSyclObjImpl(ResEvent);
480474
{
481475
NestedCallsTracker tracker;
@@ -509,7 +503,7 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
509503
return ResEvent;
510504
}
511505
}
512-
return submitWithHandler(Self, DepEvents, CallerNeedsEvent, HandlerFunc);
506+
return submitWithHandler(DepEvents, CallerNeedsEvent, HandlerFunc);
513507
}
514508

515509
void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,

0 commit comments

Comments
 (0)