Skip to content

Commit be139e9

Browse files
committed
[SYCL][NFC] Pass adapter by ref in ur::getAdapter and event:getAdapter
1 parent 0ed0037 commit be139e9

17 files changed

+75
-66
lines changed

sycl/source/backend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ namespace detail {
3333
static const adapter_impl &getAdapter(backend Backend) {
3434
switch (Backend) {
3535
case backend::opencl:
36-
return *ur::getAdapter<backend::opencl>();
36+
return ur::getAdapter<backend::opencl>();
3737
case backend::ext_oneapi_level_zero:
38-
return *ur::getAdapter<backend::ext_oneapi_level_zero>();
38+
return ur::getAdapter<backend::ext_oneapi_level_zero>();
3939
case backend::ext_oneapi_cuda:
40-
return *ur::getAdapter<backend::ext_oneapi_cuda>();
40+
return ur::getAdapter<backend::ext_oneapi_cuda>();
4141
case backend::ext_oneapi_hip:
42-
return *ur::getAdapter<backend::ext_oneapi_hip>();
42+
return ur::getAdapter<backend::ext_oneapi_hip>();
4343
default:
4444
throw sycl::exception(
4545
sycl::make_error_code(sycl::errc::runtime),

sycl/source/backend/level_zero.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ using namespace sycl::detail;
1919

2020
__SYCL_EXPORT device make_device(const platform &Platform,
2121
ur_native_handle_t NativeHandle) {
22-
const auto &Adapter = ur::getAdapter<backend::ext_oneapi_level_zero>();
22+
const adapter_impl &Adapter =
23+
ur::getAdapter<backend::ext_oneapi_level_zero>();
2324
// Create UR device first.
2425
ur_device_handle_t UrDevice;
25-
Adapter->call<UrApiKind::urDeviceCreateWithNativeHandle>(
26-
NativeHandle, Adapter->getUrAdapter(), nullptr, &UrDevice);
26+
Adapter.call<UrApiKind::urDeviceCreateWithNativeHandle>(
27+
NativeHandle, Adapter.getUrAdapter(), nullptr, &UrDevice);
2728

2829
return detail::createSyclObjFromImpl<device>(
2930
getSyclObjImpl(Platform)->getOrMakeDeviceImpl(UrDevice));

sycl/source/context.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <detail/adapter_impl.hpp>
910
#include <detail/backend_impl.hpp>
1011
#include <detail/context_impl.hpp>
1112
#include <detail/ur.hpp>
@@ -72,15 +73,16 @@ context::context(const std::vector<device> &DeviceList,
7273
impl = detail::context_impl::create(DeviceList, AsyncHandler, PropList);
7374
}
7475
context::context(cl_context ClContext, async_handler AsyncHandler) {
75-
const auto &Adapter = sycl::detail::ur::getAdapter<backend::opencl>();
76+
const detail::adapter_impl &Adapter =
77+
sycl::detail::ur::getAdapter<backend::opencl>();
7678

7779
ur_context_handle_t hContext = nullptr;
7880
ur_native_handle_t nativeHandle =
7981
reinterpret_cast<ur_native_handle_t>(ClContext);
80-
Adapter->call<detail::UrApiKind::urContextCreateWithNativeHandle>(
81-
nativeHandle, Adapter->getUrAdapter(), 0, nullptr, nullptr, &hContext);
82+
Adapter.call<detail::UrApiKind::urContextCreateWithNativeHandle>(
83+
nativeHandle, Adapter.getUrAdapter(), 0, nullptr, nullptr, &hContext);
8284

83-
impl = detail::context_impl::create(hContext, AsyncHandler, *Adapter);
85+
impl = detail::context_impl::create(hContext, AsyncHandler, Adapter);
8486
}
8587

8688
template <typename Param>

sycl/source/detail/context_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ context_impl::initializeDeviceGlobals(ur_program_handle_t NativePrg,
366366
InitEventsRef.begin(), InitEventsRef.end(),
367367
[&Adapter](const ur_event_handle_t &Event) {
368368
return get_event_info<info::event::command_execution_status>(
369-
Event, Adapter) == info::event_command_status::complete;
369+
Event, *Adapter) == info::event_command_status::complete;
370370
});
371371
// Release the removed events.
372372
for (auto EventIt = NewEnd; EventIt != InitEventsRef.end(); ++EventIt)

sycl/source/detail/device_global_map_entry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ OwnedUrEvent DeviceGlobalUSMMem::getInitEvent(const AdapterPtr &Adapter) {
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) {
33+
*MInitEvent, *Adapter) == info::event_command_status::complete) {
3434
Adapter->call<UrApiKind::urEventRelease>(*MInitEvent);
3535
MInitEvent = {};
3636
return OwnedUrEvent(Adapter);

sycl/source/detail/event_impl.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ event_impl::~event_impl() {
4848
try {
4949
auto Handle = this->getHandle();
5050
if (Handle)
51-
getAdapter()->call<UrApiKind::urEventRelease>(Handle);
51+
getAdapter().call<UrApiKind::urEventRelease>(Handle);
5252
} catch (std::exception &e) {
5353
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~event_impl", e);
5454
}
@@ -59,7 +59,7 @@ void event_impl::waitInternal(bool *Success) {
5959
if (!MIsHostEvent && Handle) {
6060
// Wait for the native event
6161
ur_result_t Err =
62-
getAdapter()->call_nocheck<UrApiKind::urEventWait>(1, &Handle);
62+
getAdapter().call_nocheck<UrApiKind::urEventWait>(1, &Handle);
6363
// TODO drop the UR_RESULT_ERROR_UKNOWN from here (this was waiting for
6464
// https://github.com/oneapi-src/unified-runtime/issues/1459 which is now
6565
// closed).
@@ -68,7 +68,7 @@ void event_impl::waitInternal(bool *Success) {
6868
Err == UR_RESULT_ERROR_IN_EVENT_LIST_EXEC_STATUS))
6969
*Success = false;
7070
else {
71-
getAdapter()->checkUrResult(Err);
71+
getAdapter().checkUrResult(Err);
7272
if (Success != nullptr)
7373
*Success = true;
7474
}
@@ -148,9 +148,9 @@ context_impl &event_impl::getContextImpl() {
148148
return *MContext;
149149
}
150150

151-
const AdapterPtr &event_impl::getAdapter() {
151+
const adapter_impl &event_impl::getAdapter() {
152152
initContextIfNeeded();
153-
return MContext->getAdapter();
153+
return *MContext->getAdapter();
154154
}
155155

156156
void event_impl::setStateIncomplete() { MState = HES_NotComplete; }
@@ -166,7 +166,7 @@ event_impl::event_impl(ur_event_handle_t Event, const context &SyclContext,
166166
MIsFlushed(true), MState(HES_Complete) {
167167

168168
ur_context_handle_t TempContext;
169-
getAdapter()->call<UrApiKind::urEventGetInfo>(
169+
getAdapter().call<UrApiKind::urEventGetInfo>(
170170
this->getHandle(), UR_EVENT_INFO_CONTEXT, sizeof(ur_context_handle_t),
171171
&TempContext, nullptr);
172172

@@ -519,19 +519,19 @@ ur_native_handle_t event_impl::getNative() {
519519
return {};
520520
initContextIfNeeded();
521521

522-
auto Adapter = getAdapter();
522+
const adapter_impl &Adapter = getAdapter();
523523
auto Handle = getHandle();
524524
if (MIsDefaultConstructed && !Handle) {
525525
auto TempContext = MContext.get()->getHandleRef();
526526
ur_event_native_properties_t NativeProperties{};
527527
ur_event_handle_t UREvent = nullptr;
528-
Adapter->call<UrApiKind::urEventCreateWithNativeHandle>(
528+
Adapter.call<UrApiKind::urEventCreateWithNativeHandle>(
529529
0, TempContext, &NativeProperties, &UREvent);
530530
this->setHandle(UREvent);
531531
Handle = UREvent;
532532
}
533533
ur_native_handle_t OutHandle;
534-
Adapter->call<UrApiKind::urEventGetNativeHandle>(Handle, &OutHandle);
534+
Adapter.call<UrApiKind::urEventGetNativeHandle>(Handle, &OutHandle);
535535
if (MContext->getBackend() == backend::opencl)
536536
__SYCL_OCL_CALL(clRetainEvent, ur::cast<cl_event>(OutHandle));
537537
return OutHandle;
@@ -569,11 +569,11 @@ void event_impl::flushIfNeeded(queue_impl *UserQueue) {
569569

570570
// Check if the task for this event has already been submitted.
571571
ur_event_status_t Status = UR_EVENT_STATUS_QUEUED;
572-
getAdapter()->call<UrApiKind::urEventGetInfo>(
572+
getAdapter().call<UrApiKind::urEventGetInfo>(
573573
Handle, UR_EVENT_INFO_COMMAND_EXECUTION_STATUS, sizeof(ur_event_status_t),
574574
&Status, nullptr);
575575
if (Status == UR_EVENT_STATUS_QUEUED) {
576-
getAdapter()->call<UrApiKind::urQueueFlush>(Queue->getHandleRef());
576+
getAdapter().call<UrApiKind::urQueueFlush>(Queue->getHandleRef());
577577
}
578578
MIsFlushed = true;
579579
}

sycl/source/detail/event_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class event_impl {
177177

178178
/// \return the Adapter associated with the context of this event.
179179
/// Should be called when this is not a Host Event.
180-
const AdapterPtr &getAdapter();
180+
const adapter_impl &getAdapter();
181181

182182
/// Associate event with the context.
183183
///

sycl/source/detail/event_info.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ namespace detail {
2121

2222
template <typename Param>
2323
typename Param::return_type
24-
get_event_profiling_info(ur_event_handle_t Event, const AdapterPtr &Adapter) {
24+
get_event_profiling_info(ur_event_handle_t Event, const adapter_impl &Adapter) {
2525
static_assert(is_event_profiling_info_desc<Param>::value,
2626
"Unexpected event profiling info descriptor");
2727
typename Param::return_type Result{0};
2828
// TODO catch an exception and put it to list of asynchronous exceptions
29-
Adapter->call<UrApiKind::urEventGetProfilingInfo>(
29+
Adapter.call<UrApiKind::urEventGetProfilingInfo>(
3030
Event, UrInfoCode<Param>::value, sizeof(Result), &Result, nullptr);
3131
return Result;
3232
}
3333

3434
template <typename Param>
3535
typename Param::return_type get_event_info(ur_event_handle_t Event,
36-
const AdapterPtr &Adapter) {
36+
const adapter_impl &Adapter) {
3737
static_assert(is_event_info_desc<Param>::value,
3838
"Unexpected event info descriptor");
3939
typename Param::return_type Result{0};
4040
// TODO catch an exception and put it to list of asynchronous exceptions
41-
Adapter->call<UrApiKind::urEventGetInfo>(Event, UrInfoCode<Param>::value,
42-
sizeof(Result), &Result, nullptr);
41+
Adapter.call<UrApiKind::urEventGetInfo>(Event, UrInfoCode<Param>::value,
42+
sizeof(Result), &Result, nullptr);
4343

4444
// If the status is UR_EVENT_STATUS_QUEUED We need to change it since QUEUE is
4545
// not a valid status in sycl.

sycl/source/detail/memory_manager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ static void waitForEvents(const std::vector<EventImplPtr> &Events) {
122122
// Assuming all events will be on the same device or
123123
// devices associated with the same Backend.
124124
if (!Events.empty()) {
125-
const AdapterPtr &Adapter = Events[0]->getAdapter();
125+
const adapter_impl &Adapter = Events[0]->getAdapter();
126126
std::vector<ur_event_handle_t> UrEvents(Events.size());
127127
std::transform(
128128
Events.begin(), Events.end(), UrEvents.begin(),
129129
[](const EventImplPtr &EventImpl) { return EventImpl->getHandle(); });
130130
if (!UrEvents.empty() && UrEvents[0]) {
131-
Adapter->call<UrApiKind::urEventWait>(UrEvents.size(), &UrEvents[0]);
131+
Adapter.call<UrApiKind::urEventWait>(UrEvents.size(), &UrEvents[0]);
132132
}
133133
}
134134
}
@@ -318,8 +318,8 @@ void *MemoryManager::allocateInteropMemObject(
318318
// Retain the event since it will be released during alloca command
319319
// destruction
320320
if (nullptr != OutEventToWait) {
321-
const AdapterPtr &Adapter = InteropEvent->getAdapter();
322-
Adapter->call<UrApiKind::urEventRetain>(OutEventToWait);
321+
const adapter_impl &Adapter = InteropEvent->getAdapter();
322+
Adapter.call<UrApiKind::urEventRetain>(OutEventToWait);
323323
}
324324
return UserPtr;
325325
}

sycl/source/detail/platform_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ platform_impl::getOrMakePlatformImpl(ur_platform_handle_t UrPlatform,
5151
// needs a bit of help...
5252
struct creator : platform_impl {
5353
creator(ur_platform_handle_t APlatform, const adapter_impl &AAdapter)
54-
: platform_impl(APlatform, &AAdapter) {}
54+
: platform_impl(APlatform, AAdapter) {}
5555
};
5656
Result = std::make_shared<creator>(UrPlatform, Adapter);
5757
PlatformCache.emplace_back(Result);

0 commit comments

Comments
 (0)