diff --git a/sycl/source/detail/allowlist.cpp b/sycl/source/detail/allowlist.cpp index f5d6c86cec26..c1600b3f68b4 100644 --- a/sycl/source/detail/allowlist.cpp +++ b/sycl/source/detail/allowlist.cpp @@ -364,8 +364,7 @@ bool deviceIsAllowed(const DeviceDescT &DeviceDesc, } void applyAllowList(std::vector &UrDevices, - ur_platform_handle_t UrPlatform, - const AdapterPtr &Adapter) { + ur_platform_handle_t UrPlatform, adapter_impl &Adapter) { AllowListParsedT AllowListParsed = parseAllowList(SYCLConfig::get()); @@ -375,7 +374,7 @@ void applyAllowList(std::vector &UrDevices, // Get platform's backend and put it to DeviceDesc DeviceDescT DeviceDesc; platform_impl &PlatformImpl = - platform_impl::getOrMakePlatformImpl(UrPlatform, *Adapter); + platform_impl::getOrMakePlatformImpl(UrPlatform, Adapter); backend Backend = PlatformImpl.getBackend(); for (const auto &SyclBe : getSyclBeMap()) { @@ -396,7 +395,7 @@ void applyAllowList(std::vector &UrDevices, device_impl &DeviceImpl = PlatformImpl.getOrMakeDeviceImpl(Device); // get DeviceType value and put it to DeviceDesc ur_device_type_t UrDevType = UR_DEVICE_TYPE_ALL; - Adapter->call( + Adapter.call( Device, UR_DEVICE_INFO_TYPE, sizeof(UrDevType), &UrDevType, nullptr); // TODO need mechanism to do these casts, there's a bunch of this sort of // thing diff --git a/sycl/source/detail/allowlist.hpp b/sycl/source/detail/allowlist.hpp index 656f6ed0e412..08205438322a 100644 --- a/sycl/source/detail/allowlist.hpp +++ b/sycl/source/detail/allowlist.hpp @@ -28,7 +28,7 @@ bool deviceIsAllowed(const DeviceDescT &DeviceDesc, const AllowListParsedT &AllowListParsed); void applyAllowList(std::vector &UrDevices, - ur_platform_handle_t UrPlatform, const AdapterPtr &Adapter); + ur_platform_handle_t UrPlatform, adapter_impl &Adapter); } // namespace detail } // namespace _V1 diff --git a/sycl/source/detail/context_impl.cpp b/sycl/source/detail/context_impl.cpp index 25755426ebc2..28f4beef8000 100644 --- a/sycl/source/detail/context_impl.cpp +++ b/sycl/source/detail/context_impl.cpp @@ -120,7 +120,7 @@ context_impl::~context_impl() { try { // Free all events associated with the initialization of device globals. for (auto &DeviceGlobalInitializer : MDeviceGlobalInitializers) - DeviceGlobalInitializer.second.ClearEvents(&getAdapter()); + DeviceGlobalInitializer.second.ClearEvents(getAdapter()); // Free all device_global USM allocations associated with this context. for (const void *DeviceGlobal : MAssociatedDeviceGlobals) { DeviceGlobalMapEntry *DGEntry = @@ -146,7 +146,7 @@ const async_handler &context_impl::get_async_handler() const { template <> uint32_t context_impl::get_info() const { return get_context_info(this->getHandleRef(), - &this->getAdapter()); + this->getAdapter()); } template <> platform context_impl::get_info() const { return createSyclObjFromImpl(*MPlatform); @@ -449,10 +449,9 @@ std::vector context_impl::initializeDeviceGlobals( } } -void context_impl::DeviceGlobalInitializer::ClearEvents( - const AdapterPtr &Adapter) { +void context_impl::DeviceGlobalInitializer::ClearEvents(adapter_impl &Adapter) { for (const ur_event_handle_t &Event : MDeviceGlobalInitEvents) - Adapter->call(Event); + Adapter.call(Event); MDeviceGlobalInitEvents.clear(); } diff --git a/sycl/source/detail/context_impl.hpp b/sycl/source/detail/context_impl.hpp index 6aa7ba2bc871..25648578fc2c 100644 --- a/sycl/source/detail/context_impl.hpp +++ b/sycl/source/detail/context_impl.hpp @@ -295,7 +295,7 @@ class context_impl : public std::enable_shared_from_this { } /// Clears all events of the initializer. This will not acquire the lock. - void ClearEvents(const AdapterPtr &Adapter); + void ClearEvents(adapter_impl &Adapter); /// The binary image of the program. const RTDeviceBinaryImage *MBinImage = nullptr; diff --git a/sycl/source/detail/context_info.hpp b/sycl/source/detail/context_info.hpp index 65a123b79602..19ad4dd58803 100644 --- a/sycl/source/detail/context_info.hpp +++ b/sycl/source/detail/context_info.hpp @@ -20,13 +20,13 @@ namespace detail { template typename Param::return_type get_context_info(ur_context_handle_t Ctx, - const AdapterPtr &Adapter) { + adapter_impl &Adapter) { static_assert(is_context_info_desc::value, "Invalid context information descriptor"); typename Param::return_type Result = 0; // TODO catch an exception and put it to list of asynchronous exceptions - Adapter->call(Ctx, UrInfoCode::value, - sizeof(Result), &Result, nullptr); + Adapter.call(Ctx, UrInfoCode::value, + sizeof(Result), &Result, nullptr); return Result; } diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index bc3c3cc6d464..16d156d9d682 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -119,11 +119,11 @@ static bool IsBannedPlatform(platform Platform) { // replace uses of this with a helper in adapter object, the adapter // objects will own the ur adapter handles and they'll need to pass them to // urPlatformsGet - so urPlatformsGet will need to be wrapped with a helper -std::vector platform_impl::getAdapterPlatforms(AdapterPtr &Adapter, +std::vector platform_impl::getAdapterPlatforms(adapter_impl &Adapter, bool Supported) { std::vector Platforms; - auto UrPlatforms = Adapter->getUrPlatforms(); + auto UrPlatforms = Adapter.getUrPlatforms(); if (UrPlatforms.empty()) { return Platforms; @@ -131,7 +131,7 @@ std::vector platform_impl::getAdapterPlatforms(AdapterPtr &Adapter, for (const auto &UrPlatform : UrPlatforms) { platform Platform = detail::createSyclObjFromImpl( - getOrMakePlatformImpl(UrPlatform, *Adapter)); + getOrMakePlatformImpl(UrPlatform, Adapter)); const bool IsBanned = IsBannedPlatform(Platform); bool HasAnyDevices = false; @@ -168,12 +168,12 @@ std::vector platform_impl::get_platforms() { // See which platform we want to be served by which adapter. // There should be just one adapter serving each backend. - std::vector &Adapters = ur::initializeUr(); - std::vector> PlatformsWithAdapter; + std::vector &Adapters = ur::initializeUr(); + std::vector> PlatformsWithAdapter; // Then check backend-specific adapters for (auto &Adapter : Adapters) { - const auto &AdapterPlatforms = getAdapterPlatforms(Adapter); + const auto &AdapterPlatforms = getAdapterPlatforms(*Adapter); for (const auto &P : AdapterPlatforms) { PlatformsWithAdapter.push_back({P, Adapter}); } @@ -504,13 +504,13 @@ platform_impl::get_devices(info::device_type DeviceType) const { // analysis. Doing adjustment by simple copy of last device num from // previous platform. // Needs non const adapter reference. - std::vector &Adapters = ur::initializeUr(); + std::vector &Adapters = ur::initializeUr(); auto It = std::find_if(Adapters.begin(), Adapters.end(), - [&Platform = MPlatform](AdapterPtr &Adapter) { + [&Platform = MPlatform](adapter_impl *&Adapter) { return Adapter->containsUrPlatform(Platform); }); if (It != Adapters.end()) { - AdapterPtr &Adapter = *It; + adapter_impl *&Adapter = *It; std::lock_guard Guard(*Adapter->getAdapterMutex()); Adapter->adjustLastDeviceId(MPlatform); } @@ -530,7 +530,7 @@ platform_impl::get_devices(info::device_type DeviceType) const { // Filter out devices that are not present in the SYCL_DEVICE_ALLOWLIST if (SYCLConfig::get()) - applyAllowList(UrDevices, MPlatform, MAdapter); + applyAllowList(UrDevices, MPlatform, *MAdapter); // The first step is to filter out devices that are not compatible with // ONEAPI_DEVICE_SELECTOR. This is also the mechanism by which top level diff --git a/sycl/source/detail/platform_impl.hpp b/sycl/source/detail/platform_impl.hpp index 6d14563e4b1a..b6057b9d5252 100644 --- a/sycl/source/detail/platform_impl.hpp +++ b/sycl/source/detail/platform_impl.hpp @@ -204,7 +204,7 @@ class platform_impl : public std::enable_shared_from_this { device_impl *getDeviceImplHelper(ur_device_handle_t UrDevice); // Helper to get the vector of platforms supported by a given UR adapter - static std::vector getAdapterPlatforms(AdapterPtr &Adapter, + static std::vector getAdapterPlatforms(adapter_impl &Adapter, bool Supported = true); // Helper to filter reportable devices in the platform @@ -216,7 +216,7 @@ class platform_impl : public std::enable_shared_from_this { ur_platform_handle_t MPlatform = 0; backend MBackend; - AdapterPtr MAdapter; + adapter_impl *MAdapter; std::vector> MDevices; friend class GlobalHandler; diff --git a/sycl/source/detail/sycl_mem_obj_t.hpp b/sycl/source/detail/sycl_mem_obj_t.hpp index e5f8b7a4d3bd..bda749da4de8 100644 --- a/sycl/source/detail/sycl_mem_obj_t.hpp +++ b/sycl/source/detail/sycl_mem_obj_t.hpp @@ -34,7 +34,6 @@ namespace detail { class context_impl; class event_impl; class adapter_impl; -using AdapterPtr = adapter_impl *; using EventImplPtr = std::shared_ptr; diff --git a/sycl/source/detail/ur.cpp b/sycl/source/detail/ur.cpp index 8f003bba5434..df3534c32060 100644 --- a/sycl/source/detail/ur.cpp +++ b/sycl/source/detail/ur.cpp @@ -96,7 +96,8 @@ static void initializeAdapters(std::vector &Adapters, bool XPTIInitDone = false; // Initializes all available Adapters. -std::vector &initializeUr(ur_loader_config_handle_t LoaderConfig) { +std::vector & +initializeUr(ur_loader_config_handle_t LoaderConfig) { // This uses static variable initialization to work around a gcc bug with // std::call_once and exceptions. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146 diff --git a/sycl/source/detail/ur.hpp b/sycl/source/detail/ur.hpp index 62aea03c3d39..0262c2471820 100644 --- a/sycl/source/detail/ur.hpp +++ b/sycl/source/detail/ur.hpp @@ -25,13 +25,12 @@ inline namespace _V1 { enum class backend : char; namespace detail { class adapter_impl; -using AdapterPtr = adapter_impl *; namespace ur { void *getURLoaderLibrary(); // Performs UR one-time initialization. -std::vector & +std::vector & initializeUr(ur_loader_config_handle_t LoaderConfig = nullptr); // Get the adapter serving given backend.