Skip to content

Commit 7187eea

Browse files
[SYCL][NFC] Remove AdapterPtr from SYCL RT (#19315)
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 #19299 #19312 #19313 #19314
1 parent cb42a56 commit 7187eea

File tree

10 files changed

+27
-30
lines changed

10 files changed

+27
-30
lines changed

sycl/source/detail/allowlist.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ bool deviceIsAllowed(const DeviceDescT &DeviceDesc,
364364
}
365365

366366
void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
367-
ur_platform_handle_t UrPlatform,
368-
const AdapterPtr &Adapter) {
367+
ur_platform_handle_t UrPlatform, adapter_impl &Adapter) {
369368

370369
AllowListParsedT AllowListParsed =
371370
parseAllowList(SYCLConfig<SYCL_DEVICE_ALLOWLIST>::get());
@@ -375,7 +374,7 @@ void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
375374
// Get platform's backend and put it to DeviceDesc
376375
DeviceDescT DeviceDesc;
377376
platform_impl &PlatformImpl =
378-
platform_impl::getOrMakePlatformImpl(UrPlatform, *Adapter);
377+
platform_impl::getOrMakePlatformImpl(UrPlatform, Adapter);
379378
backend Backend = PlatformImpl.getBackend();
380379

381380
for (const auto &SyclBe : getSyclBeMap()) {
@@ -396,7 +395,7 @@ void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
396395
device_impl &DeviceImpl = PlatformImpl.getOrMakeDeviceImpl(Device);
397396
// get DeviceType value and put it to DeviceDesc
398397
ur_device_type_t UrDevType = UR_DEVICE_TYPE_ALL;
399-
Adapter->call<UrApiKind::urDeviceGetInfo>(
398+
Adapter.call<UrApiKind::urDeviceGetInfo>(
400399
Device, UR_DEVICE_INFO_TYPE, sizeof(UrDevType), &UrDevType, nullptr);
401400
// TODO need mechanism to do these casts, there's a bunch of this sort of
402401
// thing

sycl/source/detail/allowlist.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool deviceIsAllowed(const DeviceDescT &DeviceDesc,
2828
const AllowListParsedT &AllowListParsed);
2929

3030
void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
31-
ur_platform_handle_t UrPlatform, const AdapterPtr &Adapter);
31+
ur_platform_handle_t UrPlatform, adapter_impl &Adapter);
3232

3333
} // namespace detail
3434
} // namespace _V1

sycl/source/detail/context_impl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =
@@ -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);
@@ -449,10 +449,9 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
449449
}
450450
}
451451

452-
void context_impl::DeviceGlobalInitializer::ClearEvents(
453-
const AdapterPtr &Adapter) {
452+
void context_impl::DeviceGlobalInitializer::ClearEvents(adapter_impl &Adapter) {
454453
for (const ur_event_handle_t &Event : MDeviceGlobalInitEvents)
455-
Adapter->call<UrApiKind::urEventRelease>(Event);
454+
Adapter.call<UrApiKind::urEventRelease>(Event);
456455
MDeviceGlobalInitEvents.clear();
457456
}
458457

sycl/source/detail/context_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class context_impl : public std::enable_shared_from_this<context_impl> {
295295
}
296296

297297
/// Clears all events of the initializer. This will not acquire the lock.
298-
void ClearEvents(const AdapterPtr &Adapter);
298+
void ClearEvents(adapter_impl &Adapter);
299299

300300
/// The binary image of the program.
301301
const RTDeviceBinaryImage *MBinImage = nullptr;

sycl/source/detail/context_info.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ namespace detail {
2020

2121
template <typename Param>
2222
typename Param::return_type get_context_info(ur_context_handle_t Ctx,
23-
const AdapterPtr &Adapter) {
23+
adapter_impl &Adapter) {
2424
static_assert(is_context_info_desc<Param>::value,
2525
"Invalid context information descriptor");
2626
typename Param::return_type Result = 0;
2727
// TODO catch an exception and put it to list of asynchronous exceptions
28-
Adapter->call<UrApiKind::urContextGetInfo>(Ctx, UrInfoCode<Param>::value,
29-
sizeof(Result), &Result, nullptr);
28+
Adapter.call<UrApiKind::urContextGetInfo>(Ctx, UrInfoCode<Param>::value,
29+
sizeof(Result), &Result, nullptr);
3030
return Result;
3131
}
3232

sycl/source/detail/platform_impl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ static bool IsBannedPlatform(platform Platform) {
119119
// replace uses of this with a helper in adapter object, the adapter
120120
// objects will own the ur adapter handles and they'll need to pass them to
121121
// urPlatformsGet - so urPlatformsGet will need to be wrapped with a helper
122-
std::vector<platform> platform_impl::getAdapterPlatforms(AdapterPtr &Adapter,
122+
std::vector<platform> platform_impl::getAdapterPlatforms(adapter_impl &Adapter,
123123
bool Supported) {
124124
std::vector<platform> Platforms;
125125

126-
auto UrPlatforms = Adapter->getUrPlatforms();
126+
auto UrPlatforms = Adapter.getUrPlatforms();
127127

128128
if (UrPlatforms.empty()) {
129129
return Platforms;
130130
}
131131

132132
for (const auto &UrPlatform : UrPlatforms) {
133133
platform Platform = detail::createSyclObjFromImpl<platform>(
134-
getOrMakePlatformImpl(UrPlatform, *Adapter));
134+
getOrMakePlatformImpl(UrPlatform, Adapter));
135135
const bool IsBanned = IsBannedPlatform(Platform);
136136
bool HasAnyDevices = false;
137137

@@ -168,12 +168,12 @@ std::vector<platform> platform_impl::get_platforms() {
168168

169169
// See which platform we want to be served by which adapter.
170170
// There should be just one adapter serving each backend.
171-
std::vector<AdapterPtr> &Adapters = ur::initializeUr();
172-
std::vector<std::pair<platform, AdapterPtr>> PlatformsWithAdapter;
171+
std::vector<adapter_impl *> &Adapters = ur::initializeUr();
172+
std::vector<std::pair<platform, adapter_impl *>> PlatformsWithAdapter;
173173

174174
// Then check backend-specific adapters
175175
for (auto &Adapter : Adapters) {
176-
const auto &AdapterPlatforms = getAdapterPlatforms(Adapter);
176+
const auto &AdapterPlatforms = getAdapterPlatforms(*Adapter);
177177
for (const auto &P : AdapterPlatforms) {
178178
PlatformsWithAdapter.push_back({P, Adapter});
179179
}
@@ -504,13 +504,13 @@ platform_impl::get_devices(info::device_type DeviceType) const {
504504
// analysis. Doing adjustment by simple copy of last device num from
505505
// previous platform.
506506
// Needs non const adapter reference.
507-
std::vector<AdapterPtr> &Adapters = ur::initializeUr();
507+
std::vector<adapter_impl *> &Adapters = ur::initializeUr();
508508
auto It = std::find_if(Adapters.begin(), Adapters.end(),
509-
[&Platform = MPlatform](AdapterPtr &Adapter) {
509+
[&Platform = MPlatform](adapter_impl *&Adapter) {
510510
return Adapter->containsUrPlatform(Platform);
511511
});
512512
if (It != Adapters.end()) {
513-
AdapterPtr &Adapter = *It;
513+
adapter_impl *&Adapter = *It;
514514
std::lock_guard<std::mutex> Guard(*Adapter->getAdapterMutex());
515515
Adapter->adjustLastDeviceId(MPlatform);
516516
}
@@ -530,7 +530,7 @@ platform_impl::get_devices(info::device_type DeviceType) const {
530530

531531
// Filter out devices that are not present in the SYCL_DEVICE_ALLOWLIST
532532
if (SYCLConfig<SYCL_DEVICE_ALLOWLIST>::get())
533-
applyAllowList(UrDevices, MPlatform, MAdapter);
533+
applyAllowList(UrDevices, MPlatform, *MAdapter);
534534

535535
// The first step is to filter out devices that are not compatible with
536536
// ONEAPI_DEVICE_SELECTOR. This is also the mechanism by which top level

sycl/source/detail/platform_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class platform_impl : public std::enable_shared_from_this<platform_impl> {
204204
device_impl *getDeviceImplHelper(ur_device_handle_t UrDevice);
205205

206206
// Helper to get the vector of platforms supported by a given UR adapter
207-
static std::vector<platform> getAdapterPlatforms(AdapterPtr &Adapter,
207+
static std::vector<platform> getAdapterPlatforms(adapter_impl &Adapter,
208208
bool Supported = true);
209209

210210
// Helper to filter reportable devices in the platform
@@ -216,7 +216,7 @@ class platform_impl : public std::enable_shared_from_this<platform_impl> {
216216
ur_platform_handle_t MPlatform = 0;
217217
backend MBackend;
218218

219-
AdapterPtr MAdapter;
219+
adapter_impl *MAdapter;
220220

221221
std::vector<std::shared_ptr<device_impl>> MDevices;
222222
friend class GlobalHandler;

sycl/source/detail/sycl_mem_obj_t.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ namespace detail {
3434
class context_impl;
3535
class event_impl;
3636
class adapter_impl;
37-
using AdapterPtr = adapter_impl *;
3837

3938
using EventImplPtr = std::shared_ptr<event_impl>;
4039

sycl/source/detail/ur.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static void initializeAdapters(std::vector<adapter_impl *> &Adapters,
9696
bool XPTIInitDone = false;
9797

9898
// Initializes all available Adapters.
99-
std::vector<AdapterPtr> &initializeUr(ur_loader_config_handle_t LoaderConfig) {
99+
std::vector<adapter_impl *> &
100+
initializeUr(ur_loader_config_handle_t LoaderConfig) {
100101
// This uses static variable initialization to work around a gcc bug with
101102
// std::call_once and exceptions.
102103
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146

sycl/source/detail/ur.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ inline namespace _V1 {
2525
enum class backend : char;
2626
namespace detail {
2727
class adapter_impl;
28-
using AdapterPtr = adapter_impl *;
2928

3029
namespace ur {
3130
void *getURLoaderLibrary();
3231

3332
// Performs UR one-time initialization.
34-
std::vector<AdapterPtr> &
33+
std::vector<adapter_impl *> &
3534
initializeUr(ur_loader_config_handle_t LoaderConfig = nullptr);
3635

3736
// Get the adapter serving given backend.

0 commit comments

Comments
 (0)