Skip to content

Commit 1db1d19

Browse files
committed
Make context_impl::getAdapter() return by ref
1 parent badd00a commit 1db1d19

24 files changed

+216
-216
lines changed

sycl/source/detail/async_alloc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void *async_malloc(sycl::handler &h, sycl::usm::alloc kind, size_t size) {
6868
sycl::make_error_code(sycl::errc::feature_not_supported),
6969
"Only device backed asynchronous allocations are supported!");
7070

71-
auto &Adapter = h.getContextImpl().getAdapter();
71+
detail::adapter_impl &Adapter = h.getContextImpl().getAdapter();
7272

7373
// Get CG event dependencies for this allocation.
7474
const auto &DepEvents = h.impl->CGData.MEvents;
@@ -84,7 +84,7 @@ void *async_malloc(sycl::handler &h, sycl::usm::alloc kind, size_t size) {
8484
alloc = Graph->getMemPool().malloc(size, kind, DepNodes);
8585
} else {
8686
ur_queue_handle_t Q = h.impl->get_queue().getHandleRef();
87-
Adapter->call<sycl::errc::runtime,
87+
Adapter.call<sycl::errc::runtime,
8888
sycl::detail::UrApiKind::urEnqueueUSMDeviceAllocExp>(
8989
Q, (ur_usm_pool_handle_t)0, size, nullptr, UREvents.size(),
9090
UREvents.data(), &alloc, &Event);
@@ -118,7 +118,7 @@ __SYCL_EXPORT void *async_malloc(const sycl::queue &q, sycl::usm::alloc kind,
118118
__SYCL_EXPORT void *async_malloc_from_pool(sycl::handler &h, size_t size,
119119
const memory_pool &pool) {
120120

121-
auto &Adapter = h.getContextImpl().getAdapter();
121+
detail::adapter_impl &Adapter = h.getContextImpl().getAdapter();
122122
detail::memory_pool_impl &memPoolImpl = *detail::getSyclObjImpl(pool);
123123

124124
// Get CG event dependencies for this allocation.
@@ -138,7 +138,7 @@ __SYCL_EXPORT void *async_malloc_from_pool(sycl::handler &h, size_t size,
138138
detail::getSyclObjImpl(pool).get());
139139
} else {
140140
ur_queue_handle_t Q = h.impl->get_queue().getHandleRef();
141-
Adapter->call<sycl::errc::runtime,
141+
Adapter.call<sycl::errc::runtime,
142142
sycl::detail::UrApiKind::urEnqueueUSMDeviceAllocExp>(
143143
Q, memPoolImpl.get_handle(), size, nullptr, UREvents.size(),
144144
UREvents.data(), &alloc, &Event);

sycl/source/detail/context_impl.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ context_impl::context_impl(const std::vector<sycl::device> Devices,
5454
DeviceIds.push_back(getSyclObjImpl(D)->getHandleRef());
5555
}
5656

57-
getAdapter()->call<UrApiKind::urContextCreate>(
57+
getAdapter().call<UrApiKind::urContextCreate>(
5858
DeviceIds.size(), DeviceIds.data(), nullptr, &MContext);
5959

6060
MKernelProgramCache.setContextPtr(this);
@@ -102,16 +102,16 @@ context_impl::context_impl(ur_context_handle_t UrContext,
102102
// TODO: Move this backend-specific retain of the context to SYCL-2020 style
103103
// make_context<backend::opencl> interop, when that is created.
104104
if (getBackend() == sycl::backend::opencl) {
105-
getAdapter()->call<UrApiKind::urContextRetain>(MContext);
105+
getAdapter().call<UrApiKind::urContextRetain>(MContext);
106106
}
107107
MKernelProgramCache.setContextPtr(this);
108108
}
109109

110110
cl_context context_impl::get() const {
111111
// TODO catch an exception and put it to list of asynchronous exceptions
112-
getAdapter()->call<UrApiKind::urContextRetain>(MContext);
112+
getAdapter().call<UrApiKind::urContextRetain>(MContext);
113113
ur_native_handle_t nativeHandle = 0;
114-
getAdapter()->call<UrApiKind::urContextGetNativeHandle>(MContext,
114+
getAdapter().call<UrApiKind::urContextGetNativeHandle>(MContext,
115115
&nativeHandle);
116116
return ur::cast<cl_context>(nativeHandle);
117117
}
@@ -120,7 +120,7 @@ context_impl::~context_impl() {
120120
try {
121121
// Free all events associated with the initialization of device globals.
122122
for (auto &DeviceGlobalInitializer : MDeviceGlobalInitializers)
123-
DeviceGlobalInitializer.second.ClearEvents(getAdapter());
123+
DeviceGlobalInitializer.second.ClearEvents(&getAdapter());
124124
// Free all device_global USM allocations associated with this context.
125125
for (const void *DeviceGlobal : MAssociatedDeviceGlobals) {
126126
DeviceGlobalMapEntry *DGEntry =
@@ -130,10 +130,10 @@ context_impl::~context_impl() {
130130
}
131131
for (auto LibProg : MCachedLibPrograms) {
132132
assert(LibProg.second && "Null program must not be kept in the cache");
133-
getAdapter()->call<UrApiKind::urProgramRelease>(LibProg.second);
133+
getAdapter().call<UrApiKind::urProgramRelease>(LibProg.second);
134134
}
135135
// TODO catch an exception and put it to list of asynchronous exceptions
136-
getAdapter()->call_nocheck<UrApiKind::urContextRelease>(MContext);
136+
getAdapter().call_nocheck<UrApiKind::urContextRelease>(MContext);
137137
} catch (std::exception &e) {
138138
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~context_impl", e);
139139
}
@@ -146,7 +146,7 @@ const async_handler &context_impl::get_async_handler() const {
146146
template <>
147147
uint32_t context_impl::get_info<info::context::reference_count>() const {
148148
return get_context_info<info::context::reference_count>(this->getHandleRef(),
149-
this->getAdapter());
149+
&this->getAdapter());
150150
}
151151
template <> platform context_impl::get_info<info::context::platform>() const {
152152
return createSyclObjFromImpl<platform>(*MPlatform);
@@ -292,9 +292,9 @@ context_impl::findMatchingDeviceImpl(ur_device_handle_t &DeviceUR) const {
292292
}
293293

294294
ur_native_handle_t context_impl::getNative() const {
295-
const auto &Adapter = getAdapter();
295+
detail::adapter_impl &Adapter = getAdapter();
296296
ur_native_handle_t Handle;
297-
Adapter->call<UrApiKind::urContextGetNativeHandle>(getHandleRef(), &Handle);
297+
Adapter.call<UrApiKind::urContextGetNativeHandle>(getHandleRef(), &Handle);
298298
if (getBackend() == backend::opencl) {
299299
__SYCL_OCL_CALL(clRetainContext, ur::cast<cl_context>(Handle));
300300
}
@@ -345,7 +345,7 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
345345
if (!MDeviceGlobalNotInitializedCnt.load(std::memory_order_acquire))
346346
return {};
347347

348-
const AdapterPtr &Adapter = getAdapter();
348+
detail::adapter_impl &Adapter = getAdapter();
349349
device_impl &DeviceImpl = QueueImpl.getDeviceImpl();
350350
std::lock_guard<std::mutex> NativeProgramLock(MDeviceGlobalInitializersMutex);
351351
auto ImgIt = MDeviceGlobalInitializers.find(
@@ -365,11 +365,11 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
365365
InitEventsRef.begin(), InitEventsRef.end(),
366366
[&Adapter](const ur_event_handle_t &Event) {
367367
return get_event_info<info::event::command_execution_status>(
368-
Event, *Adapter) == info::event_command_status::complete;
368+
Event, Adapter) == info::event_command_status::complete;
369369
});
370370
// Release the removed events.
371371
for (auto EventIt = NewEnd; EventIt != InitEventsRef.end(); ++EventIt)
372-
Adapter->call<UrApiKind::urEventRelease>(*EventIt);
372+
Adapter.call<UrApiKind::urEventRelease>(*EventIt);
373373
// Remove them from the collection.
374374
InitEventsRef.erase(NewEnd, InitEventsRef.end());
375375
// If there are no more events, we can mark it as fully initialized.
@@ -431,14 +431,14 @@ 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
438438
// initialize events list.
439439
ur_event_handle_t InitEvent;
440440
void *const &USMPtr = DeviceGlobalUSM.getPtr();
441-
Adapter->call<UrApiKind::urEnqueueDeviceGlobalVariableWrite>(
441+
Adapter.call<UrApiKind::urEnqueueDeviceGlobalVariableWrite>(
442442
QueueImpl.getHandleRef(), NativePrg,
443443
DeviceGlobalEntry->MUniqueId.c_str(), false, sizeof(void *), 0,
444444
&USMPtr, 0, nullptr, &InitEvent);
@@ -577,7 +577,7 @@ context_impl::get_default_memory_pool(const context &Context,
577577

578578
detail::device_impl &DevImpl = *detail::getSyclObjImpl(Device);
579579
ur_device_handle_t DeviceHandle = DevImpl.getHandleRef();
580-
const sycl::detail::AdapterPtr &Adapter = this->getAdapter();
580+
detail::adapter_impl &Adapter = this->getAdapter();
581581

582582
// Check dev is already in our list of device pool pairs.
583583
if (auto it = std::find_if(MMemPoolImplPtrs.begin(), MMemPoolImplPtrs.end(),
@@ -590,7 +590,7 @@ context_impl::get_default_memory_pool(const context &Context,
590590

591591
// The memory_pool_impl does not exist for this device yet.
592592
ur_usm_pool_handle_t PoolHandle;
593-
Adapter->call<sycl::errc::runtime,
593+
Adapter.call<sycl::errc::runtime,
594594
sycl::detail::UrApiKind::urUSMPoolGetDefaultDevicePoolExp>(
595595
this->getHandleRef(), DeviceHandle, &PoolHandle);
596596

sycl/source/detail/context_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class context_impl : public std::enable_shared_from_this<context_impl> {
9494
const async_handler &get_async_handler() const;
9595

9696
/// \return the Adapter associated with the platform of this context.
97-
const AdapterPtr &getAdapter() const { return MPlatform->getAdapter(); }
97+
adapter_impl &getAdapter() const { return *MPlatform->getAdapter(); }
9898

9999
/// \return the PlatformImpl associated with this context.
100100
platform_impl &getPlatformImpl() const { return *MPlatform; }
@@ -367,7 +367,7 @@ void GetCapabilitiesIntersectionSet(const std::vector<sycl::device> &Devices,
367367
// convenient to be able to reference them without extra `detail::`.
368368
inline auto get_ur_handles(sycl::detail::context_impl &Ctx) {
369369
ur_context_handle_t urCtx = Ctx.getHandleRef();
370-
return std::tuple{urCtx, Ctx.getAdapter()};
370+
return std::tuple{urCtx, &Ctx.getAdapter()};
371371
}
372372
inline auto get_ur_handles(const sycl::context &syclContext) {
373373
return get_ur_handles(*sycl::detail::getSyclObjImpl(syclContext));

sycl/source/detail/device_global_map_entry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void DeviceGlobalMapEntry::removeAssociatedResources(
160160
DeviceGlobalUSMMem &USMMem = USMPtrIt->second;
161161
detail::usm::freeInternal(USMMem.MPtr, CtxImpl);
162162
if (USMMem.MInitEvent.has_value())
163-
CtxImpl->getAdapter()->call<UrApiKind::urEventRelease>(
163+
CtxImpl->getAdapter().call<UrApiKind::urEventRelease>(
164164
*USMMem.MInitEvent);
165165
#ifndef NDEBUG
166166
// For debugging we set the event and memory to some recognizable values
@@ -185,7 +185,7 @@ void DeviceGlobalMapEntry::cleanup() {
185185
DeviceGlobalUSMMem &USMMem = USMPtrIt.second;
186186
detail::usm::freeInternal(USMMem.MPtr, CtxImpl);
187187
if (USMMem.MInitEvent.has_value())
188-
CtxImpl->getAdapter()->call<UrApiKind::urEventRelease>(
188+
CtxImpl->getAdapter().call<UrApiKind::urEventRelease>(
189189
*USMMem.MInitEvent);
190190
#ifndef NDEBUG
191191
// For debugging we set the event and memory to some recognizable values

sycl/source/detail/device_image_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ std::shared_ptr<kernel_impl> device_image_impl::tryGetExtensionKernel(
4242
}
4343

4444
ur_program_handle_t UrProgram = get_ur_program_ref();
45-
const AdapterPtr &Adapter = getSyclObjImpl(Context)->getAdapter();
45+
detail::adapter_impl &Adapter = getSyclObjImpl(Context)->getAdapter();
4646
ur_kernel_handle_t UrKernel = nullptr;
47-
Adapter->call<UrApiKind::urKernelCreate>(UrProgram, AdjustedName.c_str(),
47+
Adapter.call<UrApiKind::urKernelCreate>(UrProgram, AdjustedName.c_str(),
4848
&UrKernel);
4949
// Kernel created by urKernelCreate is implicitly retained.
5050

sycl/source/detail/device_image_impl.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class device_image_impl
573573
ur_mem_handle_t &get_spec_const_buffer_ref() noexcept {
574574
std::lock_guard<std::mutex> Lock{MSpecConstAccessMtx};
575575
if (nullptr == MSpecConstsBuffer && !MSpecConstsBlob.empty()) {
576-
const AdapterPtr &Adapter = getSyclObjImpl(MContext)->getAdapter();
576+
adapter_impl &Adapter = getSyclObjImpl(MContext)->getAdapter();
577577
// Uses UR_MEM_FLAGS_HOST_PTR_COPY instead of UR_MEM_FLAGS_HOST_PTR_USE
578578
// since post-enqueue cleanup might trigger destruction of
579579
// device_image_impl and, as a result, destruction of MSpecConstsBlob
@@ -605,10 +605,10 @@ class device_image_impl
605605
ur_native_handle_t getNative() const {
606606
assert(MProgram);
607607
context_impl &ContextImpl = *detail::getSyclObjImpl(MContext);
608-
const AdapterPtr &Adapter = ContextImpl.getAdapter();
608+
adapter_impl &Adapter = ContextImpl.getAdapter();
609609

610610
ur_native_handle_t NativeProgram = 0;
611-
Adapter->call<UrApiKind::urProgramGetNativeHandle>(MProgram,
611+
Adapter.call<UrApiKind::urProgramGetNativeHandle>(MProgram,
612612
&NativeProgram);
613613
if (ContextImpl.getBackend() == backend::opencl)
614614
__SYCL_OCL_CALL(clRetainProgram, ur::cast<cl_program>(NativeProgram));
@@ -619,12 +619,12 @@ class device_image_impl
619619
~device_image_impl() {
620620
try {
621621
if (MProgram) {
622-
const AdapterPtr &Adapter = getSyclObjImpl(MContext)->getAdapter();
623-
Adapter->call<UrApiKind::urProgramRelease>(MProgram);
622+
adapter_impl &Adapter = getSyclObjImpl(MContext)->getAdapter();
623+
Adapter.call<UrApiKind::urProgramRelease>(MProgram);
624624
}
625625
if (MSpecConstsBuffer) {
626626
std::lock_guard<std::mutex> Lock{MSpecConstAccessMtx};
627-
const AdapterPtr &Adapter = getSyclObjImpl(MContext)->getAdapter();
627+
adapter_impl &Adapter = getSyclObjImpl(MContext)->getAdapter();
628628
memReleaseHelper(Adapter, MSpecConstsBuffer);
629629
}
630630
} catch (std::exception &e) {
@@ -779,23 +779,23 @@ class device_image_impl
779779
Devices, BuildOptions, *SourceStrPtr, UrProgram);
780780
}
781781

782-
const AdapterPtr &Adapter = ContextImpl.getAdapter();
782+
adapter_impl &Adapter = ContextImpl.getAdapter();
783783

784784
if (!FetchedFromCache)
785785
UrProgram = createProgramFromSource(Devices, BuildOptions, LogPtr);
786786

787787
std::string XsFlags = extractXsFlags(BuildOptions, MRTCBinInfo->MLanguage);
788-
auto Res = Adapter->call_nocheck<UrApiKind::urProgramBuildExp>(
788+
auto Res = Adapter.call_nocheck<UrApiKind::urProgramBuildExp>(
789789
UrProgram, DeviceVec.size(), DeviceVec.data(), XsFlags.c_str());
790790
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
791-
Res = Adapter->call_nocheck<UrApiKind::urProgramBuild>(
791+
Res = Adapter.call_nocheck<UrApiKind::urProgramBuild>(
792792
ContextImpl.getHandleRef(), UrProgram, XsFlags.c_str());
793793
}
794-
Adapter->checkUrResult<errc::build>(Res);
794+
Adapter.checkUrResult<errc::build>(Res);
795795

796796
// Get the number of kernels in the program.
797797
size_t NumKernels;
798-
Adapter->call<UrApiKind::urProgramGetInfo>(
798+
Adapter.call<UrApiKind::urProgramGetInfo>(
799799
UrProgram, UR_PROGRAM_INFO_NUM_KERNELS, sizeof(size_t), &NumKernels,
800800
nullptr);
801801

@@ -912,7 +912,7 @@ class device_image_impl
912912
const std::vector<sycl::detail::string_view> &BuildOptions,
913913
const std::string &SourceStr, ur_program_handle_t &UrProgram) const {
914914
sycl::detail::context_impl &ContextImpl = *getSyclObjImpl(MContext);
915-
const AdapterPtr &Adapter = ContextImpl.getAdapter();
915+
adapter_impl &Adapter = ContextImpl.getAdapter();
916916

917917
std::string UserArgs = syclex::detail::userArgsAsString(BuildOptions);
918918

@@ -940,7 +940,7 @@ class device_image_impl
940940
Properties.count = 0;
941941
Properties.pMetadatas = nullptr;
942942

943-
Adapter->call<UrApiKind::urProgramCreateWithBinary>(
943+
Adapter.call<UrApiKind::urProgramCreateWithBinary>(
944944
ContextImpl.getHandleRef(), DeviceHandles.size(), DeviceHandles.data(),
945945
Lengths.data(), Binaries.data(), &Properties, &UrProgram);
946946

@@ -1235,7 +1235,7 @@ class device_image_impl
12351235
const std::vector<sycl::detail::string_view> &Options,
12361236
std::string *LogPtr) const {
12371237
sycl::detail::context_impl &ContextImpl = *getSyclObjImpl(MContext);
1238-
const AdapterPtr &Adapter = ContextImpl.getAdapter();
1238+
adapter_impl &Adapter = ContextImpl.getAdapter();
12391239
const auto spirv = [&]() -> std::vector<uint8_t> {
12401240
switch (MRTCBinInfo->MLanguage) {
12411241
case syclex::source_language::opencl: {
@@ -1246,7 +1246,7 @@ class device_image_impl
12461246
std::transform(Devices.begin(), Devices.end(), IPVersionVec.begin(),
12471247
[&](const sycl::device &SyclDev) {
12481248
uint32_t ipVersion = 0;
1249-
Adapter->call<UrApiKind::urDeviceGetInfo>(
1249+
Adapter.call<UrApiKind::urDeviceGetInfo>(
12501250
getSyclObjImpl(SyclDev)->getHandleRef(),
12511251
UR_DEVICE_INFO_IP_VERSION, sizeof(uint32_t),
12521252
&ipVersion, nullptr);
@@ -1272,7 +1272,7 @@ class device_image_impl
12721272
}();
12731273

12741274
ur_program_handle_t UrProgram = nullptr;
1275-
Adapter->call<UrApiKind::urProgramCreateWithIL>(ContextImpl.getHandleRef(),
1275+
Adapter.call<UrApiKind::urProgramCreateWithIL>(ContextImpl.getHandleRef(),
12761276
spirv.data(), spirv.size(),
12771277
nullptr, &UrProgram);
12781278
// program created by urProgramCreateWithIL is implicitly retained.
@@ -1285,16 +1285,16 @@ class device_image_impl
12851285
}
12861286

12871287
static std::vector<std::string>
1288-
getKernelNamesFromURProgram(const AdapterPtr &Adapter,
1288+
getKernelNamesFromURProgram(adapter_impl &Adapter,
12891289
ur_program_handle_t UrProgram) {
12901290
// Get the kernel names.
12911291
size_t KernelNamesSize;
1292-
Adapter->call<UrApiKind::urProgramGetInfo>(
1292+
Adapter.call<UrApiKind::urProgramGetInfo>(
12931293
UrProgram, UR_PROGRAM_INFO_KERNEL_NAMES, 0, nullptr, &KernelNamesSize);
12941294

12951295
// semi-colon delimited list of kernel names.
12961296
std::string KernelNamesStr(KernelNamesSize, ' ');
1297-
Adapter->call<UrApiKind::urProgramGetInfo>(
1297+
Adapter.call<UrApiKind::urProgramGetInfo>(
12981298
UrProgram, UR_PROGRAM_INFO_KERNEL_NAMES, KernelNamesStr.size(),
12991299
&KernelNamesStr[0], nullptr);
13001300
return detail::split_string(KernelNamesStr, ';');

sycl/source/detail/event_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ context_impl &event_impl::getContextImpl() {
150150

151151
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; }

0 commit comments

Comments
 (0)