Skip to content

Commit b707123

Browse files
[SYCL][NFC] Make queue::getAdapter() return adapter ref instead of ptr (#19299)
It's a part of larger refactoring effort to pass adapter via reference instead of pointer everywhere in the codebase. Follow-up of: #19186 #19184 #19187 #19202
1 parent d82acd7 commit b707123

File tree

10 files changed

+157
-162
lines changed

10 files changed

+157
-162
lines changed

sycl/source/detail/context_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
431431
// are cleaned up separately from cleaning up the device global USM memory
432432
// this must retain the event.
433433
{
434-
if (OwnedUrEvent ZIEvent = DeviceGlobalUSM.getInitEvent(Adapter))
434+
if (OwnedUrEvent ZIEvent = DeviceGlobalUSM.getInitEvent(*Adapter))
435435
InitEventsRef.push_back(ZIEvent.TransferOwnership());
436436
}
437437
// Write the pointer to the device global and store the event in the

sycl/source/detail/device_global_map_entry.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() {
2525
assert(!MInitEvent.has_value() && "MInitEvent has not been cleaned up.");
2626
}
2727

28-
OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(const AdapterPtr &Adapter) {
28+
OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(adapter_impl &Adapter) {
2929
std::lock_guard<std::mutex> Lock(MInitEventMutex);
3030
// If there is a init event we can remove it if it is done.
3131
if (MInitEvent.has_value()) {
3232
if (get_event_info<info::event::command_execution_status>(
33-
*MInitEvent, *Adapter) == info::event_command_status::complete) {
34-
Adapter->call<UrApiKind::urEventRelease>(*MInitEvent);
33+
*MInitEvent, Adapter) == info::event_command_status::complete) {
34+
Adapter.call<UrApiKind::urEventRelease>(*MInitEvent);
3535
MInitEvent = {};
3636
return OwnedUrEvent(Adapter);
3737
} else {

sycl/source/detail/device_global_map_entry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct DeviceGlobalUSMMem {
3939

4040
// Gets the initialization event if it exists. If not the OwnedUrEvent
4141
// will contain no event.
42-
OwnedUrEvent getInitEvent(const AdapterPtr &Adapter);
42+
OwnedUrEvent getInitEvent(adapter_impl &Adapter);
4343

4444
private:
4545
void *MPtr;

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,21 +1107,19 @@ EventImplPtr exec_graph_impl::enqueuePartitionDirectly(
11071107
UrEnqueueWaitListSize == 0 ? nullptr : UrEventHandles.data();
11081108

11091109
if (!EventNeeded) {
1110-
Queue.getAdapter()
1111-
->call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
1112-
Queue.getHandleRef(), CommandBuffer, UrEnqueueWaitListSize,
1113-
UrEnqueueWaitList, nullptr);
1110+
Queue.getAdapter().call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
1111+
Queue.getHandleRef(), CommandBuffer, UrEnqueueWaitListSize,
1112+
UrEnqueueWaitList, nullptr);
11141113
return nullptr;
11151114
} else {
11161115
auto NewEvent = sycl::detail::event_impl::create_device_event(Queue);
11171116
NewEvent->setContextImpl(Queue.getContextImpl());
11181117
NewEvent->setStateIncomplete();
11191118
NewEvent->setSubmissionTime();
11201119
ur_event_handle_t UrEvent = nullptr;
1121-
Queue.getAdapter()
1122-
->call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
1123-
Queue.getHandleRef(), CommandBuffer, UrEventHandles.size(),
1124-
UrEnqueueWaitList, &UrEvent);
1120+
Queue.getAdapter().call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
1121+
Queue.getHandleRef(), CommandBuffer, UrEventHandles.size(),
1122+
UrEnqueueWaitList, &UrEvent);
11251123
NewEvent->setHandle(UrEvent);
11261124
NewEvent->setEventFromSubmittedExecCommandBuffer(true);
11271125
return NewEvent;

sycl/source/detail/memory_manager.cpp

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

sycl/source/detail/queue_impl.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ getUrEvents(const std::vector<sycl::event> &DepEvents) {
6363
template <>
6464
uint32_t queue_impl::get_info<info::queue::reference_count>() const {
6565
ur_result_t result = UR_RESULT_SUCCESS;
66-
getAdapter()->call<UrApiKind::urQueueGetInfo>(
66+
getAdapter().call<UrApiKind::urQueueGetInfo>(
6767
MQueue, UR_QUEUE_INFO_REFERENCE_COUNT, sizeof(result), &result, nullptr);
6868
return result;
6969
}
@@ -657,8 +657,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
657657
}
658658
}
659659

660-
const AdapterPtr &Adapter = getAdapter();
661-
Adapter->call<UrApiKind::urQueueFinish>(getHandleRef());
660+
getAdapter().call<UrApiKind::urQueueFinish>(getHandleRef());
662661

663662
if (!isInOrder()) {
664663
std::vector<EventImplPtr> StreamsServiceEvents;
@@ -735,14 +734,13 @@ void queue_impl::destructorNotification() {
735734
}
736735

737736
ur_native_handle_t queue_impl::getNative(int32_t &NativeHandleDesc) const {
738-
const AdapterPtr &Adapter = getAdapter();
739737
ur_native_handle_t Handle{};
740738
ur_queue_native_desc_t UrNativeDesc{UR_STRUCTURE_TYPE_QUEUE_NATIVE_DESC,
741739
nullptr, nullptr};
742740
UrNativeDesc.pNativeData = &NativeHandleDesc;
743741

744-
Adapter->call<UrApiKind::urQueueGetNativeHandle>(MQueue, &UrNativeDesc,
745-
&Handle);
742+
getAdapter().call<UrApiKind::urQueueGetNativeHandle>(MQueue, &UrNativeDesc,
743+
&Handle);
746744
if (getContextImpl().getBackend() == backend::opencl)
747745
__SYCL_OCL_CALL(clRetainCommandQueue, ur::cast<cl_command_queue>(Handle));
748746

@@ -766,7 +764,7 @@ bool queue_impl::queue_empty() const {
766764

767765
// Check the status of the backend queue if this is not a host queue.
768766
ur_bool_t IsReady = false;
769-
getAdapter()->call<UrApiKind::urQueueGetInfo>(
767+
getAdapter().call<UrApiKind::urQueueGetInfo>(
770768
MQueue, UR_QUEUE_INFO_EMPTY, sizeof(IsReady), &IsReady, nullptr);
771769
if (!IsReady)
772770
return false;

sycl/source/detail/queue_impl.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
255255
#endif
256256
throw_asynchronous();
257257
auto status =
258-
getAdapter()->call_nocheck<UrApiKind::urQueueRelease>(MQueue);
258+
getAdapter().call_nocheck<UrApiKind::urQueueRelease>(MQueue);
259259
// If loader is already closed, it'll return a not-initialized status
260260
// which the UR should convert to SUCCESS code. But that isn't always
261261
// working on Windows. This is a temporary workaround until that is fixed.
262262
// TODO: Remove this workaround when UR is fixed, and restore
263263
// ->call<>() instead of ->call_nocheck<>() above.
264264
if (status != UR_RESULT_SUCCESS &&
265265
status != UR_RESULT_ERROR_UNINITIALIZED) {
266-
__SYCL_CHECK_UR_CODE_NO_EXC(status, getAdapter()->getBackend());
266+
__SYCL_CHECK_UR_CODE_NO_EXC(status, getAdapter().getBackend());
267267
}
268268
} catch (std::exception &e) {
269269
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~queue_impl", e);
@@ -274,8 +274,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
274274

275275
cl_command_queue get() {
276276
ur_native_handle_t nativeHandle = 0;
277-
getAdapter()->call<UrApiKind::urQueueGetNativeHandle>(MQueue, nullptr,
278-
&nativeHandle);
277+
getAdapter().call<UrApiKind::urQueueGetNativeHandle>(MQueue, nullptr,
278+
&nativeHandle);
279279
__SYCL_OCL_CALL(clRetainCommandQueue, ur::cast<cl_command_queue>(nativeHandle));
280280
return ur::cast<cl_command_queue>(nativeHandle);
281281
}
@@ -285,7 +285,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
285285
return createSyclObjFromImpl<context>(MContext);
286286
}
287287

288-
const AdapterPtr &getAdapter() const { return MContext->getAdapter(); }
288+
adapter_impl &getAdapter() const { return *MContext->getAdapter(); }
289289

290290
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
291291
const std::shared_ptr<context_impl> &getContextImplPtr() const {
@@ -325,7 +325,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
325325
"flush cannot be called for a queue which is "
326326
"recording to a command graph.");
327327
}
328-
getAdapter()->call<UrApiKind::urQueueFlush>(MQueue);
328+
getAdapter().call<UrApiKind::urQueueFlush>(MQueue);
329329
}
330330

331331
/// Submits a command group function object to the queue, in order to be
@@ -487,7 +487,6 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
487487
ur_queue_handle_t Queue{};
488488
ur_context_handle_t Context = MContext->getHandleRef();
489489
ur_device_handle_t Device = MDevice.getHandleRef();
490-
const AdapterPtr &Adapter = getAdapter();
491490
/*
492491
sycl::detail::pi::PiQueueProperties Properties[] = {
493492
PI_QUEUE_FLAGS, createPiQueueProperties(MPropList, Order), 0, 0, 0};
@@ -503,8 +502,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
503502
.get_index();
504503
Properties.pNext = &IndexProperties;
505504
}
506-
Adapter->call<UrApiKind::urQueueCreate>(Context, Device, &Properties,
507-
&Queue);
505+
getAdapter().call<UrApiKind::urQueueCreate>(Context, Device, &Properties,
506+
&Queue);
508507

509508
return Queue;
510509
}
@@ -665,8 +664,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
665664
EventImplPtr insertMarkerEvent() {
666665
auto ResEvent = detail::event_impl::create_device_event(*this);
667666
ur_event_handle_t UREvent = nullptr;
668-
getAdapter()->call<UrApiKind::urEnqueueEventsWait>(getHandleRef(), 0,
669-
nullptr, &UREvent);
667+
getAdapter().call<UrApiKind::urEnqueueEventsWait>(getHandleRef(), 0,
668+
nullptr, &UREvent);
670669
ResEvent->setHandle(UREvent);
671670
return ResEvent;
672671
}
@@ -690,7 +689,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
690689
queue_impl &Queue = Handler.impl->get_queue();
691690
auto ResEvent = detail::event_impl::create_device_event(Queue);
692691
ur_event_handle_t UREvent = nullptr;
693-
getAdapter()->call<UrApiKind::urEnqueueEventsWaitWithBarrier>(
692+
getAdapter().call<UrApiKind::urEnqueueEventsWaitWithBarrier>(
694693
Queue.getHandleRef(), 0, nullptr, &UREvent);
695694
ResEvent->setHandle(UREvent);
696695
return ResEvent;

0 commit comments

Comments
 (0)