Skip to content

[SYCL][NFC] Make queue::getAdapter() return adapter ref instead of ptr #19299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
// are cleaned up separately from cleaning up the device global USM memory
// this must retain the event.
{
if (OwnedUrEvent ZIEvent = DeviceGlobalUSM.getInitEvent(Adapter))
if (OwnedUrEvent ZIEvent = DeviceGlobalUSM.getInitEvent(*Adapter))
InitEventsRef.push_back(ZIEvent.TransferOwnership());
}
// Write the pointer to the device global and store the event in the
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/device_global_map_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() {
assert(!MInitEvent.has_value() && "MInitEvent has not been cleaned up.");
}

OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(const AdapterPtr &Adapter) {
OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(adapter_impl &Adapter) {
std::lock_guard<std::mutex> Lock(MInitEventMutex);
// If there is a init event we can remove it if it is done.
if (MInitEvent.has_value()) {
if (get_event_info<info::event::command_execution_status>(
*MInitEvent, *Adapter) == info::event_command_status::complete) {
Adapter->call<UrApiKind::urEventRelease>(*MInitEvent);
*MInitEvent, Adapter) == info::event_command_status::complete) {
Adapter.call<UrApiKind::urEventRelease>(*MInitEvent);
MInitEvent = {};
return OwnedUrEvent(Adapter);
} else {
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/device_global_map_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct DeviceGlobalUSMMem {

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

private:
void *MPtr;
Expand Down
14 changes: 6 additions & 8 deletions sycl/source/detail/graph/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,21 +1107,19 @@ EventImplPtr exec_graph_impl::enqueuePartitionDirectly(
UrEnqueueWaitListSize == 0 ? nullptr : UrEventHandles.data();

if (!EventNeeded) {
Queue.getAdapter()
->call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
Queue.getHandleRef(), CommandBuffer, UrEnqueueWaitListSize,
UrEnqueueWaitList, nullptr);
Queue.getAdapter().call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
Queue.getHandleRef(), CommandBuffer, UrEnqueueWaitListSize,
UrEnqueueWaitList, nullptr);
return nullptr;
} else {
auto NewEvent = sycl::detail::event_impl::create_device_event(Queue);
NewEvent->setContextImpl(Queue.getContextImpl());
NewEvent->setStateIncomplete();
NewEvent->setSubmissionTime();
ur_event_handle_t UrEvent = nullptr;
Queue.getAdapter()
->call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
Queue.getHandleRef(), CommandBuffer, UrEventHandles.size(),
UrEnqueueWaitList, &UrEvent);
Queue.getAdapter().call<sycl::detail::UrApiKind::urEnqueueCommandBufferExp>(
Queue.getHandleRef(), CommandBuffer, UrEventHandles.size(),
UrEnqueueWaitList, &UrEvent);
NewEvent->setHandle(UrEvent);
NewEvent->setEventFromSubmittedExecCommandBuffer(true);
return NewEvent;
Expand Down
116 changes: 58 additions & 58 deletions sycl/source/detail/memory_manager.cpp

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ getUrEvents(const std::vector<sycl::event> &DepEvents) {
template <>
uint32_t queue_impl::get_info<info::queue::reference_count>() const {
ur_result_t result = UR_RESULT_SUCCESS;
getAdapter()->call<UrApiKind::urQueueGetInfo>(
getAdapter().call<UrApiKind::urQueueGetInfo>(
MQueue, UR_QUEUE_INFO_REFERENCE_COUNT, sizeof(result), &result, nullptr);
return result;
}
Expand Down Expand Up @@ -657,8 +657,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
}
}

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

if (!isInOrder()) {
std::vector<EventImplPtr> StreamsServiceEvents;
Expand Down Expand Up @@ -735,14 +734,13 @@ void queue_impl::destructorNotification() {
}

ur_native_handle_t queue_impl::getNative(int32_t &NativeHandleDesc) const {
const AdapterPtr &Adapter = getAdapter();
ur_native_handle_t Handle{};
ur_queue_native_desc_t UrNativeDesc{UR_STRUCTURE_TYPE_QUEUE_NATIVE_DESC,
nullptr, nullptr};
UrNativeDesc.pNativeData = &NativeHandleDesc;

Adapter->call<UrApiKind::urQueueGetNativeHandle>(MQueue, &UrNativeDesc,
&Handle);
getAdapter().call<UrApiKind::urQueueGetNativeHandle>(MQueue, &UrNativeDesc,
&Handle);
if (getContextImpl().getBackend() == backend::opencl)
__SYCL_OCL_CALL(clRetainCommandQueue, ur::cast<cl_command_queue>(Handle));

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

// Check the status of the backend queue if this is not a host queue.
ur_bool_t IsReady = false;
getAdapter()->call<UrApiKind::urQueueGetInfo>(
getAdapter().call<UrApiKind::urQueueGetInfo>(
MQueue, UR_QUEUE_INFO_EMPTY, sizeof(IsReady), &IsReady, nullptr);
if (!IsReady)
return false;
Expand Down
23 changes: 11 additions & 12 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
#endif
throw_asynchronous();
auto status =
getAdapter()->call_nocheck<UrApiKind::urQueueRelease>(MQueue);
getAdapter().call_nocheck<UrApiKind::urQueueRelease>(MQueue);
// If loader is already closed, it'll return a not-initialized status
// which the UR should convert to SUCCESS code. But that isn't always
// working on Windows. This is a temporary workaround until that is fixed.
// TODO: Remove this workaround when UR is fixed, and restore
// ->call<>() instead of ->call_nocheck<>() above.
if (status != UR_RESULT_SUCCESS &&
status != UR_RESULT_ERROR_UNINITIALIZED) {
__SYCL_CHECK_UR_CODE_NO_EXC(status, getAdapter()->getBackend());
__SYCL_CHECK_UR_CODE_NO_EXC(status, getAdapter().getBackend());
}
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~queue_impl", e);
Expand All @@ -274,8 +274,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {

cl_command_queue get() {
ur_native_handle_t nativeHandle = 0;
getAdapter()->call<UrApiKind::urQueueGetNativeHandle>(MQueue, nullptr,
&nativeHandle);
getAdapter().call<UrApiKind::urQueueGetNativeHandle>(MQueue, nullptr,
&nativeHandle);
__SYCL_OCL_CALL(clRetainCommandQueue, ur::cast<cl_command_queue>(nativeHandle));
return ur::cast<cl_command_queue>(nativeHandle);
}
Expand All @@ -285,7 +285,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
return createSyclObjFromImpl<context>(MContext);
}

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

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

/// Submits a command group function object to the queue, in order to be
Expand Down Expand Up @@ -487,7 +487,6 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
ur_queue_handle_t Queue{};
ur_context_handle_t Context = MContext->getHandleRef();
ur_device_handle_t Device = MDevice.getHandleRef();
const AdapterPtr &Adapter = getAdapter();
/*
sycl::detail::pi::PiQueueProperties Properties[] = {
PI_QUEUE_FLAGS, createPiQueueProperties(MPropList, Order), 0, 0, 0};
Expand All @@ -503,8 +502,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
.get_index();
Properties.pNext = &IndexProperties;
}
Adapter->call<UrApiKind::urQueueCreate>(Context, Device, &Properties,
&Queue);
getAdapter().call<UrApiKind::urQueueCreate>(Context, Device, &Properties,
&Queue);

return Queue;
}
Expand Down Expand Up @@ -665,8 +664,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
EventImplPtr insertMarkerEvent() {
auto ResEvent = detail::event_impl::create_device_event(*this);
ur_event_handle_t UREvent = nullptr;
getAdapter()->call<UrApiKind::urEnqueueEventsWait>(getHandleRef(), 0,
nullptr, &UREvent);
getAdapter().call<UrApiKind::urEnqueueEventsWait>(getHandleRef(), 0,
nullptr, &UREvent);
ResEvent->setHandle(UREvent);
return ResEvent;
}
Expand All @@ -690,7 +689,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
queue_impl &Queue = Handler.impl->get_queue();
auto ResEvent = detail::event_impl::create_device_event(Queue);
ur_event_handle_t UREvent = nullptr;
getAdapter()->call<UrApiKind::urEnqueueEventsWaitWithBarrier>(
getAdapter().call<UrApiKind::urEnqueueEventsWaitWithBarrier>(
Queue.getHandleRef(), 0, nullptr, &UREvent);
ResEvent->setHandle(UREvent);
return ResEvent;
Expand Down
Loading