diff --git a/sycl/doc/EnvironmentVariables.md b/sycl/doc/EnvironmentVariables.md index c6838ba2c099..032ea3743154 100755 --- a/sycl/doc/EnvironmentVariables.md +++ b/sycl/doc/EnvironmentVariables.md @@ -191,6 +191,7 @@ variables in production code. | Environment variable | Values | Description | | -------------------- | ------ | ----------- | +| `SYCL_PREFER_UR` | Integer | If non-0 then run through Unified Runtime if desired backend is supported there. Default is 0. | | `SYCL_PI_TRACE` | Described [below](#sycl_pi_trace-options) | Enable specified level of tracing for PI. | | `SYCL_QUEUE_THREAD_POOL_SIZE` | Positive integer | Number of threads in thread pool of queue. | | `SYCL_DEVICELIB_NO_FALLBACK` | Any(\*) | Disable loading and linking of device library images | diff --git a/sycl/include/sycl/detail/pi.hpp b/sycl/include/sycl/detail/pi.hpp index a814802fbc45..a5ca74419e55 100644 --- a/sycl/include/sycl/detail/pi.hpp +++ b/sycl/include/sycl/detail/pi.hpp @@ -44,6 +44,7 @@ enum class PiApiKind { #include }; class plugin; +using PluginPtr = std::shared_ptr; template __SYCL_EXPORT void *getPluginOpaqueData(void *opaquedata_arg); @@ -70,12 +71,14 @@ bool trace(TraceLevel level); #define __SYCL_CUDA_PLUGIN_NAME "pi_cuda.dll" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "pi_esimd_emulator.dll" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dll" +#define __SYCL_UR_PLUGIN_NAME "pi_unified_runtime.dll" #else #define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.dll" #define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.dll" #define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.dll" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.dll" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dll" +#define __SYCL_UR_PLUGIN_NAME "libpi_unified_runtime.dll" #endif #elif defined(__SYCL_RT_OS_LINUX) #define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.so" @@ -83,12 +86,14 @@ bool trace(TraceLevel level); #define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.so" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.so" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.so" +#define __SYCL_UR_PLUGIN_NAME "libpi_unified_runtime.so" #elif defined(__SYCL_RT_OS_DARWIN) #define __SYCL_OPENCL_PLUGIN_NAME "libpi_opencl.dylib" #define __SYCL_LEVEL_ZERO_PLUGIN_NAME "libpi_level_zero.dylib" #define __SYCL_CUDA_PLUGIN_NAME "libpi_cuda.dylib" #define __SYCL_ESIMD_EMULATOR_PLUGIN_NAME "libpi_esimd_emulator.dylib" #define __SYCL_HIP_PLUGIN_NAME "libpi_hip.dylib" +#define __SYCL_UR_PLUGIN_NAME "libpi_unified_runtime.dylib" #else #error "Unsupported OS" #endif @@ -176,10 +181,10 @@ template To cast(From value); extern std::shared_ptr GlobalPlugin; // Performs PI one-time initialization. -std::vector &initialize(); +std::vector &initialize(); // Get the plugin serving given backend. -template __SYCL_EXPORT const plugin &getPlugin(); +template __SYCL_EXPORT const PluginPtr &getPlugin(); // Utility Functions to get Function Name for a PI Api. template struct PiFuncInfo {}; diff --git a/sycl/plugins/unified_runtime/CMakeLists.txt b/sycl/plugins/unified_runtime/CMakeLists.txt index 336f24db7044..b4c1a0c6d336 100755 --- a/sycl/plugins/unified_runtime/CMakeLists.txt +++ b/sycl/plugins/unified_runtime/CMakeLists.txt @@ -123,4 +123,20 @@ set_target_properties("ur_adapter_level_zero" PROPERTIES if (TARGET UnifiedRuntimeLoader) set_target_properties(hello_world PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) + # Install the UR loader. + # TODO: this is piggy-backing on the existing target component level-zero-sycl-dev + # When UR is moved to its separate repo perhaps we should introduce new component, + # e.g. unified-runtime-sycl-dev. + install(TARGETS loader + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-sycl-dev + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT level-zero-sycl-dev + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-sycl-dev + ) endif() + +# Install the UR adapters too +install(TARGETS ur_adapter_level_zero +ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-sycl-dev +RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT level-zero-sycl-dev +LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-sycl-dev +) diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 829ba08746d9..499616fd6dcf 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -29,7 +29,7 @@ namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { namespace detail { -static const plugin &getPlugin(backend Backend) { +static const PluginPtr &getPlugin(backend Backend) { switch (Backend) { case backend::opencl: return pi::getPlugin(); @@ -67,8 +67,8 @@ platform make_platform(pi_native_handle NativeHandle, backend Backend) { // Create PI platform first. pi::PiPlatform PiPlatform = nullptr; - Plugin.call(NativeHandle, - &PiPlatform); + Plugin->call(NativeHandle, + &PiPlatform); return detail::createSyclObjFromImpl( platform_impl::getOrMakePlatformImpl(PiPlatform, Plugin)); @@ -79,8 +79,8 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle, const auto &Plugin = getPlugin(Backend); pi::PiDevice PiDevice = nullptr; - Plugin.call(NativeHandle, - nullptr, &PiDevice); + Plugin->call( + NativeHandle, nullptr, &PiDevice); // Construct the SYCL device from PI device. return detail::createSyclObjFromImpl( std::make_shared(PiDevice, Plugin)); @@ -92,7 +92,7 @@ __SYCL_EXPORT context make_context(pi_native_handle NativeHandle, const auto &Plugin = getPlugin(Backend); pi::PiContext PiContext = nullptr; - Plugin.call( + Plugin->call( NativeHandle, 0, nullptr, false, &PiContext); // Construct the SYCL context from PI context. return detail::createSyclObjFromImpl( @@ -106,7 +106,7 @@ queue make_queue_impl(pi_native_handle NativeHandle, const context &Context, const auto &ContextImpl = getSyclObjImpl(Context); // Create PI queue first. pi::PiQueue PiQueue = nullptr; - Plugin.call( + Plugin->call( NativeHandle, ContextImpl->getHandleRef(), Device, !KeepOwnership, &PiQueue); // Construct the SYCL queue from PI queue. @@ -155,7 +155,7 @@ __SYCL_EXPORT queue make_queue2(pi_native_handle NativeHandle, // Create PI queue first. pi::PiQueue PiQueue = nullptr; - Plugin.call( + Plugin->call( NativeHandle, NativeHandleDesc, ContextImpl->getHandleRef(), PiDevice, !KeepOwnership, Properties, &PiQueue); // Construct the SYCL queue from PI queue. @@ -175,14 +175,14 @@ __SYCL_EXPORT event make_event(pi_native_handle NativeHandle, const auto &ContextImpl = getSyclObjImpl(Context); pi::PiEvent PiEvent = nullptr; - Plugin.call( + Plugin->call( NativeHandle, ContextImpl->getHandleRef(), !KeepOwnership, &PiEvent); event Event = detail::createSyclObjFromImpl( std::make_shared(PiEvent, Context)); if (Backend == backend::opencl) - Plugin.call(PiEvent); + Plugin->call(PiEvent); return Event; } @@ -193,34 +193,34 @@ make_kernel_bundle(pi_native_handle NativeHandle, const context &TargetContext, const auto &ContextImpl = getSyclObjImpl(TargetContext); pi::PiProgram PiProgram = nullptr; - Plugin.call( + Plugin->call( NativeHandle, ContextImpl->getHandleRef(), !KeepOwnership, &PiProgram); if (ContextImpl->getBackend() == backend::opencl) - Plugin.call(PiProgram); + Plugin->call(PiProgram); std::vector ProgramDevices; size_t NumDevices = 0; - Plugin.call( + Plugin->call( PiProgram, PI_PROGRAM_INFO_NUM_DEVICES, sizeof(size_t), &NumDevices, nullptr); ProgramDevices.resize(NumDevices); - Plugin.call(PiProgram, PI_PROGRAM_INFO_DEVICES, - sizeof(pi::PiDevice) * NumDevices, - ProgramDevices.data(), nullptr); + Plugin->call(PiProgram, PI_PROGRAM_INFO_DEVICES, + sizeof(pi::PiDevice) * NumDevices, + ProgramDevices.data(), nullptr); for (const auto &Dev : ProgramDevices) { size_t BinaryType = 0; - Plugin.call( + Plugin->call( PiProgram, Dev, PI_PROGRAM_BUILD_INFO_BINARY_TYPE, sizeof(size_t), &BinaryType, nullptr); switch (BinaryType) { case (PI_PROGRAM_BINARY_TYPE_NONE): if (State == bundle_state::object) - Plugin.call( + Plugin->call( PiProgram, 1, &Dev, nullptr, 0, nullptr, nullptr, nullptr, nullptr); else if (State == bundle_state::executable) - Plugin.call( + Plugin->call( PiProgram, 1, &Dev, nullptr, nullptr, nullptr); break; case (PI_PROGRAM_BINARY_TYPE_COMPILED_OBJECT): @@ -231,7 +231,7 @@ make_kernel_bundle(pi_native_handle NativeHandle, const context &TargetContext, "Program and kernel_bundle state mismatch", PI_ERROR_INVALID_VALUE); if (State == bundle_state::executable) - Plugin.call( + Plugin->call( ContextImpl->getHandleRef(), 1, &Dev, nullptr, 1, &PiProgram, nullptr, nullptr, &PiProgram); break; @@ -306,12 +306,12 @@ kernel make_kernel(const context &TargetContext, // Create PI kernel first. pi::PiKernel PiKernel = nullptr; - Plugin.call( + Plugin->call( NativeHandle, ContextImpl->getHandleRef(), PiProgram, !KeepOwnership, &PiKernel); if (Backend == backend::opencl) - Plugin.call(PiKernel); + Plugin->call(PiKernel); // Construct the SYCL queue from PI queue. return detail::createSyclObjFromImpl( diff --git a/sycl/source/backend/level_zero.cpp b/sycl/source/backend/level_zero.cpp index c363a9c143d3..3b03e24b4a5c 100644 --- a/sycl/source/backend/level_zero.cpp +++ b/sycl/source/backend/level_zero.cpp @@ -32,7 +32,7 @@ __SYCL_EXPORT device make_device(const platform &Platform, const auto &PlatformImpl = getSyclObjImpl(Platform); // Create PI device first. pi::PiDevice PiDevice; - Plugin.call( + Plugin->call( NativeHandle, PlatformImpl->getHandleRef(), &PiDevice); return detail::createSyclObjFromImpl( @@ -51,7 +51,7 @@ __SYCL_EXPORT context make_context(const std::vector &DeviceList, for (auto Dev : DeviceList) { DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef()); } - Plugin.call( + Plugin->call( NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership, &PiContext); // Construct the SYCL context from PI context. diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index 8dd6aaa4b393..8b3a9570858e 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -62,21 +62,21 @@ __SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform, std::shared_ptr PlatformImpl = getSyclObjImpl(SyclPlatform); detail::RT::PiPlatform PluginPlatform = PlatformImpl->getHandleRef(); - const plugin &Plugin = PlatformImpl->getPlugin(); + const PluginPtr &Plugin = PlatformImpl->getPlugin(); // Manual invocation of plugin API to avoid using deprecated // info::platform::extensions call. size_t ResultSize = 0; - Plugin.call( + Plugin->call( PluginPlatform, PI_PLATFORM_INFO_EXTENSIONS, /*param_value_size=*/0, /*param_value_size=*/nullptr, &ResultSize); if (ResultSize == 0) return false; std::unique_ptr Result(new char[ResultSize]); - Plugin.call(PluginPlatform, - PI_PLATFORM_INFO_EXTENSIONS, - ResultSize, Result.get(), nullptr); + Plugin->call(PluginPlatform, + PI_PLATFORM_INFO_EXTENSIONS, + ResultSize, Result.get(), nullptr); std::string_view ExtensionsString(Result.get()); return ExtensionsString.find(Extension) != std::string::npos; @@ -93,21 +93,21 @@ __SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice, std::shared_ptr DeviceImpl = getSyclObjImpl(SyclDevice); detail::RT::PiDevice PluginDevice = DeviceImpl->getHandleRef(); - const plugin &Plugin = DeviceImpl->getPlugin(); + const PluginPtr &Plugin = DeviceImpl->getPlugin(); // Manual invocation of plugin API to avoid using deprecated // info::device::extensions call. size_t ResultSize = 0; - Plugin.call( + Plugin->call( PluginDevice, PI_DEVICE_INFO_EXTENSIONS, /*param_value_size=*/0, /*param_value_size=*/nullptr, &ResultSize); if (ResultSize == 0) return false; std::unique_ptr Result(new char[ResultSize]); - Plugin.call(PluginDevice, - PI_DEVICE_INFO_EXTENSIONS, ResultSize, - Result.get(), nullptr); + Plugin->call(PluginDevice, + PI_DEVICE_INFO_EXTENSIONS, + ResultSize, Result.get(), nullptr); std::string_view ExtensionsString(Result.get()); return ExtensionsString.find(Extension) != std::string::npos; diff --git a/sycl/source/detail/allowlist.cpp b/sycl/source/detail/allowlist.cpp index 2bb9e7f6669c..af24ff03a118 100644 --- a/sycl/source/detail/allowlist.cpp +++ b/sycl/source/detail/allowlist.cpp @@ -335,7 +335,7 @@ bool deviceIsAllowed(const DeviceDescT &DeviceDesc, } void applyAllowList(std::vector &PiDevices, - RT::PiPlatform PiPlatform, const plugin &Plugin) { + RT::PiPlatform PiPlatform, const PluginPtr &Plugin) { AllowListParsedT AllowListParsed = parseAllowList(SYCLConfig::get()); @@ -367,9 +367,9 @@ void applyAllowList(std::vector &PiDevices, auto DeviceImpl = PlatformImpl->getOrMakeDeviceImpl(Device, PlatformImpl); // get DeviceType value and put it to DeviceDesc RT::PiDeviceType PiDevType; - Plugin.call(Device, PI_DEVICE_INFO_TYPE, - sizeof(RT::PiDeviceType), - &PiDevType, nullptr); + Plugin->call(Device, PI_DEVICE_INFO_TYPE, + sizeof(RT::PiDeviceType), + &PiDevType, nullptr); sycl::info::device_type DeviceType = pi::cast(PiDevType); for (const auto &SyclDeviceType : getSyclDeviceTypeMap()) { if (SyclDeviceType.second == DeviceType) { diff --git a/sycl/source/detail/allowlist.hpp b/sycl/source/detail/allowlist.hpp index 21325477044f..25598631ce73 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 &PiDevices, - RT::PiPlatform PiPlatform, const plugin &Plugin); + RT::PiPlatform PiPlatform, const PluginPtr &Plugin); } // namespace detail } // __SYCL_INLINE_VER_NAMESPACE(_V1) diff --git a/sycl/source/detail/buffer_impl.cpp b/sycl/source/detail/buffer_impl.cpp index e2cb7bf17f6a..96fb885f66cc 100644 --- a/sycl/source/detail/buffer_impl.cpp +++ b/sycl/source/detail/buffer_impl.cpp @@ -50,8 +50,8 @@ void buffer_impl::addInteropObject( if (std::find(Handles.begin(), Handles.end(), pi::cast(MInteropMemObject)) == Handles.end()) { - const plugin &Plugin = getPlugin(); - Plugin.call( + const PluginPtr &Plugin = getPlugin(); + Plugin->call( pi::cast(MInteropMemObject)); Handles.push_back(pi::cast(MInteropMemObject)); } @@ -79,11 +79,11 @@ buffer_impl::getNativeVector(backend BackendName) const { if (Platform->getBackend() != BackendName) continue; if (Platform->getBackend() == backend::opencl) { - Plugin.call(NativeMem); + Plugin->call(NativeMem); } pi_native_handle Handle; - Plugin.call(NativeMem, &Handle); + Plugin->call(NativeMem, &Handle); Handles.push_back(Handle); } diff --git a/sycl/source/detail/context_impl.cpp b/sycl/source/detail/context_impl.cpp index e312c3102661..5c8c2040ecd9 100644 --- a/sycl/source/detail/context_impl.cpp +++ b/sycl/source/detail/context_impl.cpp @@ -58,33 +58,33 @@ context_impl::context_impl(const std::vector Devices, __SYCL_PI_CONTEXT_PROPERTIES_CUDA_PRIMARY), static_cast(UseCUDAPrimaryContext), 0}; - getPlugin().call( + getPlugin()->call( Props, DeviceIds.size(), DeviceIds.data(), nullptr, nullptr, &MContext); } else { - getPlugin().call(nullptr, DeviceIds.size(), - DeviceIds.data(), nullptr, - nullptr, &MContext); + getPlugin()->call(nullptr, DeviceIds.size(), + DeviceIds.data(), nullptr, + nullptr, &MContext); } MKernelProgramCache.setContextPtr(this); } context_impl::context_impl(RT::PiContext PiContext, async_handler AsyncHandler, - const plugin &Plugin) + const PluginPtr &Plugin) : MAsyncHandler(AsyncHandler), MDevices(), MContext(PiContext), MPlatform(), MHostContext(false), MSupportBufferLocationByDevices(NotChecked) { std::vector DeviceIds; size_t DevicesNum = 0; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + Plugin->call( MContext, PI_CONTEXT_INFO_NUM_DEVICES, sizeof(DevicesNum), &DevicesNum, nullptr); DeviceIds.resize(DevicesNum); // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(MContext, PI_CONTEXT_INFO_DEVICES, - sizeof(RT::PiDevice) * DevicesNum, - &DeviceIds[0], nullptr); + Plugin->call(MContext, PI_CONTEXT_INFO_DEVICES, + sizeof(RT::PiDevice) * DevicesNum, + &DeviceIds[0], nullptr); if (!DeviceIds.empty()) { std::shared_ptr Platform = @@ -102,7 +102,7 @@ context_impl::context_impl(RT::PiContext PiContext, async_handler AsyncHandler, // TODO: Move this backend-specific retain of the context to SYCL-2020 style // make_context interop, when that is created. if (getBackend() == sycl::backend::opencl) { - getPlugin().call(MContext); + getPlugin()->call(MContext); } MKernelProgramCache.setContextPtr(this); } @@ -114,7 +114,7 @@ cl_context context_impl::get() const { PI_ERROR_INVALID_CONTEXT); } // TODO catch an exception and put it to list of asynchronous exceptions - getPlugin().call(MContext); + getPlugin()->call(MContext); return pi::cast(MContext); } @@ -133,11 +133,11 @@ context_impl::~context_impl() { } for (auto LibProg : MCachedLibPrograms) { assert(LibProg.second && "Null program must not be kept in the cache"); - getPlugin().call(LibProg.second); + getPlugin()->call(LibProg.second); } if (!MHostContext) { // TODO catch an exception and put it to list of asynchronous exceptions - getPlugin().call_nocheck(MContext); + getPlugin()->call_nocheck(MContext); } } @@ -255,11 +255,11 @@ context_impl::findMatchingDeviceImpl(RT::PiDevice &DevicePI) const { } pi_native_handle context_impl::getNative() const { - auto Plugin = getPlugin(); + const auto &Plugin = getPlugin(); if (getBackend() == backend::opencl) - Plugin.call(getHandleRef()); + Plugin->call(getHandleRef()); pi_native_handle Handle; - Plugin.call(getHandleRef(), &Handle); + Plugin->call(getHandleRef(), &Handle); return Handle; } @@ -294,7 +294,7 @@ void context_impl::addDeviceGlobalInitializer( std::vector context_impl::initializeDeviceGlobals( pi::PiProgram NativePrg, const std::shared_ptr &QueueImpl) { - const plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); const DeviceImplPtr &DeviceImpl = QueueImpl->getDeviceImplPtr(); std::lock_guard NativeProgramLock(MDeviceGlobalInitializersMutex); auto ImgIt = MDeviceGlobalInitializers.find( @@ -317,7 +317,7 @@ std::vector context_impl::initializeDeviceGlobals( }); // Release the removed events. for (auto EventIt = NewEnd; EventIt != InitEventsRef.end(); ++EventIt) - Plugin.call(*EventIt); + Plugin->call(*EventIt); // Remove them from the collection. InitEventsRef.erase(NewEnd, InitEventsRef.end()); // If there are no more events, we can mark it as fully initialized. @@ -375,7 +375,7 @@ std::vector context_impl::initializeDeviceGlobals( // initialize events list. RT::PiEvent InitEvent; void *const &USMPtr = DeviceGlobalUSM.getPtr(); - Plugin.call( + Plugin->call( QueueImpl->getHandleRef(), NativePrg, DeviceGlobalEntry->MUniqueId.c_str(), false, sizeof(void *), 0, &USMPtr, 0, nullptr, &InitEvent); @@ -387,9 +387,10 @@ std::vector context_impl::initializeDeviceGlobals( } } -void context_impl::DeviceGlobalInitializer::ClearEvents(const plugin &Plugin) { +void context_impl::DeviceGlobalInitializer::ClearEvents( + const PluginPtr &Plugin) { for (const RT::PiEvent &Event : MDeviceGlobalInitEvents) - Plugin.call(Event); + Plugin->call(Event); MDeviceGlobalInitEvents.clear(); } diff --git a/sycl/source/detail/context_impl.hpp b/sycl/source/detail/context_impl.hpp index d660636bbf2b..e22fbabf8087 100644 --- a/sycl/source/detail/context_impl.hpp +++ b/sycl/source/detail/context_impl.hpp @@ -69,7 +69,7 @@ class context_impl { /// \param Plugin is the reference to the underlying Plugin that this /// context is associated with. context_impl(RT::PiContext PiContext, async_handler AsyncHandler, - const plugin &Plugin); + const PluginPtr &Plugin); ~context_impl(); @@ -106,7 +106,7 @@ class context_impl { const async_handler &get_async_handler() const; /// \return the Plugin associated with the platform of this context. - const plugin &getPlugin() const { return MPlatform->getPlugin(); } + const PluginPtr &getPlugin() const { return MPlatform->getPlugin(); } /// \return the PlatformImpl associated with this context. PlatformImplPtr getPlatformImpl() const { return MPlatform; } @@ -266,7 +266,7 @@ class context_impl { } /// Clears all events of the initializer. This will not acquire the lock. - void ClearEvents(const plugin &Plugin); + void ClearEvents(const PluginPtr &Plugin); /// 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 d30113dc6d08..40e487e3e001 100644 --- a/sycl/source/detail/context_info.hpp +++ b/sycl/source/detail/context_info.hpp @@ -19,13 +19,13 @@ namespace detail { template typename Param::return_type get_context_info(RT::PiContext Ctx, - const plugin &Plugin) { + const PluginPtr &Plugin) { 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 - Plugin.call(Ctx, PiInfoCode::value, - sizeof(Result), &Result, nullptr); + Plugin->call(Ctx, PiInfoCode::value, + sizeof(Result), &Result, nullptr); return Result; } diff --git a/sycl/source/detail/device_global_map_entry.cpp b/sycl/source/detail/device_global_map_entry.cpp index 39920181d2cc..4ae425fb1347 100644 --- a/sycl/source/detail/device_global_map_entry.cpp +++ b/sycl/source/detail/device_global_map_entry.cpp @@ -26,13 +26,13 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() { "MZeroInitEvent has not been cleaned up."); } -OwnedPiEvent DeviceGlobalUSMMem::getZeroInitEvent(const plugin &Plugin) { +OwnedPiEvent DeviceGlobalUSMMem::getZeroInitEvent(const PluginPtr &Plugin) { std::lock_guard Lock(MZeroInitEventMutex); // If there is a zero-init event we can remove it if it is done. if (MZeroInitEvent.has_value()) { if (get_event_info( *MZeroInitEvent, Plugin) == info::event_command_status::complete) { - Plugin.call(*MZeroInitEvent); + Plugin->call(*MZeroInitEvent); MZeroInitEvent = {}; return OwnedPiEvent(Plugin); } else { @@ -90,7 +90,7 @@ void DeviceGlobalMapEntry::removeAssociatedResources( DeviceGlobalUSMMem &USMMem = USMPtrIt->second; detail::usm::freeInternal(USMMem.MPtr, CtxImpl); if (USMMem.MZeroInitEvent.has_value()) - CtxImpl->getPlugin().call( + CtxImpl->getPlugin()->call( *USMMem.MZeroInitEvent); #ifndef NDEBUG // For debugging we set the event and memory to some recognizable values diff --git a/sycl/source/detail/device_global_map_entry.hpp b/sycl/source/detail/device_global_map_entry.hpp index 9fe4de71b4b2..8f8cb7a7cde2 100644 --- a/sycl/source/detail/device_global_map_entry.hpp +++ b/sycl/source/detail/device_global_map_entry.hpp @@ -36,7 +36,7 @@ struct DeviceGlobalUSMMem { // Gets the zero-initialization event if it exists. If not the OwnedPiEvent // will contain no event. - OwnedPiEvent getZeroInitEvent(const plugin &Plugin); + OwnedPiEvent getZeroInitEvent(const PluginPtr &Plugin); private: void *MPtr; diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index fab5c26e3c24..5f81c3e4470d 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -218,7 +218,7 @@ class device_image_impl { RT::PiMem &get_spec_const_buffer_ref() noexcept { std::lock_guard Lock{MSpecConstAccessMtx}; if (nullptr == MSpecConstsBuffer && !MSpecConstsBlob.empty()) { - const detail::plugin &Plugin = getSyclObjImpl(MContext)->getPlugin(); + const PluginPtr &Plugin = getSyclObjImpl(MContext)->getPlugin(); // Uses PI_MEM_FLAGS_HOST_PTR_COPY instead of PI_MEM_FLAGS_HOST_PTR_USE // since post-enqueue cleanup might trigger destruction of // device_image_impl and, as a result, destruction of MSpecConstsBlob @@ -244,13 +244,13 @@ class device_image_impl { pi_native_handle getNative() const { assert(MProgram); const auto &ContextImplPtr = detail::getSyclObjImpl(MContext); - const plugin &Plugin = ContextImplPtr->getPlugin(); + const PluginPtr &Plugin = ContextImplPtr->getPlugin(); if (ContextImplPtr->getBackend() == backend::opencl) - Plugin.call(MProgram); + Plugin->call(MProgram); pi_native_handle NativeProgram = 0; - Plugin.call(MProgram, - &NativeProgram); + Plugin->call(MProgram, + &NativeProgram); return NativeProgram; } @@ -258,12 +258,12 @@ class device_image_impl { ~device_image_impl() { if (MProgram) { - const detail::plugin &Plugin = getSyclObjImpl(MContext)->getPlugin(); - Plugin.call(MProgram); + const PluginPtr &Plugin = getSyclObjImpl(MContext)->getPlugin(); + Plugin->call(MProgram); } if (MSpecConstsBuffer) { std::lock_guard Lock{MSpecConstAccessMtx}; - const detail::plugin &Plugin = getSyclObjImpl(MContext)->getPlugin(); + const PluginPtr &Plugin = getSyclObjImpl(MContext)->getPlugin(); memReleaseHelper(Plugin, MSpecConstsBuffer); } } diff --git a/sycl/source/detail/device_impl.cpp b/sycl/source/detail/device_impl.cpp index 2cdb713ace74..14e991df767a 100644 --- a/sycl/source/detail/device_impl.cpp +++ b/sycl/source/detail/device_impl.cpp @@ -23,20 +23,20 @@ device_impl::device_impl() MIsAssertFailSupported(true) {} device_impl::device_impl(pi_native_handle InteropDeviceHandle, - const plugin &Plugin) + const PluginPtr &Plugin) : device_impl(InteropDeviceHandle, nullptr, nullptr, Plugin) {} device_impl::device_impl(RT::PiDevice Device, PlatformImplPtr Platform) : device_impl(reinterpret_cast(nullptr), Device, Platform, Platform->getPlugin()) {} -device_impl::device_impl(RT::PiDevice Device, const plugin &Plugin) +device_impl::device_impl(RT::PiDevice Device, const PluginPtr &Plugin) : device_impl(reinterpret_cast(nullptr), Device, nullptr, Plugin) {} device_impl::device_impl(pi_native_handle InteropDeviceHandle, RT::PiDevice Device, PlatformImplPtr Platform, - const plugin &Plugin) + const PluginPtr &Plugin) : MDevice(Device), MIsHostDevice(false), MDeviceHostBaseTime(std::make_pair(0, 0)) { @@ -46,19 +46,19 @@ device_impl::device_impl(pi_native_handle InteropDeviceHandle, // Get PI device from the raw device handle. // NOTE: this is for OpenCL interop only (and should go away). // With SYCL-2020 BE generalization "make" functions are used instead. - Plugin.call( + Plugin->call( InteropDeviceHandle, nullptr, &MDevice); InteroperabilityConstructor = true; } // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + Plugin->call( MDevice, PI_DEVICE_INFO_TYPE, sizeof(RT::PiDeviceType), &MType, nullptr); // No need to set MRootDevice when MAlwaysRootDevice is true if ((Platform == nullptr) || !Platform->MAlwaysRootDevice) { // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + Plugin->call( MDevice, PI_DEVICE_INFO_PARENT_DEVICE, sizeof(RT::PiDevice), &MRootDevice, nullptr); } @@ -67,7 +67,7 @@ device_impl::device_impl(pi_native_handle InteropDeviceHandle, // TODO catch an exception and put it to list of asynchronous exceptions // Interoperability Constructor already calls DeviceRetain in // piextDeviceFromNative. - Plugin.call(MDevice); + Plugin->call(MDevice); } // set MPlatform @@ -83,8 +83,9 @@ device_impl::device_impl(pi_native_handle InteropDeviceHandle, device_impl::~device_impl() { if (!MIsHostDevice) { // TODO catch an exception and put it to list of asynchronous exceptions - const detail::plugin &Plugin = getPlugin(); - RT::PiResult Err = Plugin.call_nocheck(MDevice); + const PluginPtr &Plugin = getPlugin(); + RT::PiResult Err = + Plugin->call_nocheck(MDevice); __SYCL_CHECK_OCL_CODE_NO_EXC(Err); } } @@ -103,7 +104,7 @@ cl_device_id device_impl::get() const { PI_ERROR_INVALID_DEVICE); } // TODO catch an exception and put it to list of asynchronous exceptions - getPlugin().call(MDevice); + getPlugin()->call(MDevice); return pi::cast(getNative()); } @@ -116,7 +117,8 @@ typename Param::return_type device_impl::get_info() const { if (is_host()) { return get_device_info_host(); } - return get_device_info(MPlatform->getOrMakeDeviceImpl(MDevice, MPlatform)); + return get_device_info( + MPlatform->getOrMakeDeviceImpl(MDevice, MPlatform)); } // Explicitly instantiate all device info traits #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ @@ -159,8 +161,8 @@ device_impl::create_sub_devices(const cl_device_partition_property *Properties, std::vector SubDevices(SubDevicesCount); pi_uint32 ReturnedSubDevices = 0; - const detail::plugin &Plugin = getPlugin(); - Plugin.call( + const PluginPtr &Plugin = getPlugin(); + Plugin->call( MDevice, Properties, SubDevicesCount, SubDevices.data(), &ReturnedSubDevices); if (ReturnedSubDevices != SubDevicesCount) { @@ -270,8 +272,8 @@ std::vector device_impl::create_sub_devices( (pi_device_partition_property)AffinityDomain, 0}; pi_uint32 SubDevicesCount = 0; - const detail::plugin &Plugin = getPlugin(); - Plugin.call( + const PluginPtr &Plugin = getPlugin(); + Plugin->call( MDevice, Properties, 0, nullptr, &SubDevicesCount); return create_sub_devices(Properties, SubDevicesCount); @@ -292,8 +294,8 @@ std::vector device_impl::create_sub_devices() const { PI_EXT_INTEL_DEVICE_PARTITION_BY_CSLICE, 0}; pi_uint32 SubDevicesCount = 0; - const detail::plugin &Plugin = getPlugin(); - Plugin.call( + const PluginPtr &Plugin = getPlugin(); + Plugin->call( MDevice, Properties, 0, nullptr, &SubDevicesCount); return create_sub_devices(Properties, SubDevicesCount); @@ -302,9 +304,9 @@ std::vector device_impl::create_sub_devices() const { pi_native_handle device_impl::getNative() const { auto Plugin = getPlugin(); if (getBackend() == backend::opencl) - Plugin.call(getHandleRef()); + Plugin->call(getHandleRef()); pi_native_handle Handle; - Plugin.call(getHandleRef(), &Handle); + Plugin->call(getHandleRef(), &Handle); return Handle; } @@ -372,51 +374,51 @@ bool device_impl::has(aspect Aspect) const { case aspect::usm_system_allocations: return get_info(); case aspect::ext_intel_device_id: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_DEVICE_ID, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_pci_address: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_PCI_ADDRESS, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_gpu_eu_count: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_GPU_EU_COUNT, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_gpu_eu_simd_width: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_gpu_slices: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_GPU_SLICES, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_gpu_subslices_per_slice: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_GPU_SUBSLICES_PER_SLICE, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_gpu_eu_count_per_subslice: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_gpu_hw_threads_per_eu: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_GPU_HW_THREADS_PER_EU, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_free_memory: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_EXT_INTEL_DEVICE_INFO_FREE_MEMORY, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_memory_clock_rate: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_EXT_INTEL_DEVICE_INFO_MEMORY_CLOCK_RATE, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_memory_bus_width: - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_EXT_INTEL_DEVICE_INFO_MEMORY_BUS_WIDTH, 0, nullptr, &return_size) == PI_SUCCESS; case aspect::ext_intel_device_info_uuid: { - auto Result = getPlugin().call_nocheck( + auto Result = getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_UUID, 0, nullptr, &return_size); if (Result != PI_SUCCESS) { return false; @@ -425,7 +427,7 @@ bool device_impl::has(aspect Aspect) const { assert(return_size <= 16); unsigned char UUID[16]; - return getPlugin().call_nocheck( + return getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_UUID, 16 * sizeof(unsigned char), UUID, nullptr) == PI_SUCCESS; } @@ -439,7 +441,7 @@ bool device_impl::has(aspect Aspect) const { case aspect::ext_oneapi_cuda_async_barrier: { int async_barrier_supported; bool call_successful = - getPlugin().call_nocheck( + getPlugin()->call_nocheck( MDevice, PI_EXT_ONEAPI_DEVICE_INFO_CUDA_ASYNC_BARRIER, sizeof(int), &async_barrier_supported, nullptr) == PI_SUCCESS; return call_successful && async_barrier_supported; @@ -447,7 +449,7 @@ bool device_impl::has(aspect Aspect) const { case aspect::ext_intel_legacy_image: { pi_bool legacy_image_support = PI_FALSE; bool call_successful = - getPlugin().call_nocheck( + getPlugin()->call_nocheck( MDevice, PI_DEVICE_INFO_IMAGE_SUPPORT, sizeof(pi_bool), &legacy_image_support, nullptr) == PI_SUCCESS; return call_successful && legacy_image_support; @@ -501,21 +503,21 @@ uint64_t device_impl::getCurrentDeviceTime() { uint64_t Diff = HostTime - MDeviceHostBaseTime.second; if (Diff > TimeTillRefresh || Diff <= 0) { - auto Plugin = getPlugin(); + const auto &Plugin = getPlugin(); auto Result = - Plugin.call_nocheck( + Plugin->call_nocheck( MDevice, &MDeviceHostBaseTime.first, &MDeviceHostBaseTime.second); if (Result == PI_ERROR_INVALID_OPERATION) { char *p = nullptr; - Plugin.call_nocheck(&p); + Plugin->call_nocheck(&p); std::string errorMsg(p ? p : ""); throw sycl::feature_not_supported( "Device and/or backend does not support querying timestamp: " + errorMsg, Result); } else { - Plugin.checkPiResult(Result); + Plugin->checkPiResult(Result); } // Until next sync we will compute device time based on the host time // returned in HostTime, so make this our base host time. diff --git a/sycl/source/detail/device_impl.hpp b/sycl/source/detail/device_impl.hpp index 6f99d78296b5..ca889f32be90 100644 --- a/sycl/source/detail/device_impl.hpp +++ b/sycl/source/detail/device_impl.hpp @@ -38,7 +38,7 @@ class device_impl { device_impl(); /// Constructs a SYCL device instance using the provided raw device handle. - explicit device_impl(pi_native_handle, const plugin &Plugin); + explicit device_impl(pi_native_handle, const PluginPtr &Plugin); /// Constructs a SYCL device instance using the provided /// PI device instance. @@ -46,7 +46,7 @@ class device_impl { /// Constructs a SYCL device instance using the provided /// PI device instance. - explicit device_impl(RT::PiDevice Device, const plugin &Plugin); + explicit device_impl(RT::PiDevice Device, const PluginPtr &Plugin); ~device_impl(); @@ -122,7 +122,7 @@ class device_impl { platform get_platform() const; /// \return the associated plugin with this device. - const plugin &getPlugin() const { return MPlatform->getPlugin(); } + const PluginPtr &getPlugin() const { return MPlatform->getPlugin(); } /// Check SYCL extension support by device /// @@ -248,7 +248,7 @@ class device_impl { private: explicit device_impl(pi_native_handle InteropDevice, RT::PiDevice Device, - PlatformImplPtr Platform, const plugin &Plugin); + PlatformImplPtr Platform, const PluginPtr &Plugin); RT::PiDevice MDevice = 0; RT::PiDeviceType MType; RT::PiDevice MRootDevice = nullptr; diff --git a/sycl/source/detail/device_info.hpp b/sycl/source/detail/device_info.hpp index 52da2328f29a..9ef9744bddbe 100644 --- a/sycl/source/detail/device_info.hpp +++ b/sycl/source/detail/device_info.hpp @@ -136,7 +136,7 @@ template <> struct check_fp_support { template struct get_device_info_impl { static ReturnT get(const DeviceImplPtr &Dev) { typename sycl_to_pi::type result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); return ReturnT(result); @@ -147,7 +147,7 @@ template struct get_device_info_impl { template struct get_device_info_impl { static platform get(const DeviceImplPtr &Dev) { typename sycl_to_pi::type result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); // TODO: Change PiDevice to device_impl. @@ -163,13 +163,13 @@ template struct get_device_info_impl { inline std::string device_impl::get_device_info_string(RT::PiDeviceInfo InfoCode) const { size_t resultSize = 0; - getPlugin().call(getHandleRef(), InfoCode, 0, - nullptr, &resultSize); + getPlugin()->call(getHandleRef(), InfoCode, 0, + nullptr, &resultSize); if (resultSize == 0) { return std::string(); } std::unique_ptr result(new char[resultSize]); - getPlugin().call( + getPlugin()->call( getHandleRef(), InfoCode, resultSize, result.get(), nullptr); return std::string(result.get()); @@ -199,7 +199,7 @@ struct get_device_info_impl, Param> { return {}; } cl_device_fp_config result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); return read_fp_bitfield(result); @@ -220,7 +220,7 @@ struct get_device_info_impl, info::device::single_fp_config> { static std::vector get(const DeviceImplPtr &Dev) { pi_device_fp_config result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); return read_fp_bitfield(result); @@ -229,7 +229,7 @@ struct get_device_info_impl, inline bool checkNativeQueueProfiling(const DeviceImplPtr &Dev) { pi_queue_properties Properties; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(Properties), &Properties, nullptr); return Properties & PI_QUEUE_FLAG_PROFILING_ENABLE; @@ -243,11 +243,11 @@ template <> struct get_device_info_impl { return false; RT::PiResult Result = Dev->getPlugin() - .call_nocheck( + ->call_nocheck( Dev->getHandleRef(), nullptr, nullptr); if (Result == PI_ERROR_INVALID_OPERATION) return false; - Dev->getPlugin().checkPiResult(Result); + Dev->getPlugin()->checkPiResult(Result); return true; } }; @@ -258,7 +258,7 @@ struct get_device_info_impl, info::device::atomic_memory_order_capabilities> { static std::vector get(const DeviceImplPtr &Dev) { pi_memory_order_capabilities result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_memory_order_capabilities), &result, nullptr); @@ -272,7 +272,7 @@ struct get_device_info_impl, info::device::atomic_fence_order_capabilities> { static std::vector get(const DeviceImplPtr &Dev) { pi_memory_order_capabilities result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_memory_order_capabilities), &result, nullptr); @@ -286,7 +286,7 @@ struct get_device_info_impl, info::device::atomic_memory_scope_capabilities> { static std::vector get(const DeviceImplPtr &Dev) { pi_memory_scope_capabilities result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_memory_scope_capabilities), &result, nullptr); @@ -300,7 +300,7 @@ struct get_device_info_impl, info::device::atomic_fence_scope_capabilities> { static std::vector get(const DeviceImplPtr &Dev) { pi_memory_scope_capabilities result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_memory_scope_capabilities), &result, nullptr); @@ -316,7 +316,7 @@ struct get_device_info_implgetPlugin().call_nocheck( + Dev->getPlugin()->call_nocheck( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); @@ -333,7 +333,7 @@ struct get_device_info_impl, info::device::execution_capabilities> { static std::vector get(const DeviceImplPtr &Dev) { pi_device_exec_capabilities result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); @@ -402,8 +402,8 @@ struct get_device_info_impl, const auto &Plugin = Dev->getPlugin(); size_t resultSize; - Plugin.call(Dev->getHandleRef(), info_partition, - 0, nullptr, &resultSize); + Plugin->call( + Dev->getHandleRef(), info_partition, 0, nullptr, &resultSize); size_t arrayLength = resultSize / sizeof(cl_device_partition_property); if (arrayLength == 0) { @@ -411,9 +411,9 @@ struct get_device_info_impl, } std::unique_ptr arrayResult( new cl_device_partition_property[arrayLength]); - Plugin.call(Dev->getHandleRef(), info_partition, - resultSize, arrayResult.get(), - nullptr); + Plugin->call(Dev->getHandleRef(), + info_partition, resultSize, + arrayResult.get(), nullptr); std::vector result; for (size_t i = 0; i < arrayLength; ++i) { @@ -435,7 +435,7 @@ struct get_device_info_impl, static std::vector get(const DeviceImplPtr &Dev) { pi_device_affinity_domain result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); @@ -450,7 +450,7 @@ struct get_device_info_impl { static info::partition_affinity_domain get(const DeviceImplPtr &Dev) { size_t resultSize; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, 0, nullptr, &resultSize); @@ -458,7 +458,7 @@ struct get_device_info_implgetPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); @@ -480,7 +480,7 @@ struct get_device_info_impl { static info::partition_property get(const DeviceImplPtr &Dev) { size_t resultSize; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PI_DEVICE_INFO_PARTITION_TYPE, 0, nullptr, &resultSize); if (!resultSize) @@ -490,7 +490,7 @@ struct get_device_info_impl arrayResult( new cl_device_partition_property[arrayLength]); - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PI_DEVICE_INFO_PARTITION_TYPE, resultSize, arrayResult.get(), nullptr); if (!arrayResult[0]) @@ -504,12 +504,12 @@ struct get_device_info_impl, info::device::sub_group_sizes> { static std::vector get(const DeviceImplPtr &Dev) { size_t resultSize = 0; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, 0, nullptr, &resultSize); std::vector result(resultSize / sizeof(size_t)); - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, resultSize, result.data(), nullptr); return result; @@ -556,7 +556,7 @@ struct get_device_info_impl, info::device::max_work_item_sizes> { static id get(const DeviceImplPtr &Dev) { size_t result[3]; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode>::value, sizeof(result), &result, nullptr); @@ -579,7 +579,7 @@ struct get_device_info_impl< size_t Limit = get_device_info_impl::get(Dev); - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode< ext::oneapi::experimental::info::device::max_work_groups<3>>::value, @@ -596,7 +596,7 @@ struct get_device_info_impl< size_t Limit = get_device_info_impl::get(Dev); - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode< ext::oneapi::experimental::info::device::max_work_groups<3>>::value, @@ -613,7 +613,7 @@ struct get_device_info_impl< size_t Limit = get_device_info_impl::get(Dev); - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode< ext::oneapi::experimental::info::device::max_work_groups<3>>::value, @@ -675,7 +675,7 @@ struct get_device_info_impl, template <> struct get_device_info_impl { static device get(const DeviceImplPtr &Dev) { typename sycl_to_pi::type result; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, sizeof(result), &result, nullptr); if (result == nullptr) @@ -704,7 +704,7 @@ template <> struct get_device_info_impl { static bool get(const DeviceImplPtr &Dev) { pi_usm_capabilities caps; - pi_result Err = Dev->getPlugin().call_nocheck( + pi_result Err = Dev->getPlugin()->call_nocheck( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_usm_capabilities), &caps, nullptr); @@ -718,7 +718,7 @@ template <> struct get_device_info_impl { static bool get(const DeviceImplPtr &Dev) { pi_usm_capabilities caps; - pi_result Err = Dev->getPlugin().call_nocheck( + pi_result Err = Dev->getPlugin()->call_nocheck( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_usm_capabilities), &caps, nullptr); @@ -732,7 +732,7 @@ template <> struct get_device_info_impl { static bool get(const DeviceImplPtr &Dev) { pi_usm_capabilities caps; - pi_result Err = Dev->getPlugin().call_nocheck( + pi_result Err = Dev->getPlugin()->call_nocheck( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_usm_capabilities), &caps, nullptr); @@ -746,7 +746,7 @@ struct get_device_info_impl { static bool get(const DeviceImplPtr &Dev) { pi_usm_capabilities caps; - pi_result Err = Dev->getPlugin().call_nocheck( + pi_result Err = Dev->getPlugin()->call_nocheck( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_usm_capabilities), &caps, nullptr); @@ -762,7 +762,7 @@ template <> struct get_device_info_impl { static bool get(const DeviceImplPtr &Dev) { pi_usm_capabilities caps; - pi_result Err = Dev->getPlugin().call_nocheck( + pi_result Err = Dev->getPlugin()->call_nocheck( Dev->getHandleRef(), PiInfoCode::value, sizeof(pi_usm_capabilities), &caps, nullptr); @@ -795,7 +795,7 @@ struct get_device_info_impl< ext::codeplay::experimental::info::device::max_registers_per_work_group> { static uint32_t get(const DeviceImplPtr &Dev) { uint32_t maxRegsPerWG; - Dev->getPlugin().call( + Dev->getPlugin()->call( Dev->getHandleRef(), PiInfoCode::value, diff --git a/sycl/source/detail/error_handling/error_handling.cpp b/sycl/source/detail/error_handling/error_handling.cpp index 3f6084d00245..dbdb28078fa6 100644 --- a/sycl/source/detail/error_handling/error_handling.cpp +++ b/sycl/source/detail/error_handling/error_handling.cpp @@ -24,13 +24,13 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, const NDRDescT &NDRDesc) { const bool HasLocalSize = (NDRDesc.LocalSize[0] != 0); - const plugin &Plugin = DeviceImpl.getPlugin(); + const PluginPtr &Plugin = DeviceImpl.getPlugin(); RT::PiDevice Device = DeviceImpl.getHandleRef(); sycl::platform Platform = DeviceImpl.get_platform(); if (HasLocalSize) { size_t MaxThreadsPerBlock[3] = {}; - Plugin.call( + Plugin->call( Device, PI_DEVICE_INFO_MAX_WORK_ITEM_SIZES, sizeof(MaxThreadsPerBlock), MaxThreadsPerBlock, nullptr); @@ -49,8 +49,8 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, // Some of the error handling below is special for particular OpenCL // versions. If this is an OpenCL backend, get the version. - bool IsOpenCL = false; // Backend is any OpenCL version - bool IsOpenCLV1x = false; // Backend is OpenCL 1.x + bool IsOpenCL = false; // Backend is any OpenCL version + bool IsOpenCLV1x = false; // Backend is OpenCL 1.x bool IsOpenCLVGE20 = false; // Backend is Greater or Equal to OpenCL 2.0 bool IsLevelZero = false; // Backend is any OneAPI Level 0 version bool IsCuda = false; // Backend is CUDA @@ -69,14 +69,14 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, } size_t CompileWGSize[3] = {0}; - Plugin.call( + Plugin->call( Kernel, Device, PI_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE, sizeof(size_t) * 3, CompileWGSize, nullptr); size_t MaxWGSize = 0; - Plugin.call(Device, - PI_DEVICE_INFO_MAX_WORK_GROUP_SIZE, - sizeof(size_t), &MaxWGSize, nullptr); + Plugin->call(Device, + PI_DEVICE_INFO_MAX_WORK_GROUP_SIZE, + sizeof(size_t), &MaxWGSize, nullptr); if (CompileWGSize[0] != 0) { if (CompileWGSize[0] > MaxWGSize || CompileWGSize[1] > MaxWGSize || CompileWGSize[2] > MaxWGSize) @@ -133,7 +133,7 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, // than the value specified by PI_KERNEL_GROUP_INFO_WORK_GROUP_SIZE in // table 5.21. size_t KernelWGSize = 0; - Plugin.call( + Plugin->call( Kernel, Device, PI_KERNEL_GROUP_INFO_WORK_GROUP_SIZE, sizeof(size_t), &KernelWGSize, nullptr); const size_t TotalNumberOfWIs = @@ -188,15 +188,15 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, // given by local_work_size pi_program Program = nullptr; - Plugin.call( + Plugin->call( Kernel, PI_KERNEL_INFO_PROGRAM, sizeof(pi_program), &Program, nullptr); size_t OptsSize = 0; - Plugin.call( + Plugin->call( Program, Device, PI_PROGRAM_BUILD_INFO_OPTIONS, 0, nullptr, &OptsSize); std::string Opts(OptsSize, '\0'); - Plugin.call( + Plugin->call( Program, Device, PI_PROGRAM_BUILD_INFO_OPTIONS, OptsSize, &Opts.front(), nullptr); const bool HasStd20 = Opts.find("-cl-std=CL2.0") != std::string::npos; @@ -253,7 +253,7 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, NDRDesc.LocalSize[0] * NDRDesc.LocalSize[1] * NDRDesc.LocalSize[2]; uint32_t NumRegisters = 0; - Plugin.call( + Plugin->call( Kernel, Device, PI_KERNEL_GROUP_INFO_NUM_REGS, sizeof(NumRegisters), &NumRegisters, nullptr); @@ -301,12 +301,12 @@ void handleInvalidWorkGroupSize(const device_impl &DeviceImpl, pi_kernel Kernel, void handleInvalidWorkItemSize(const device_impl &DeviceImpl, const NDRDescT &NDRDesc) { - const plugin &Plugin = DeviceImpl.getPlugin(); + const PluginPtr &Plugin = DeviceImpl.getPlugin(); RT::PiDevice Device = DeviceImpl.getHandleRef(); size_t MaxWISize[] = {0, 0, 0}; - Plugin.call( + Plugin->call( Device, PI_DEVICE_INFO_MAX_WORK_ITEM_SIZES, sizeof(MaxWISize), &MaxWISize, nullptr); for (unsigned I = 0; I < NDRDesc.Dims; I++) { @@ -321,11 +321,11 @@ void handleInvalidWorkItemSize(const device_impl &DeviceImpl, void handleInvalidValue(const device_impl &DeviceImpl, const NDRDescT &NDRDesc) { - const plugin &Plugin = DeviceImpl.getPlugin(); + const PluginPtr &Plugin = DeviceImpl.getPlugin(); RT::PiDevice Device = DeviceImpl.getHandleRef(); size_t MaxNWGs[] = {0, 0, 0}; - Plugin.call( + Plugin->call( Device, PI_EXT_ONEAPI_DEVICE_INFO_MAX_WORK_GROUPS_3D, sizeof(MaxNWGs), &MaxNWGs, nullptr); for (unsigned int I = 0; I < NDRDesc.Dims; I++) { @@ -400,7 +400,7 @@ void handleErrorOrWarning(pi_result Error, const device_impl &DeviceImpl, // depending on whether PI_ERROR_PLUGIN_SPECIFIC_ERROR contains an error or // a warning. It also ensures that the contents of the error message buffer // (used only by PI_ERROR_PLUGIN_SPECIFIC_ERROR) get handled correctly. - return DeviceImpl.getPlugin().checkPiResult(Error); + return DeviceImpl.getPlugin()->checkPiResult(Error); // TODO: Handle other error codes @@ -414,7 +414,7 @@ void handleErrorOrWarning(pi_result Error, const device_impl &DeviceImpl, namespace detail::kernel_get_group_info { void handleErrorOrWarning(pi_result Error, pi_kernel_group_info Descriptor, - const plugin &Plugin) { + const PluginPtr &Plugin) { assert(Error != PI_SUCCESS && "Success is expected to be handled on caller side"); switch (Error) { @@ -428,7 +428,7 @@ void handleErrorOrWarning(pi_result Error, pi_kernel_group_info Descriptor, break; // TODO: Handle other error codes default: - Plugin.checkPiResult(Error); + Plugin->checkPiResult(Error); break; } } diff --git a/sycl/source/detail/error_handling/error_handling.hpp b/sycl/source/detail/error_handling/error_handling.hpp index c44937b5e804..f634a1a5e40d 100644 --- a/sycl/source/detail/error_handling/error_handling.hpp +++ b/sycl/source/detail/error_handling/error_handling.hpp @@ -31,7 +31,7 @@ void handleErrorOrWarning(pi_result, const device_impl &, pi_kernel, namespace kernel_get_group_info { /// Analyzes error code of piKernelGetGroupInfo. -void handleErrorOrWarning(pi_result, pi_kernel_group_info, const plugin &); +void handleErrorOrWarning(pi_result, pi_kernel_group_info, const PluginPtr &); } // namespace kernel_get_group_info } // namespace detail diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index f2960fae9a18..8e6da928ac4a 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -55,13 +55,13 @@ bool event_impl::is_host() { event_impl::~event_impl() { if (MEvent) - getPlugin().call(MEvent); + getPlugin()->call(MEvent); } void event_impl::waitInternal() { if (!MHostEvent && MEvent) { // Wait for the native event - getPlugin().call(1, &MEvent); + getPlugin()->call(1, &MEvent); } else if (MState == HES_Discarded) { // Waiting for the discarded event is invalid throw sycl::exception( @@ -108,7 +108,7 @@ const ContextImplPtr &event_impl::getContextImpl() { return MContext; } -const plugin &event_impl::getPlugin() { +const PluginPtr &event_impl::getPlugin() { ensureContextInitialized(); return MContext->getPlugin(); } @@ -134,9 +134,9 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext) } RT::PiContext TempContext; - getPlugin().call(MEvent, PI_EVENT_INFO_CONTEXT, - sizeof(RT::PiContext), - &TempContext, nullptr); + getPlugin()->call(MEvent, PI_EVENT_INFO_CONTEXT, + sizeof(RT::PiContext), + &TempContext, nullptr); if (MContext->getHandleRef() != TempContext) { throw sycl::invalid_parameter_error( "The syclContext must match the OpenCL context associated with the " @@ -353,12 +353,12 @@ pi_native_handle event_impl::getNative() { if (!MIsInitialized) { MIsInitialized = true; auto TempContext = MContext.get()->getHandleRef(); - Plugin.call(TempContext, &MEvent); + Plugin->call(TempContext, &MEvent); } if (MContext->getBackend() == backend::opencl) - Plugin.call(getHandleRef()); + Plugin->call(getHandleRef()); pi_native_handle Handle; - Plugin.call(getHandleRef(), &Handle); + Plugin->call(getHandleRef(), &Handle); return Handle; } @@ -398,11 +398,11 @@ void event_impl::flushIfNeeded(const QueueImplPtr &UserQueue) { // Check if the task for this event has already been submitted. pi_event_status Status = PI_EVENT_QUEUED; - getPlugin().call( + getPlugin()->call( MEvent, PI_EVENT_INFO_COMMAND_EXECUTION_STATUS, sizeof(pi_int32), &Status, nullptr); if (Status == PI_EVENT_QUEUED) { - getPlugin().call(Queue->getHandleRef()); + getPlugin()->call(Queue->getHandleRef()); } MIsFlushed = true; } diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index 1e6f83697da6..bd9e47551a42 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -129,7 +129,7 @@ class event_impl { /// \return the Plugin associated with the context of this event. /// Should be called when this is not a Host Event. - const plugin &getPlugin(); + const PluginPtr &getPlugin(); /// Associate event with the context. /// diff --git a/sycl/source/detail/event_info.hpp b/sycl/source/detail/event_info.hpp index e4121b05e89b..6d6bfcdf0704 100644 --- a/sycl/source/detail/event_info.hpp +++ b/sycl/source/detail/event_info.hpp @@ -20,25 +20,25 @@ namespace detail { template typename Param::return_type get_event_profiling_info(RT::PiEvent Event, - const plugin &Plugin) { + const PluginPtr &Plugin) { static_assert(is_event_profiling_info_desc::value, "Unexpected event profiling info descriptor"); typename Param::return_type Result{0}; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + Plugin->call( Event, PiInfoCode::value, sizeof(Result), &Result, nullptr); return Result; } template typename Param::return_type get_event_info(RT::PiEvent Event, - const plugin &Plugin) { + const PluginPtr &Plugin) { static_assert(is_event_info_desc::value, "Unexpected event info descriptor"); typename Param::return_type Result{0}; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(Event, PiInfoCode::value, - sizeof(Result), &Result, nullptr); + Plugin->call(Event, PiInfoCode::value, + sizeof(Result), &Result, nullptr); return Result; } diff --git a/sycl/source/detail/global_handler.cpp b/sycl/source/detail/global_handler.cpp index 4ed6846967cb..3e27451fe516 100644 --- a/sycl/source/detail/global_handler.cpp +++ b/sycl/source/detail/global_handler.cpp @@ -198,7 +198,7 @@ std::mutex &GlobalHandler::getPlatformMapMutex() { std::mutex &GlobalHandler::getFilterMutex() { return getOrCreate(MFilterMutex); } -std::vector &GlobalHandler::getPlugins() { +std::vector &GlobalHandler::getPlugins() { enableOnCrashStackPrinting(); return getOrCreate(MPlugins); } @@ -258,13 +258,13 @@ void GlobalHandler::unloadPlugins() { // user application has loaded SYCL runtime, and never called any APIs, // there's no need to load and unload plugins. if (MPlugins.Inst) { - for (plugin &Plugin : getPlugins()) { + for (const PluginPtr &Plugin : getPlugins()) { // PluginParameter is reserved for future use that can control // some parameters in the plugin tear-down process. // Currently, it is not used. void *PluginParameter = nullptr; - Plugin.call(PluginParameter); - Plugin.unload(); + Plugin->call(PluginParameter); + Plugin->unload(); } } // Clear after unload to avoid uses after unload. diff --git a/sycl/source/detail/global_handler.hpp b/sycl/source/detail/global_handler.hpp index 67843a336ac5..e9c695934f07 100644 --- a/sycl/source/detail/global_handler.hpp +++ b/sycl/source/detail/global_handler.hpp @@ -30,6 +30,7 @@ class ThreadPool; using PlatformImplPtr = std::shared_ptr; using ContextImplPtr = std::shared_ptr; +using PluginPtr = std::shared_ptr; /// Wrapper class for global data structures with non-trivial destructors. /// @@ -66,7 +67,7 @@ class GlobalHandler { std::mutex &getPlatformToDefaultContextCacheMutex(); std::mutex &getPlatformMapMutex(); std::mutex &getFilterMutex(); - std::vector &getPlugins(); + std::vector &getPlugins(); device_filter_list &getDeviceFilterList(const std::string &InitValue); ods_target_list &getOneapiDeviceSelectorTargets(const std::string &InitValue); XPTIRegistry &getXPTIRegistry(); @@ -117,7 +118,7 @@ class GlobalHandler { InstWithLock MPlatformToDefaultContextCacheMutex; InstWithLock MPlatformMapMutex; InstWithLock MFilterMutex; - InstWithLock> MPlugins; + InstWithLock> MPlugins; InstWithLock MDeviceFilterList; InstWithLock MOneapiDeviceSelectorTargets; InstWithLock MXPTIRegistry; diff --git a/sycl/source/detail/image_impl.cpp b/sycl/source/detail/image_impl.cpp index 5be2ad656a8b..2ce1e3e04179 100644 --- a/sycl/source/detail/image_impl.cpp +++ b/sycl/source/detail/image_impl.cpp @@ -254,10 +254,10 @@ image_channel_type convertChannelType(RT::PiMemImageChannelType Type) { template static void getImageInfo(const ContextImplPtr Context, RT::PiMemImageInfo Info, T &Dest, RT::PiMem InteropMemObject) { - const detail::plugin &Plugin = Context->getPlugin(); + const PluginPtr &Plugin = Context->getPlugin(); RT::PiMem Mem = pi::cast(InteropMemObject); - Plugin.call(Mem, Info, sizeof(T), &Dest, - nullptr); + Plugin->call(Mem, Info, sizeof(T), &Dest, + nullptr); } image_impl::image_impl(cl_mem MemObject, const context &SyclContext, @@ -269,9 +269,9 @@ image_impl::image_impl(cl_mem MemObject, const context &SyclContext, MDimensions(Dimensions), MRange({0, 0, 0}) { RT::PiMem Mem = pi::cast(BaseT::MInteropMemObject); const ContextImplPtr Context = getSyclObjImpl(SyclContext); - const detail::plugin &Plugin = Context->getPlugin(); - Plugin.call(Mem, PI_MEM_SIZE, sizeof(size_t), - &(BaseT::MSizeInBytes), nullptr); + const PluginPtr &Plugin = Context->getPlugin(); + Plugin->call(Mem, PI_MEM_SIZE, sizeof(size_t), + &(BaseT::MSizeInBytes), nullptr); RT::PiMemImageFormat Format; getImageInfo(Context, PI_IMAGE_INFO_FORMAT, Format, Mem); diff --git a/sycl/source/detail/kernel_impl.cpp b/sycl/source/detail/kernel_impl.cpp index 8784cd967b3c..c7a808f9cc0a 100644 --- a/sycl/source/detail/kernel_impl.cpp +++ b/sycl/source/detail/kernel_impl.cpp @@ -26,7 +26,7 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context, // Enable USM indirect access for interoperability kernels. // Some PI Plugins (like OpenCL) require this call to enable USM // For others, PI will turn this into a NOP. - getPlugin().call( + getPlugin()->call( MKernel, PI_USM_INDIRECT_ACCESS, sizeof(pi_bool), &PI_TRUE); // This constructor is only called in the interoperability kernel constructor. @@ -45,7 +45,7 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl, RT::PiContext Context = nullptr; // Using the plugin from the passed ContextImpl - getPlugin().call( + getPlugin()->call( MKernel, PI_KERNEL_INFO_CONTEXT, sizeof(Context), &Context, nullptr); if (ContextImpl->getHandleRef() != Context) throw sycl::invalid_parameter_error( @@ -66,7 +66,7 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl, // kernel_impl shared ownership of kernel handle if (!is_host()) { - getPlugin().call(MKernel); + getPlugin()->call(MKernel); } MIsInterop = MKernelBundleImpl->isInterop(); @@ -78,7 +78,7 @@ kernel_impl::kernel_impl(ContextImplPtr Context, ProgramImplPtr ProgramImpl) kernel_impl::~kernel_impl() { // TODO catch an exception and put it to list of asynchronous exceptions if (!is_host()) { - getPlugin().call(MKernel); + getPlugin()->call(MKernel); } } diff --git a/sycl/source/detail/kernel_impl.hpp b/sycl/source/detail/kernel_impl.hpp index e6590b9943b8..b8a6c70697a3 100644 --- a/sycl/source/detail/kernel_impl.hpp +++ b/sycl/source/detail/kernel_impl.hpp @@ -105,7 +105,7 @@ class kernel_impl { "This instance of kernel doesn't support OpenCL interoperability.", PI_ERROR_INVALID_KERNEL); } - getPlugin().call(MKernel); + getPlugin()->call(MKernel); return pi::cast(MKernel); } @@ -114,7 +114,7 @@ class kernel_impl { /// \return true if this SYCL kernel is a host kernel. bool is_host() const { return MContext->is_host(); } - const plugin &getPlugin() const { return MContext->getPlugin(); } + const PluginPtr &getPlugin() const { return MContext->getPlugin(); } /// Query information from the kernel object using the info::kernel_info /// descriptor. @@ -160,13 +160,13 @@ class kernel_impl { const DeviceImageImplPtr &getDeviceImage() const { return MDeviceImageImpl; } pi_native_handle getNative() const { - const plugin &Plugin = MContext->getPlugin(); + const PluginPtr &Plugin = MContext->getPlugin(); if (MContext->getBackend() == backend::opencl) - Plugin.call(MKernel); + Plugin->call(MKernel); pi_native_handle NativeKernel = 0; - Plugin.call(MKernel, &NativeKernel); + Plugin->call(MKernel, &NativeKernel); return NativeKernel; } diff --git a/sycl/source/detail/kernel_info.hpp b/sycl/source/detail/kernel_info.hpp index 66cb95da6174..ef5f8e94a7aa 100644 --- a/sycl/source/detail/kernel_info.hpp +++ b/sycl/source/detail/kernel_info.hpp @@ -26,33 +26,33 @@ template typename std::enable_if< std::is_same::value, std::string>::type -get_kernel_info(RT::PiKernel Kernel, const plugin &Plugin) { +get_kernel_info(RT::PiKernel Kernel, const PluginPtr &Plugin) { static_assert(detail::is_kernel_info_desc::value, "Invalid kernel information descriptor"); size_t ResultSize = 0; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(Kernel, PiInfoCode::value, 0, - nullptr, &ResultSize); + Plugin->call(Kernel, PiInfoCode::value, 0, + nullptr, &ResultSize); if (ResultSize == 0) { return ""; } std::vector Result(ResultSize); // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(Kernel, PiInfoCode::value, - ResultSize, Result.data(), nullptr); + Plugin->call(Kernel, PiInfoCode::value, + ResultSize, Result.data(), nullptr); return std::string(Result.data()); } template typename std::enable_if< std::is_same::value, uint32_t>::type -get_kernel_info(RT::PiKernel Kernel, const plugin &Plugin) { +get_kernel_info(RT::PiKernel Kernel, const PluginPtr &Plugin) { uint32_t Result = 0; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(Kernel, PiInfoCode::value, - sizeof(uint32_t), &Result, nullptr); + Plugin->call(Kernel, PiInfoCode::value, + sizeof(uint32_t), &Result, nullptr); return Result; } @@ -60,9 +60,9 @@ get_kernel_info(RT::PiKernel Kernel, const plugin &Plugin) { template typename std::enable_if::value>::type get_kernel_device_specific_info_helper(RT::PiKernel Kernel, RT::PiDevice Device, - const plugin &Plugin, void *Result, + const PluginPtr &Plugin, void *Result, size_t Size) { - Plugin.call( + Plugin->call( Kernel, Device, PiInfoCode::value, 0, nullptr, Size, Result, nullptr); } @@ -70,9 +70,9 @@ get_kernel_device_specific_info_helper(RT::PiKernel Kernel, RT::PiDevice Device, template typename std::enable_if::value>::type get_kernel_device_specific_info_helper(RT::PiKernel Kernel, RT::PiDevice Device, - const plugin &Plugin, void *Result, + const PluginPtr &Plugin, void *Result, size_t Size) { - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( Kernel, Device, PiInfoCode::value, Size, Result, nullptr); if (Error != PI_SUCCESS) kernel_get_group_info::handleErrorOrWarning(Error, PiInfoCode::value, @@ -84,7 +84,7 @@ typename std::enable_if< !std::is_same>::value, typename Param::return_type>::type get_kernel_device_specific_info(RT::PiKernel Kernel, RT::PiDevice Device, - const plugin &Plugin) { + const PluginPtr &Plugin) { static_assert(is_kernel_device_specific_info_desc::value, "Unexpected kernel_device_specific information descriptor"); typename Param::return_type Result = {}; @@ -99,7 +99,7 @@ typename std::enable_if< std::is_same>::value, sycl::range<3>>::type get_kernel_device_specific_info(RT::PiKernel Kernel, RT::PiDevice Device, - const plugin &Plugin) { + const PluginPtr &Plugin) { static_assert(is_kernel_device_specific_info_desc::value, "Unexpected kernel_device_specific information descriptor"); size_t Result[3] = {0, 0, 0}; @@ -116,7 +116,7 @@ template uint32_t get_kernel_device_specific_info_with_input(RT::PiKernel Kernel, RT::PiDevice Device, sycl::range<3> In, - const plugin &Plugin) { + const PluginPtr &Plugin) { static_assert(is_kernel_device_specific_info_desc::value, "Unexpected kernel_device_specific information descriptor"); static_assert(std::is_same::value, @@ -127,7 +127,7 @@ uint32_t get_kernel_device_specific_info_with_input(RT::PiKernel Kernel, size_t Input[3] = {In[0], In[1], In[2]}; uint32_t Result = 0; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + Plugin->call( Kernel, Device, PiInfoCode::value, sizeof(size_t) * 3, Input, sizeof(uint32_t), &Result, nullptr); diff --git a/sycl/source/detail/kernel_program_cache.cpp b/sycl/source/detail/kernel_program_cache.cpp index f17e1f0ddfdd..6867f268e9b4 100644 --- a/sycl/source/detail/kernel_program_cache.cpp +++ b/sycl/source/detail/kernel_program_cache.cpp @@ -29,15 +29,15 @@ KernelProgramCache::~KernelProgramCache() { KernelArgMaskPairT *KernelArgMaskPair = KernelWithState.Ptr.load(); if (KernelArgMaskPair) { - const detail::plugin &Plugin = MParentContext->getPlugin(); - Plugin.call(KernelArgMaskPair->first); + const PluginPtr &Plugin = MParentContext->getPlugin(); + Plugin->call(KernelArgMaskPair->first); } } MKernelsPerProgramCache.erase(KernIt); } - const detail::plugin &Plugin = MParentContext->getPlugin(); - Plugin.call(*ToBeDeleted); + const PluginPtr &Plugin = MParentContext->getPlugin(); + Plugin->call(*ToBeDeleted); } } } // namespace detail diff --git a/sycl/source/detail/mem_alloc_helper.hpp b/sycl/source/detail/mem_alloc_helper.hpp index c2c6dd0a3d5a..64bb61942326 100644 --- a/sycl/source/detail/mem_alloc_helper.hpp +++ b/sycl/source/detail/mem_alloc_helper.hpp @@ -13,19 +13,20 @@ namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { namespace detail { -void memBufferCreateHelper(const plugin &Plugin, pi_context Ctx, +void memBufferCreateHelper(const PluginPtr &Plugin, pi_context Ctx, pi_mem_flags Flags, size_t Size, void *HostPtr, pi_mem *RetMem, const pi_mem_properties *Props = nullptr); -void memReleaseHelper(const plugin &Plugin, pi_mem Mem); -void memBufferMapHelper(const plugin &Plugin, pi_queue command_queue, +void memReleaseHelper(const PluginPtr &Plugin, pi_mem Mem); +void memBufferMapHelper(const PluginPtr &Plugin, pi_queue command_queue, pi_mem buffer, pi_bool blocking_map, pi_map_flags map_flags, size_t offset, size_t size, pi_uint32 num_events_in_wait_list, const pi_event *event_wait_list, pi_event *event, void **ret_map); -void memUnmapHelper(const plugin &Plugin, pi_queue command_queue, pi_mem memobj, - void *mapped_ptr, pi_uint32 num_events_in_wait_list, +void memUnmapHelper(const PluginPtr &Plugin, pi_queue command_queue, + pi_mem memobj, void *mapped_ptr, + pi_uint32 num_events_in_wait_list, const pi_event *event_wait_list, pi_event *event); } // namespace detail } // __SYCL_INLINE_VER_NAMESPACE(_V1) diff --git a/sycl/source/detail/memory_manager.cpp b/sycl/source/detail/memory_manager.cpp index 54efd09e04e6..6abb47f8b749 100644 --- a/sycl/source/detail/memory_manager.cpp +++ b/sycl/source/detail/memory_manager.cpp @@ -116,17 +116,17 @@ static void waitForEvents(const std::vector &Events) { // Assuming all events will be on the same device or // devices associated with the same Backend. if (!Events.empty()) { - const detail::plugin &Plugin = Events[0]->getPlugin(); + const PluginPtr &Plugin = Events[0]->getPlugin(); std::vector PiEvents(Events.size()); std::transform(Events.begin(), Events.end(), PiEvents.begin(), [](const EventImplPtr &EventImpl) { return EventImpl->getHandleRef(); }); - Plugin.call(PiEvents.size(), &PiEvents[0]); + Plugin->call(PiEvents.size(), &PiEvents[0]); } } -void memBufferCreateHelper(const plugin &Plugin, pi_context Ctx, +void memBufferCreateHelper(const PluginPtr &Plugin, pi_context Ctx, pi_mem_flags Flags, size_t Size, void *HostPtr, pi_mem *RetMem, const pi_mem_properties *Props) { #ifdef XPTI_ENABLE_INSTRUMENTATION @@ -144,17 +144,17 @@ void memBufferCreateHelper(const plugin &Plugin, pi_context Ctx, // Always use call_nocheck here, because call may throw an exception, // and this lambda will be called from destructor, which in combination // rewards us with UB. - Plugin.call_nocheck(*RetMem, &Ptr); + Plugin->call_nocheck(*RetMem, &Ptr); emitMemAllocEndTrace(MemObjID, (uintptr_t)(Ptr), Size, 0 /* guard zone */, CorrID); }}; #endif - Plugin.call(Ctx, Flags, Size, HostPtr, RetMem, - Props); + Plugin->call(Ctx, Flags, Size, HostPtr, + RetMem, Props); } } -void memReleaseHelper(const plugin &Plugin, pi_mem Mem) { +void memReleaseHelper(const PluginPtr &Plugin, pi_mem Mem) { // FIXME piMemRelease does not guarante memory release. It is only true if // reference counter is 1. However, SYCL runtime currently only calls // piMemRetain only for OpenCL interop @@ -166,7 +166,7 @@ void memReleaseHelper(const plugin &Plugin, pi_mem Mem) { // Do not make unnecessary PI calls without instrumentation enabled if (xptiTraceEnabled()) { pi_native_handle PtrHandle = 0; - Plugin.call(Mem, &PtrHandle); + Plugin->call(Mem, &PtrHandle); Ptr = (uintptr_t)(PtrHandle); } #endif @@ -177,11 +177,11 @@ void memReleaseHelper(const plugin &Plugin, pi_mem Mem) { xpti::utils::finally _{ [&] { emitMemReleaseEndTrace(MemObjID, Ptr, CorrID); }}; #endif - Plugin.call(Mem); + Plugin->call(Mem); } } -void memBufferMapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Buffer, +void memBufferMapHelper(const PluginPtr &Plugin, pi_queue Queue, pi_mem Buffer, pi_bool Blocking, pi_map_flags Flags, size_t Offset, size_t Size, pi_uint32 NumEvents, const pi_event *WaitList, pi_event *Event, @@ -199,13 +199,13 @@ void memBufferMapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Buffer, 0 /* guard zone */, CorrID); }}; #endif - Plugin.call( + Plugin->call( Queue, Buffer, Blocking, Flags, Offset, Size, NumEvents, WaitList, Event, RetMap); } } -void memUnmapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Mem, +void memUnmapHelper(const PluginPtr &Plugin, pi_queue Queue, pi_mem Mem, void *MappedPtr, pi_uint32 NumEvents, const pi_event *WaitList, pi_event *Event) { #ifdef XPTI_ENABLE_INSTRUMENTATION @@ -224,12 +224,12 @@ void memUnmapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Mem, // Always use call_nocheck here, because call may throw an exception, // and this lambda will be called from destructor, which in combination // rewards us with UB. - Plugin.call_nocheck(1, Event); + Plugin->call_nocheck(1, Event); emitMemReleaseEndTrace(MemObjID, Ptr, CorrID); }}; #endif - Plugin.call(Queue, Mem, MappedPtr, NumEvents, - WaitList, Event); + Plugin->call(Queue, Mem, MappedPtr, NumEvents, + WaitList, Event); } } @@ -258,7 +258,7 @@ void MemoryManager::releaseMemObj(ContextImplPtr TargetContext, return; } - const detail::plugin &Plugin = TargetContext->getPlugin(); + const PluginPtr &Plugin = TargetContext->getPlugin(); memReleaseHelper(Plugin, pi::cast(MemAllocation)); } @@ -301,8 +301,8 @@ void *MemoryManager::allocateInteropMemObject( // Retain the event since it will be released during alloca command // destruction if (nullptr != OutEventToWait) { - const detail::plugin &Plugin = InteropEvent->getPlugin(); - Plugin.call(OutEventToWait); + const PluginPtr &Plugin = InteropEvent->getPlugin(); + Plugin->call(OutEventToWait); } return UserPtr; } @@ -326,10 +326,10 @@ void *MemoryManager::allocateImageObject(ContextImplPtr TargetContext, getMemObjCreationFlags(UserPtr, HostPtrReadOnly); RT::PiMem NewMem; - const detail::plugin &Plugin = TargetContext->getPlugin(); - Plugin.call(TargetContext->getHandleRef(), - CreationFlags, &Format, &Desc, - UserPtr, &NewMem); + const PluginPtr &Plugin = TargetContext->getPlugin(); + Plugin->call(TargetContext->getHandleRef(), + CreationFlags, &Format, &Desc, + UserPtr, &NewMem); return NewMem; } @@ -344,7 +344,7 @@ MemoryManager::allocateBufferObject(ContextImplPtr TargetContext, void *UserPtr, CreationFlags |= PI_MEM_FLAGS_HOST_PTR_ALLOC; RT::PiMem NewMem = nullptr; - const detail::plugin &Plugin = TargetContext->getPlugin(); + const PluginPtr &Plugin = TargetContext->getPlugin(); std::vector AllocProps; @@ -435,8 +435,8 @@ void *MemoryManager::allocateMemSubBuffer(ContextImplPtr TargetContext, RT::PiResult Error = PI_SUCCESS; pi_buffer_region_struct Region{Offset, SizeInBytes}; RT::PiMem NewMem; - const detail::plugin &Plugin = TargetContext->getPlugin(); - Error = Plugin.call_nocheck( + const PluginPtr &Plugin = TargetContext->getPlugin(); + Error = Plugin->call_nocheck( pi::cast(ParentMemObj), PI_MEM_FLAGS_ACCESS_RW, PI_BUFFER_CREATE_TYPE_REGION, &Region, &NewMem); if (Error == PI_ERROR_MISALIGNED_SUB_BUFFER_OFFSET) @@ -446,7 +446,7 @@ void *MemoryManager::allocateMemSubBuffer(ContextImplPtr TargetContext, PI_ERROR_INVALID_VALUE); if (Error != PI_SUCCESS) { - Plugin.reportPiError(Error, "allocateMemSubBuffer()"); + Plugin->reportPiError(Error, "allocateMemSubBuffer()"); } return NewMem; @@ -494,7 +494,7 @@ void copyH2D(SYCLMemObjI *SYCLMemObj, char *SrcMem, QueueImplPtr, assert(SYCLMemObj && "The SYCLMemObj is nullptr"); const RT::PiQueue Queue = TgtQueue->getHandleRef(); - const detail::plugin &Plugin = TgtQueue->getPlugin(); + const PluginPtr &Plugin = TgtQueue->getPlugin(); detail::SYCLMemObjI::MemObjType MemType = SYCLMemObj->getType(); TermPositions SrcPos, DstPos; @@ -509,7 +509,7 @@ void copyH2D(SYCLMemObjI *SYCLMemObj, char *SrcMem, QueueImplPtr, if (MemType == detail::SYCLMemObjI::MemObjType::Buffer) { if (1 == DimDst && 1 == DimSrc) { - Plugin.call( + Plugin->call( Queue, DstMem, /*blocking_write=*/PI_FALSE, DstXOffBytes, DstAccessRangeWidthBytes, SrcMem + SrcXOffBytes, DepEvents.size(), DepEvents.data(), &OutEvent); @@ -529,7 +529,7 @@ void copyH2D(SYCLMemObjI *SYCLMemObj, char *SrcMem, QueueImplPtr, DstAccessRange[DstPos.YTerm], DstAccessRange[DstPos.ZTerm]}; - Plugin.call( + Plugin->call( Queue, DstMem, /*blocking_write=*/PI_FALSE, &BufferOffset, &HostOffset, &RectRegion, BufferRowPitch, BufferSlicePitch, HostRowPitch, HostSlicePitch, @@ -547,7 +547,7 @@ void copyH2D(SYCLMemObjI *SYCLMemObj, char *SrcMem, QueueImplPtr, DstAccessRange[DstPos.YTerm], DstAccessRange[DstPos.ZTerm]}; - Plugin.call( + Plugin->call( Queue, DstMem, /*blocking_write=*/PI_FALSE, &Origin, &Region, InputRowPitch, InputSlicePitch, SrcMem, DepEvents.size(), DepEvents.data(), &OutEvent); @@ -566,7 +566,7 @@ void copyD2H(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, assert(SYCLMemObj && "The SYCLMemObj is nullptr"); const RT::PiQueue Queue = SrcQueue->getHandleRef(); - const detail::plugin &Plugin = SrcQueue->getPlugin(); + const PluginPtr &Plugin = SrcQueue->getPlugin(); detail::SYCLMemObjI::MemObjType MemType = SYCLMemObj->getType(); TermPositions SrcPos, DstPos; @@ -587,7 +587,7 @@ void copyD2H(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, if (MemType == detail::SYCLMemObjI::MemObjType::Buffer) { if (1 == DimDst && 1 == DimSrc) { - Plugin.call( + Plugin->call( Queue, SrcMem, /*blocking_read=*/PI_FALSE, SrcXOffBytes, SrcAccessRangeWidthBytes, DstMem + DstXOffBytes, DepEvents.size(), DepEvents.data(), &OutEvent); @@ -607,7 +607,7 @@ void copyD2H(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, SrcAccessRange[SrcPos.YTerm], SrcAccessRange[SrcPos.ZTerm]}; - Plugin.call( + Plugin->call( Queue, SrcMem, /*blocking_read=*/PI_FALSE, &BufferOffset, &HostOffset, &RectRegion, BufferRowPitch, BufferSlicePitch, HostRowPitch, HostSlicePitch, @@ -625,7 +625,7 @@ void copyD2H(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, SrcAccessRange[SrcPos.YTerm], SrcAccessRange[SrcPos.ZTerm]}; - Plugin.call( + Plugin->call( Queue, SrcMem, PI_FALSE, &Offset, &Region, RowPitch, SlicePitch, DstMem, DepEvents.size(), DepEvents.data(), &OutEvent); } @@ -641,7 +641,7 @@ void copyD2D(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, assert(SYCLMemObj && "The SYCLMemObj is nullptr"); const RT::PiQueue Queue = SrcQueue->getHandleRef(); - const detail::plugin &Plugin = SrcQueue->getPlugin(); + const PluginPtr &Plugin = SrcQueue->getPlugin(); detail::SYCLMemObjI::MemObjType MemType = SYCLMemObj->getType(); TermPositions SrcPos, DstPos; @@ -656,7 +656,7 @@ void copyD2D(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, if (MemType == detail::SYCLMemObjI::MemObjType::Buffer) { if (1 == DimDst && 1 == DimSrc) { - Plugin.call( + Plugin->call( Queue, SrcMem, DstMem, SrcXOffBytes, DstXOffBytes, SrcAccessRangeWidthBytes, DepEvents.size(), DepEvents.data(), &OutEvent); @@ -681,7 +681,7 @@ void copyD2D(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, SrcAccessRange[SrcPos.YTerm], SrcAccessRange[SrcPos.ZTerm]}; - Plugin.call( + Plugin->call( Queue, SrcMem, DstMem, &SrcOrigin, &DstOrigin, &Region, SrcRowPitch, SrcSlicePitch, DstRowPitch, DstSlicePitch, DepEvents.size(), DepEvents.data(), &OutEvent); @@ -697,7 +697,7 @@ void copyD2D(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue, SrcAccessRange[SrcPos.YTerm], SrcAccessRange[SrcPos.ZTerm]}; - Plugin.call( + Plugin->call( Queue, SrcMem, DstMem, &SrcOrigin, &DstOrigin, &Region, DepEvents.size(), DepEvents.data(), &OutEvent); } @@ -779,10 +779,10 @@ void MemoryManager::fill(SYCLMemObjI *SYCLMemObj, void *Mem, QueueImplPtr Queue, RT::PiEvent &OutEvent) { assert(SYCLMemObj && "The SYCLMemObj is nullptr"); - const detail::plugin &Plugin = Queue->getPlugin(); + const PluginPtr &Plugin = Queue->getPlugin(); if (SYCLMemObj->getType() == detail::SYCLMemObjI::MemObjType::Buffer) { if (Dim <= 1) { - Plugin.call( + Plugin->call( Queue->getHandleRef(), pi::cast(Mem), Pattern, PatternSize, Offset[0] * ElementSize, Range[0] * ElementSize, DepEvents.size(), DepEvents.data(), &OutEvent); @@ -791,7 +791,7 @@ void MemoryManager::fill(SYCLMemObjI *SYCLMemObj, void *Mem, QueueImplPtr Queue, throw runtime_error("Not supported configuration of fill requested", PI_ERROR_INVALID_OPERATION); } else { - Plugin.call( + Plugin->call( Queue->getHandleRef(), pi::cast(Mem), Pattern, &Offset[0], &Range[0], DepEvents.size(), DepEvents.data(), &OutEvent); } @@ -835,7 +835,7 @@ void *MemoryManager::map(SYCLMemObjI *, void *Mem, QueueImplPtr Queue, void *MappedPtr = nullptr; const size_t BytesToMap = AccessRange[0] * AccessRange[1] * AccessRange[2]; - const detail::plugin &Plugin = Queue->getPlugin(); + const PluginPtr &Plugin = Queue->getPlugin(); memBufferMapHelper(Plugin, Queue->getHandleRef(), pi::cast(Mem), PI_FALSE, Flags, AccessOffset[0], BytesToMap, DepEvents.size(), DepEvents.data(), &OutEvent, &MappedPtr); @@ -850,7 +850,7 @@ void MemoryManager::unmap(SYCLMemObjI *, void *Mem, QueueImplPtr Queue, // All DepEvents are to the same Context. // Using the plugin of the Queue. - const detail::plugin &Plugin = Queue->getPlugin(); + const PluginPtr &Plugin = Queue->getPlugin(); memUnmapHelper(Plugin, Queue->getHandleRef(), pi::cast(Mem), MappedPtr, DepEvents.size(), DepEvents.data(), &OutEvent); } @@ -864,7 +864,7 @@ void MemoryManager::copy_usm(const void *SrcMem, QueueImplPtr SrcQueue, if (!Len) { // no-op, but ensure DepEvents will still be waited on if (!DepEvents.empty()) { - SrcQueue->getPlugin().call( + SrcQueue->getPlugin()->call( SrcQueue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); } @@ -875,11 +875,11 @@ void MemoryManager::copy_usm(const void *SrcMem, QueueImplPtr SrcQueue, throw runtime_error("NULL pointer argument in memory copy operation.", PI_ERROR_INVALID_VALUE); - const detail::plugin &Plugin = SrcQueue->getPlugin(); - Plugin.call(SrcQueue->getHandleRef(), - /* blocking */ PI_FALSE, DstMem, - SrcMem, Len, DepEvents.size(), - DepEvents.data(), OutEvent); + const PluginPtr &Plugin = SrcQueue->getPlugin(); + Plugin->call( + SrcQueue->getHandleRef(), + /* blocking */ PI_FALSE, DstMem, SrcMem, Len, DepEvents.size(), + DepEvents.data(), OutEvent); } void MemoryManager::fill_usm(void *Mem, QueueImplPtr Queue, size_t Length, @@ -890,7 +890,7 @@ void MemoryManager::fill_usm(void *Mem, QueueImplPtr Queue, size_t Length, if (!Length) { // no-op, but ensure DepEvents will still be waited on if (!DepEvents.empty()) { - Queue->getPlugin().call( + Queue->getPlugin()->call( Queue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); } return; @@ -900,8 +900,8 @@ void MemoryManager::fill_usm(void *Mem, QueueImplPtr Queue, size_t Length, throw runtime_error("NULL pointer argument in memory fill operation.", PI_ERROR_INVALID_VALUE); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), Mem, Pattern, Length, DepEvents.size(), DepEvents.data(), OutEvent); } @@ -912,8 +912,8 @@ void MemoryManager::prefetch_usm(void *Mem, QueueImplPtr Queue, size_t Length, assert(!Queue->getContextImplPtr()->is_host() && "Host queue not supported in prefetch_usm."); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), Mem, Length, _pi_usm_migration_flags(0), DepEvents.size(), DepEvents.data(), OutEvent); } @@ -925,9 +925,9 @@ void MemoryManager::advise_usm(const void *Mem, QueueImplPtr Queue, assert(!Queue->getContextImplPtr()->is_host() && "Host queue not supported in advise_usm."); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call(Queue->getHandleRef(), Mem, - Length, Advice, OutEvent); + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call(Queue->getHandleRef(), Mem, + Length, Advice, OutEvent); } void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, @@ -941,7 +941,7 @@ void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, if (Width == 0 || Height == 0) { // no-op, but ensure DepEvents will still be waited on if (!DepEvents.empty()) { - Queue->getPlugin().call( + Queue->getPlugin()->call( Queue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); } return; @@ -951,17 +951,17 @@ void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, throw sycl::exception(sycl::make_error_code(errc::invalid), "NULL pointer argument in 2D memory copy operation."); - const detail::plugin &Plugin = Queue->getPlugin(); + const PluginPtr &Plugin = Queue->getPlugin(); pi_bool SupportsUSMMemcpy2D = false; - Plugin.call( + Plugin->call( Queue->getContextImplPtr()->getHandleRef(), PI_EXT_ONEAPI_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT, sizeof(pi_bool), &SupportsUSMMemcpy2D, nullptr); if (SupportsUSMMemcpy2D) { // Direct memcpy2D is supported so we use this function. - Plugin.call( + Plugin->call( Queue->getHandleRef(), /*blocking=*/PI_FALSE, DstMem, DstPitch, SrcMem, SrcPitch, Width, Height, DepEvents.size(), DepEvents.data(), OutEvent); return; @@ -988,7 +988,7 @@ void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, for (size_t I = 0; I < Height; ++I) { char *DstItBegin = static_cast(DstMem) + I * DstPitch; const char *SrcItBegin = static_cast(SrcMem) + I * SrcPitch; - Plugin.call( + Plugin->call( Queue->getHandleRef(), /* blocking */ PI_FALSE, DstItBegin, SrcItBegin, Width, DepEvents.size(), DepEvents.data(), CopyEvents.data() + I); CopyEventsManaged.emplace_back(CopyEvents[I], Plugin, @@ -996,7 +996,7 @@ void MemoryManager::copy_2d_usm(const void *SrcMem, size_t SrcPitch, } // Then insert a wait to coalesce the copy events. - Queue->getPlugin().call( + Queue->getPlugin()->call( Queue->getHandleRef(), CopyEvents.size(), CopyEvents.data(), OutEvent); } @@ -1011,7 +1011,7 @@ void MemoryManager::fill_2d_usm(void *DstMem, QueueImplPtr Queue, size_t Pitch, if (Width == 0 || Height == 0) { // no-op, but ensure DepEvents will still be waited on if (!DepEvents.empty()) { - Queue->getPlugin().call( + Queue->getPlugin()->call( Queue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); } return; @@ -1020,8 +1020,8 @@ void MemoryManager::fill_2d_usm(void *DstMem, QueueImplPtr Queue, size_t Pitch, if (!DstMem) throw sycl::exception(sycl::make_error_code(errc::invalid), "NULL pointer argument in 2D memory fill operation."); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), DstMem, Pitch, Pattern.size(), Pattern.data(), Width, Height, DepEvents.size(), DepEvents.data(), OutEvent); } @@ -1037,7 +1037,7 @@ void MemoryManager::memset_2d_usm(void *DstMem, QueueImplPtr Queue, if (Width == 0 || Height == 0) { // no-op, but ensure DepEvents will still be waited on if (!DepEvents.empty()) { - Queue->getPlugin().call( + Queue->getPlugin()->call( Queue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); } return; @@ -1047,8 +1047,8 @@ void MemoryManager::memset_2d_usm(void *DstMem, QueueImplPtr Queue, throw sycl::exception( sycl::make_error_code(errc::invalid), "NULL pointer argument in 2D memory memset operation."); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), DstMem, Pitch, static_cast(Value), Width, Height, DepEvents.size(), DepEvents.data(), OutEvent); } @@ -1161,8 +1161,8 @@ static void memcpyToDeviceGlobalDirect( const std::vector &DepEvents, RT::PiEvent *OutEvent) { RT::PiProgram Program = getOrBuildProgramForDeviceGlobal(Queue, DeviceGlobalEntry, M); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), Program, DeviceGlobalEntry->MUniqueId.c_str(), false, NumBytes, Offset, Src, DepEvents.size(), DepEvents.data(), OutEvent); @@ -1174,8 +1174,8 @@ static void memcpyFromDeviceGlobalDirect( const std::vector &DepEvents, RT::PiEvent *OutEvent) { RT::PiProgram Program = getOrBuildProgramForDeviceGlobal(Queue, DeviceGlobalEntry, M); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), Program, DeviceGlobalEntry->MUniqueId.c_str(), false, NumBytes, Offset, Dest, DepEvents.size(), DepEvents.data(), OutEvent); diff --git a/sycl/source/detail/persistent_device_code_cache.cpp b/sycl/source/detail/persistent_device_code_cache.cpp index 7473fc32193a..2bae6c64c1c5 100644 --- a/sycl/source/detail/persistent_device_code_cache.cpp +++ b/sycl/source/detail/persistent_device_code_cache.cpp @@ -106,12 +106,12 @@ void PersistentDeviceCodeCache::putItemToDisc( unsigned int DeviceNum = 0; - Plugin.call( + Plugin->call( NativePrg, PI_PROGRAM_INFO_NUM_DEVICES, sizeof(DeviceNum), &DeviceNum, nullptr); std::vector BinarySizes(DeviceNum); - Plugin.call( + Plugin->call( NativePrg, PI_PROGRAM_INFO_BINARY_SIZES, sizeof(size_t) * BinarySizes.size(), BinarySizes.data(), nullptr); @@ -122,9 +122,9 @@ void PersistentDeviceCodeCache::putItemToDisc( Pointers.push_back(Result[I].data()); } - Plugin.call(NativePrg, PI_PROGRAM_INFO_BINARIES, - sizeof(char *) * Pointers.size(), - Pointers.data(), nullptr); + Plugin->call(NativePrg, PI_PROGRAM_INFO_BINARIES, + sizeof(char *) * Pointers.size(), + Pointers.data(), nullptr); try { OSUtil::makeDir(DirName.c_str()); diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index c50971ca32bb..9163158c79d3 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -54,9 +54,9 @@ xpti_td *GPIArgCallEvent = nullptr; template void *getPluginOpaqueData(void *OpaqueDataParam) { void *ReturnOpaqueData = nullptr; - const sycl::detail::plugin &Plugin = sycl::detail::pi::getPlugin(); + const PluginPtr &Plugin = pi::getPlugin(); - Plugin.call( + Plugin->call( OpaqueDataParam, &ReturnOpaqueData); return ReturnOpaqueData; @@ -67,7 +67,7 @@ getPluginOpaqueData(void *); namespace pi { -static void initializePlugins(std::vector &Plugins); +static void initializePlugins(std::vector &Plugins); bool XPTIInitDone = false; @@ -174,9 +174,9 @@ void contextSetExtendedDeleter(const sycl::context &context, void *user_data) { auto impl = getSyclObjImpl(context); auto contextHandle = reinterpret_cast(impl->getHandleRef()); - auto plugin = impl->getPlugin(); - plugin.call(contextHandle, func, - user_data); + const auto &Plugin = impl->getPlugin(); + Plugin->call(contextHandle, func, + user_data); } std::string platformInfoToString(pi_platform_info info) { @@ -286,6 +286,7 @@ std::vector> findPlugins() { backend::ext_oneapi_level_zero); PluginNames.emplace_back(__SYCL_CUDA_PLUGIN_NAME, backend::ext_oneapi_cuda); PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip); + PluginNames.emplace_back(__SYCL_UR_PLUGIN_NAME, backend::all); } else if (FilterList) { std::vector Filters = FilterList->get(); bool OpenCLFound = false; @@ -323,6 +324,7 @@ std::vector> findPlugins() { backend::ext_oneapi_hip); HIPFound = true; } + PluginNames.emplace_back(__SYCL_UR_PLUGIN_NAME, backend::all); } } else { ods_target_list &list = *OdsTargetList; @@ -344,6 +346,7 @@ std::vector> findPlugins() { if (list.backendCompatible(backend::ext_oneapi_hip)) { PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip); } + PluginNames.emplace_back(__SYCL_UR_PLUGIN_NAME, backend::all); } return PluginNames; } @@ -390,7 +393,7 @@ bool trace(TraceLevel Level) { } // Initializes all available Plugins. -std::vector &initialize() { +std::vector &initialize() { static std::once_flag PluginsInitDone; // std::call_once is blocking all other threads if a thread is already // creating a vector of plugins. So, no additional lock is needed. @@ -400,7 +403,7 @@ std::vector &initialize() { return GlobalHandler::instance().getPlugins(); } -static void initializePlugins(std::vector &Plugins) { +static void initializePlugins(std::vector &Plugins) { std::vector> PluginNames = findPlugins(); if (PluginNames.empty() && trace(PI_TRACE_ALL)) @@ -435,14 +438,13 @@ static void initializePlugins(std::vector &Plugins) { } continue; } - plugin &NewPlugin = Plugins.emplace_back( - plugin(PluginInformation, PluginNames[I].second, Library)); + PluginPtr &NewPlugin = Plugins.emplace_back(std::make_shared( + PluginInformation, PluginNames[I].second, Library)); if (trace(TraceLevel::PI_TRACE_BASIC)) std::cerr << "SYCL_PI_TRACE[basic]: " << "Plugin found and successfully loaded: " - << PluginNames[I].first - << " [ PluginVersion: " << NewPlugin.getPiPlugin().PluginVersion - << " ]" << std::endl; + << PluginNames[I].first << " [ PluginVersion: " + << NewPlugin->getPiPlugin().PluginVersion << " ]" << std::endl; } #ifdef XPTI_ENABLE_INSTRUMENTATION @@ -499,14 +501,14 @@ static void initializePlugins(std::vector &Plugins) { } // Get the plugin serving given backend. -template const plugin &getPlugin() { - static const plugin *Plugin = nullptr; +template const PluginPtr &getPlugin() { + static PluginPtr *Plugin = nullptr; if (Plugin) return *Plugin; - const std::vector &Plugins = pi::initialize(); - for (const auto &P : Plugins) - if (P.hasBackend(BE)) { + std::vector &Plugins = pi::initialize(); + for (auto &P : Plugins) + if (P->hasBackend(BE)) { Plugin = &P; return *Plugin; } @@ -515,12 +517,12 @@ template const plugin &getPlugin() { PI_ERROR_INVALID_OPERATION); } -template __SYCL_EXPORT const plugin &getPlugin(); -template __SYCL_EXPORT const plugin & +template __SYCL_EXPORT const PluginPtr &getPlugin(); +template __SYCL_EXPORT const PluginPtr & getPlugin(); -template __SYCL_EXPORT const plugin & +template __SYCL_EXPORT const PluginPtr & getPlugin(); -template __SYCL_EXPORT const plugin &getPlugin(); +template __SYCL_EXPORT const PluginPtr &getPlugin(); // Report error and no return (keeps compiler from printing warnings). // TODO: Probably change that to throw a catchable exception, diff --git a/sycl/source/detail/pi_utils.hpp b/sycl/source/detail/pi_utils.hpp index 78bbb2e54d07..e808da8d4aff 100644 --- a/sycl/source/detail/pi_utils.hpp +++ b/sycl/source/detail/pi_utils.hpp @@ -20,19 +20,20 @@ namespace detail { // RAII object for keeping ownership of a PI event. struct OwnedPiEvent { - OwnedPiEvent(const plugin &Plugin) : MEvent{std::nullopt}, MPlugin{Plugin} {} - OwnedPiEvent(RT::PiEvent Event, const plugin &Plugin, + OwnedPiEvent(const PluginPtr &Plugin) + : MEvent{std::nullopt}, MPlugin{Plugin} {} + OwnedPiEvent(RT::PiEvent Event, const PluginPtr &Plugin, bool TakeOwnership = false) : MEvent(Event), MPlugin(Plugin) { // If it is not instructed to take ownership, retain the event to share // ownership of it. if (!TakeOwnership) - MPlugin.call(*MEvent); + MPlugin->call(*MEvent); } ~OwnedPiEvent() { // Release the event if the ownership was not transferred. if (MEvent.has_value()) - MPlugin.call(*MEvent); + MPlugin->call(*MEvent); } OwnedPiEvent(OwnedPiEvent &&Other) @@ -58,7 +59,7 @@ struct OwnedPiEvent { private: std::optional MEvent; - const plugin &MPlugin; + const PluginPtr &MPlugin; }; } // namespace detail diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index fffa19888f41..c964e5745212 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace sycl { @@ -36,7 +37,7 @@ PlatformImplPtr platform_impl::getHostPlatformImpl() { } PlatformImplPtr platform_impl::getOrMakePlatformImpl(RT::PiPlatform PiPlatform, - const plugin &Plugin) { + const PluginPtr &Plugin) { PlatformImplPtr Result; { const std::lock_guard Guard( @@ -59,12 +60,13 @@ PlatformImplPtr platform_impl::getOrMakePlatformImpl(RT::PiPlatform PiPlatform, return Result; } -PlatformImplPtr platform_impl::getPlatformFromPiDevice(RT::PiDevice PiDevice, - const plugin &Plugin) { +PlatformImplPtr +platform_impl::getPlatformFromPiDevice(RT::PiDevice PiDevice, + const PluginPtr &Plugin) { RT::PiPlatform Plt = nullptr; // TODO catch an exception and put it to list // of asynchronous exceptions - Plugin.call(PiDevice, PI_DEVICE_INFO_PLATFORM, - sizeof(Plt), &Plt, nullptr); + Plugin->call(PiDevice, PI_DEVICE_INFO_PLATFORM, + sizeof(Plt), &Plt, nullptr); return getOrMakePlatformImpl(Plt, Plugin); } @@ -102,19 +104,18 @@ static bool IsBannedPlatform(platform Platform) { // This routine has the side effect of registering each platform's last device // id into each plugin, which is used for device counting. std::vector platform_impl::get_platforms() { - std::vector Platforms; - std::vector &Plugins = RT::initialize(); - for (plugin &Plugin : Plugins) { + + // Get the vector of platforms supported by a given PI plugin + auto getPluginPlatforms = [](PluginPtr &Plugin) { + std::vector Platforms; pi_uint32 NumPlatforms = 0; - // Move to the next plugin if the plugin fails to initialize. - // This way platforms from other plugins get a chance to be discovered. - if (Plugin.call_nocheck( + if (Plugin->call_nocheck( 0, nullptr, &NumPlatforms) != PI_SUCCESS) - continue; + return Platforms; if (NumPlatforms) { std::vector PiPlatforms(NumPlatforms); - if (Plugin.call_nocheck( + if (Plugin->call_nocheck( NumPlatforms, PiPlatforms.data(), nullptr) != PI_SUCCESS) return Platforms; @@ -126,12 +127,6 @@ std::vector platform_impl::get_platforms() { // mess up device counting } - { - std::lock_guard Guard(*Plugin.getPluginMutex()); - // insert PiPlatform into the Plugin - Plugin.getPlatformId(PiPlatform); - } - // The SYCL spec says that a platform has one or more devices. ( SYCL // 2020 4.6.2 ) If we have an empty platform, we don't report it back // from platform::get_platforms(). @@ -140,6 +135,60 @@ std::vector platform_impl::get_platforms() { } } } + return Platforms; + }; + + static const bool PreferUR = [] { + const char *PreferURStr = std::getenv("SYCL_PREFER_UR"); + return (PreferURStr && (std::stoi(PreferURStr) != 0)); + }(); + + // See which platform we want to be served by which plugin. + // There should be just one plugin serving each backend. + std::vector &Plugins = RT::initialize(); + std::vector> PlatformsWithPlugin; + + // First check Unified Runtime + // Keep track of backends covered by UR + std::unordered_set BackendsUR; + if (PreferUR) { + PluginPtr *PluginUR = nullptr; + for (PluginPtr &Plugin : Plugins) { + if (Plugin->hasBackend(backend::all)) { // this denotes UR + PluginUR = &Plugin; + break; + } + } + if (PluginUR) { + for (const auto &P : getPluginPlatforms(*PluginUR)) { + PlatformsWithPlugin.push_back({P, *PluginUR}); + BackendsUR.insert(getSyclObjImpl(P)->getBackend()); + } + } + } + + // Then check backend-specific plugins + for (auto &Plugin : Plugins) { + if (Plugin->hasBackend(backend::all)) { + continue; // skip UR on this pass + } + const auto &PluginPlatforms = getPluginPlatforms(Plugin); + for (const auto &P : PluginPlatforms) { + // Only add those not already covered by UR + if (BackendsUR.find(getSyclObjImpl(P)->getBackend()) == + BackendsUR.end()) { + PlatformsWithPlugin.push_back({P, Plugin}); + } + } + } + + // For the selected platforms register them with their plugins + std::vector Platforms; + for (auto &Platform : PlatformsWithPlugin) { + auto &Plugin = Platform.second; + std::lock_guard Guard(*Plugin->getPluginMutex()); + Plugin->getPlatformId(getSyclObjImpl(Platform.first)->getHandleRef()); + Platforms.push_back(Platform.first); } // Register default context release handler after plugins have been loaded and @@ -166,9 +215,9 @@ std::vector platform_impl::get_platforms() { // The return value is a vector that represents the indices of the chosen // devices. template -static std::vector filterDeviceFilter(std::vector &PiDevices, - RT::PiPlatform Platform, - ListT *FilterList) { +std::vector +platform_impl::filterDeviceFilter(std::vector &PiDevices, + ListT *FilterList) const { constexpr bool is_ods_target = std::is_same_v; // There are some differences in implementation between SYCL_DEVICE_FILTER @@ -198,33 +247,23 @@ static std::vector filterDeviceFilter(std::vector &PiDevices, // devices and is whats returned by the function std::vector original_indices; - std::vector &Plugins = RT::initialize(); - auto It = - std::find_if(Plugins.begin(), Plugins.end(), [Platform](plugin &Plugin) { - return Plugin.containsPiPlatform(Platform); - }); - if (It == Plugins.end()) { - return original_indices; - } - plugin &Plugin = *It; - // Find out backend of the platform RT::PiPlatformBackend PiBackend; - Plugin.call( - Platform, PI_EXT_PLATFORM_INFO_BACKEND, sizeof(RT::PiPlatformBackend), + MPlugin->call( + MPlatform, PI_EXT_PLATFORM_INFO_BACKEND, sizeof(RT::PiPlatformBackend), &PiBackend, nullptr); backend Backend = convertBackend(PiBackend); int InsertIDx = 0; // DeviceIds should be given consecutive numbers across platforms in the same // backend - std::lock_guard Guard(*Plugin.getPluginMutex()); - int DeviceNum = Plugin.getStartingDeviceId(Platform); + std::lock_guard Guard(*MPlugin->getPluginMutex()); + int DeviceNum = MPlugin->getStartingDeviceId(MPlatform); for (RT::PiDevice Device : PiDevices) { RT::PiDeviceType PiDevType; - Plugin.call(Device, PI_DEVICE_INFO_TYPE, - sizeof(RT::PiDeviceType), - &PiDevType, nullptr); + MPlugin->call(Device, PI_DEVICE_INFO_TYPE, + sizeof(RT::PiDeviceType), + &PiDevType, nullptr); // Assumption here is that there is 1-to-1 mapping between PiDevType and // Sycl device type for GPU, CPU, and ACC. info::device_type DeviceType = pi::cast(PiDevType); @@ -285,7 +324,7 @@ static std::vector filterDeviceFilter(std::vector &PiDevices, // remember the last backend that has gone through this filter function // to assign a unique device id number across platforms that belong to // the same backend. For example, opencl:cpu:0, opencl:acc:1, opencl:gpu:2 - Plugin.setLastDeviceId(Platform, DeviceNum); + MPlugin->setLastDeviceId(MPlatform, DeviceNum); return original_indices; } @@ -483,8 +522,7 @@ platform_impl::get_devices(info::device_type DeviceType) const { return Res; pi_uint32 NumDevices = 0; - const detail::plugin &Plugin = getPlugin(); - Plugin.call( + MPlugin->call( MPlatform, pi::cast(DeviceType), 0, // CP info::device_type::all pi::cast(nullptr), &NumDevices); @@ -496,21 +534,22 @@ 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 plugin reference. - std::vector &Plugins = RT::initialize(); + std::vector &Plugins = RT::initialize(); auto It = std::find_if(Plugins.begin(), Plugins.end(), - [&Platform = MPlatform](plugin &Plugin) { - return Plugin.containsPiPlatform(Platform); + [&Platform = MPlatform](PluginPtr &Plugin) { + return Plugin->containsPiPlatform(Platform); }); if (It != Plugins.end()) { - std::lock_guard Guard(*(It->getPluginMutex())); - (*It).adjustLastDeviceId(MPlatform); + PluginPtr &Plugin = *It; + std::lock_guard Guard(*Plugin->getPluginMutex()); + Plugin->adjustLastDeviceId(MPlatform); } return Res; } std::vector PiDevices(NumDevices); // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + MPlugin->call( MPlatform, pi::cast(DeviceType), // CP info::device_type::all NumDevices, PiDevices.data(), nullptr); @@ -521,7 +560,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(PiDevices, MPlatform, Plugin); + applyAllowList(PiDevices, MPlatform, MPlugin); // The first step is to filter out devices that are not compatible with // SYCL_DEVICE_FILTER or ONEAPI_DEVICE_SELECTOR. This is also the mechanism by @@ -534,16 +573,16 @@ platform_impl::get_devices(info::device_type DeviceType) const { "conjunction with SYCL_DEVICE_FILTER"); } PlatformDeviceIndices = filterDeviceFilter( - PiDevices, MPlatform, OdsTargetList); + PiDevices, OdsTargetList); } else if (FilterList) { PlatformDeviceIndices = - filterDeviceFilter( - PiDevices, MPlatform, FilterList); + filterDeviceFilter(PiDevices, + FilterList); } // The next step is to inflate the filtered PIDevices into SYCL Device // objects. - PlatformImplPtr PlatformImpl = getOrMakePlatformImpl(MPlatform, Plugin); + PlatformImplPtr PlatformImpl = getOrMakePlatformImpl(MPlatform, MPlugin); std::transform( PiDevices.begin(), PiDevices.end(), std::back_inserter(Res), [PlatformImpl](const RT::PiDevice &PiDevice) -> device { @@ -554,7 +593,7 @@ platform_impl::get_devices(info::device_type DeviceType) const { // The reference counter for handles, that we used to create sycl objects, is // incremented, so we need to call release here. for (RT::PiDevice &PiDev : PiDevicesToCleanUp) - Plugin.call(PiDev); + MPlugin->call(PiDev); // If we aren't using ONEAPI_DEVICE_SELECTOR, then we are done. // and if there are no devices so far, there won't be any need to replace them @@ -581,7 +620,8 @@ bool platform_impl::has_extension(const std::string &ExtensionName) const { pi_native_handle platform_impl::getNative() const { const auto &Plugin = getPlugin(); pi_native_handle Handle; - Plugin.call(getHandleRef(), &Handle); + Plugin->call(getHandleRef(), + &Handle); return Handle; } diff --git a/sycl/source/detail/platform_impl.hpp b/sycl/source/detail/platform_impl.hpp index 6741197bae79..e8494ccc0be4 100644 --- a/sycl/source/detail/platform_impl.hpp +++ b/sycl/source/detail/platform_impl.hpp @@ -41,11 +41,8 @@ class platform_impl { /// /// \param APlatform is a raw plug-in platform handle. /// \param APlugin is a plug-in handle. - explicit platform_impl(RT::PiPlatform APlatform, const plugin &APlugin) - : platform_impl(APlatform, std::make_shared(APlugin)) {} - explicit platform_impl(RT::PiPlatform APlatform, - std::shared_ptr APlugin) + const std::shared_ptr &APlugin) : MPlatform(APlatform), MPlugin(APlugin) { // Find out backend of the platform @@ -91,9 +88,10 @@ class platform_impl { void getBackendOption(const char *frontend_option, const char **backend_option) const { const auto &Plugin = getPlugin(); - RT::PiResult Err = Plugin.call_nocheck( - MPlatform, frontend_option, backend_option); - Plugin.checkPiResult(Err); + RT::PiResult Err = + Plugin->call_nocheck( + MPlatform, frontend_option, backend_option); + Plugin->checkPiResult(Err); } /// \return an instance of OpenCL cl_platform_id. @@ -131,20 +129,18 @@ class platform_impl { static std::vector get_platforms(); // \return the Plugin associated with this platform. - const plugin &getPlugin() const { + const PluginPtr &getPlugin() const { assert(!MHostPlatform && "Plugin is not available for Host."); - return *MPlugin; + return MPlugin; } /// Sets the platform implementation to use another plugin. /// /// \param PluginPtr is a pointer to a plugin instance /// \param Backend is the backend that we want this platform to use - void setPlugin(std::shared_ptr PluginPtr, backend Backend) { + void setPlugin(PluginPtr &PluginPtr, backend Backend) { assert(!MHostPlatform && "Plugin is not available for Host"); - MPlugin = std::move(PluginPtr); - // Make sure that the given plugin supports wanted backend - assert(MPlugin->hasBackend(Backend) && "Plugin does not serve backend"); + MPlugin = PluginPtr; MBackend = Backend; } @@ -200,7 +196,7 @@ class platform_impl { /// \param Plugin is the PI plugin providing the backend for the platform /// \return the platform_impl representing the PI platform static std::shared_ptr - getOrMakePlatformImpl(RT::PiPlatform PiPlatform, const plugin &Plugin); + getOrMakePlatformImpl(RT::PiPlatform PiPlatform, const PluginPtr &Plugin); /// Queries the cache for the specified platform based on an input device. /// If found, returns the the cached platform_impl, otherwise creates a new @@ -212,7 +208,7 @@ class platform_impl { /// platform /// \return the platform_impl that contains the input device static std::shared_ptr - getPlatformFromPiDevice(RT::PiDevice PiDevice, const plugin &Plugin); + getPlatformFromPiDevice(RT::PiDevice PiDevice, const PluginPtr &Plugin); // when getting sub-devices for ONEAPI_DEVICE_SELECTOR we may temporarily // ensure every device is a root one. @@ -221,11 +217,16 @@ class platform_impl { private: std::shared_ptr getDeviceImplHelper(RT::PiDevice PiDevice); + // Helper to filter reportable devices in the platform + template + std::vector filterDeviceFilter(std::vector &PiDevices, + ListT *FilterList) const; + bool MHostPlatform = false; RT::PiPlatform MPlatform = 0; backend MBackend; - std::shared_ptr MPlugin; + PluginPtr MPlugin; std::vector> MDeviceCache; std::mutex MDeviceMapMutex; }; diff --git a/sycl/source/detail/platform_info.hpp b/sycl/source/detail/platform_info.hpp index 2c7ed14191cd..0c11304c4676 100644 --- a/sycl/source/detail/platform_info.hpp +++ b/sycl/source/detail/platform_info.hpp @@ -19,19 +19,19 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { namespace detail { inline std::string get_platform_info_string_impl(RT::PiPlatform Plt, - const plugin &Plugin, + const PluginPtr &Plugin, pi_platform_info PiCode) { size_t ResultSize; // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(Plt, PiCode, 0, nullptr, - &ResultSize); + Plugin->call(Plt, PiCode, 0, nullptr, + &ResultSize); if (ResultSize == 0) { return ""; } std::unique_ptr Result(new char[ResultSize]); // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call(Plt, PiCode, ResultSize, - Result.get(), nullptr); + Plugin->call(Plt, PiCode, ResultSize, + Result.get(), nullptr); return Result.get(); } // The platform information methods @@ -39,7 +39,7 @@ template typename std::enable_if< std::is_same::value, std::string>::type -get_platform_info(RT::PiPlatform Plt, const plugin &Plugin) { +get_platform_info(RT::PiPlatform Plt, const PluginPtr &Plugin) { static_assert(is_platform_info_desc::value, "Invalid platform information descriptor"); return get_platform_info_string_impl(Plt, Plugin, @@ -49,7 +49,7 @@ get_platform_info(RT::PiPlatform Plt, const plugin &Plugin) { template typename std::enable_if::value, std::vector>::type -get_platform_info(RT::PiPlatform Plt, const plugin &Plugin) { +get_platform_info(RT::PiPlatform Plt, const PluginPtr &Plugin) { static_assert(is_platform_info_desc::value, "Invalid platform information descriptor"); std::string Result = get_platform_info_string_impl( diff --git a/sycl/source/detail/plugin.hpp b/sycl/source/detail/plugin.hpp index 312758daa87f..9726063a8ea2 100644 --- a/sycl/source/detail/plugin.hpp +++ b/sycl/source/detail/plugin.hpp @@ -96,10 +96,11 @@ class plugin { TracingMutex(std::make_shared()), MPluginMutex(std::make_shared()) {} - plugin &operator=(const plugin &) = default; - plugin(const plugin &) = default; - plugin &operator=(plugin &&other) noexcept = default; - plugin(plugin &&other) noexcept = default; + // Disallow accidental copies of plugins + plugin &operator=(const plugin &) = delete; + plugin(const plugin &) = delete; + plugin &operator=(plugin &&other) noexcept = delete; + plugin(plugin &&other) noexcept = delete; ~plugin() = default; @@ -159,8 +160,8 @@ class plugin { /// /// Usage: /// \code{cpp} - /// PiResult Err = plugin.call(Args); - /// Plugin.checkPiResult(Err); // Checks Result and throws a runtime_error + /// PiResult Err = Plugin->call(Args); + /// Plugin->checkPiResult(Err); // Checks Result and throws a runtime_error /// // exception. /// \endcode /// @@ -303,6 +304,9 @@ class plugin { // index of this vector corresponds to the index in PiPlatforms vector. std::vector LastDeviceIds; }; // class plugin + +using PluginPtr = std::shared_ptr; + } // namespace detail } // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl diff --git a/sycl/source/detail/program_impl.cpp b/sycl/source/detail/program_impl.cpp index 7c3f8535d9db..72d79818f69a 100644 --- a/sycl/source/detail/program_impl.cpp +++ b/sycl/source/detail/program_impl.cpp @@ -107,12 +107,12 @@ program_impl::program_impl( NonInterOpToLink |= !Prg->MLinkable; Programs.push_back(Prg->MProgram); } - const detail::plugin &Plugin = getPlugin(); - RT::PiResult Err = Plugin.call_nocheck( + const PluginPtr &Plugin = getPlugin(); + RT::PiResult Err = Plugin->call_nocheck( MContext->getHandleRef(), Devices.size(), Devices.data(), LinkOptions.c_str(), Programs.size(), Programs.data(), nullptr, nullptr, &MProgram); - Plugin.checkPiResult(Err); + Plugin->checkPiResult(Err); } } @@ -126,25 +126,25 @@ program_impl::program_impl(ContextImplPtr Context, pi_native_handle InteropProgram, RT::PiProgram Program) : MProgram(Program), MContext(Context), MLinkable(true) { - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); if (MProgram == nullptr) { assert(InteropProgram && "No InteropProgram/PiProgram defined with piextProgramFromNative"); // Translate the raw program handle into PI program. - Plugin.call( + Plugin->call( InteropProgram, MContext->getHandleRef(), false, &MProgram); } else - Plugin.call(Program); + Plugin->call(Program); // TODO handle the case when cl_program build is in progress pi_uint32 NumDevices; - Plugin.call( + Plugin->call( MProgram, PI_PROGRAM_INFO_NUM_DEVICES, sizeof(pi_uint32), &NumDevices, nullptr); std::vector PiDevices(NumDevices); - Plugin.call(MProgram, PI_PROGRAM_INFO_DEVICES, - sizeof(RT::PiDevice) * NumDevices, - PiDevices.data(), nullptr); + Plugin->call(MProgram, PI_PROGRAM_INFO_DEVICES, + sizeof(RT::PiDevice) * NumDevices, + PiDevices.data(), nullptr); std::vector SyclContextDevices = MContext->get_info(); @@ -164,7 +164,7 @@ program_impl::program_impl(ContextImplPtr Context, RT::PiDevice Device = getSyclObjImpl(MDevices[0])->getHandleRef(); // TODO check build for each device instead cl_program_binary_type BinaryType; - Plugin.call( + Plugin->call( MProgram, Device, PI_PROGRAM_BUILD_INFO_BINARY_TYPE, sizeof(cl_program_binary_type), &BinaryType, nullptr); if (BinaryType == PI_PROGRAM_BINARY_TYPE_NONE) { @@ -174,10 +174,10 @@ program_impl::program_impl(ContextImplPtr Context, PI_ERROR_INVALID_PROGRAM); } size_t Size = 0; - Plugin.call( + Plugin->call( MProgram, Device, PI_PROGRAM_BUILD_INFO_OPTIONS, 0, nullptr, &Size); std::vector OptionsVector(Size); - Plugin.call( + Plugin->call( MProgram, Device, PI_PROGRAM_BUILD_INFO_OPTIONS, Size, OptionsVector.data(), nullptr); std::string Options(OptionsVector.begin(), OptionsVector.end()); @@ -208,8 +208,8 @@ program_impl::program_impl(ContextImplPtr Context, RT::PiKernel Kernel) program_impl::~program_impl() { // TODO catch an exception and put it to list of asynchronous exceptions if (!is_host() && MProgram != nullptr) { - const detail::plugin &Plugin = getPlugin(); - Plugin.call(MProgram); + const PluginPtr &Plugin = getPlugin(); + Plugin->call(MProgram); } } @@ -220,7 +220,7 @@ cl_program program_impl::get() const { "This instance of program doesn't support OpenCL interoperability.", PI_ERROR_INVALID_PROGRAM); } - getPlugin().call(MProgram); + getPlugin()->call(MProgram); return pi::cast(MProgram); } @@ -265,8 +265,8 @@ void program_impl::build_with_kernel_name(std::string KernelName, Module, detail::getSyclObjImpl(get_context()), detail::getSyclObjImpl(get_devices()[0]), KernelName, this, /*JITCompilationIsRequired=*/(!BuildOptions.empty())); - const detail::plugin &Plugin = getPlugin(); - Plugin.call(MProgram); + const PluginPtr &Plugin = getPlugin(); + Plugin->call(MProgram); } MState = program_state::linked; } @@ -290,7 +290,7 @@ void program_impl::link(std::string LinkOptions) { if (!is_host()) { check_device_feature_support(MDevices); std::vector Devices(get_pi_devices()); - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); const char *LinkOpts = SYCLConfig::get(); if (!LinkOpts) { LinkOpts = LinkOptions.c_str(); @@ -300,12 +300,12 @@ void program_impl::link(std::string LinkOptions) { // "piProgramLink". Thus, we need to release MProgram before the call to // piProgramLink. if (MProgram != nullptr) - Plugin.call(MProgram); + Plugin->call(MProgram); - RT::PiResult Err = Plugin.call_nocheck( + RT::PiResult Err = Plugin->call_nocheck( MContext->getHandleRef(), Devices.size(), Devices.data(), LinkOpts, /*num_input_programs*/ 1, &MProgram, nullptr, nullptr, &MProgram); - Plugin.checkPiResult(Err); + Plugin->checkPiResult(Err); MLinkOptions = LinkOptions; MBuildOptions = LinkOptions; } @@ -321,11 +321,11 @@ bool program_impl::has_kernel(std::string KernelName, std::vector Devices(get_pi_devices()); pi_uint64 function_ptr; - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); RT::PiResult Err = PI_SUCCESS; for (RT::PiDevice Device : Devices) { - Err = Plugin.call_nocheck( + Err = Plugin->call_nocheck( Device, MProgram, KernelName.c_str(), &function_ptr); if (Err != PI_SUCCESS && Err != PI_ERROR_FUNCTION_ADDRESS_IS_NOT_AVAILABLE && @@ -363,9 +363,9 @@ std::vector> program_impl::get_binaries() const { return {}; std::vector> Result; - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); std::vector BinarySizes(MDevices.size()); - Plugin.call( + Plugin->call( MProgram, PI_PROGRAM_INFO_BINARY_SIZES, sizeof(size_t) * BinarySizes.size(), BinarySizes.data(), nullptr); @@ -374,9 +374,9 @@ std::vector> program_impl::get_binaries() const { Result.emplace_back(BinarySizes[I]); Pointers.push_back(Result[I].data()); } - Plugin.call(MProgram, PI_PROGRAM_INFO_BINARIES, - sizeof(char *) * Pointers.size(), - Pointers.data(), nullptr); + Plugin->call(MProgram, PI_PROGRAM_INFO_BINARIES, + sizeof(char *) * Pointers.size(), + Pointers.data(), nullptr); return Result; } @@ -384,9 +384,9 @@ void program_impl::create_cl_program_with_source(const std::string &Source) { assert(!MProgram && "This program already has an encapsulated cl_program"); const char *Src = Source.c_str(); size_t Size = Source.size(); - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); RT::PiResult Err = - Plugin.call_nocheck( + Plugin->call_nocheck( MContext->getHandleRef(), 1, &Src, &Size, &MProgram); if (Err == PI_ERROR_INVALID_OPERATION) { @@ -396,19 +396,19 @@ void program_impl::create_cl_program_with_source(const std::string &Source) { } if (Err != PI_SUCCESS) { - Plugin.reportPiError(Err, "create_cl_program_with_source()"); + Plugin->reportPiError(Err, "create_cl_program_with_source()"); } } void program_impl::compile(const std::string &Options) { check_device_feature_support(MDevices); std::vector Devices(get_pi_devices()); - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); const char *CompileOpts = SYCLConfig::get(); if (!CompileOpts) { CompileOpts = Options.c_str(); } - RT::PiResult Err = Plugin.call_nocheck( + RT::PiResult Err = Plugin->call_nocheck( MProgram, Devices.size(), Devices.data(), CompileOpts, 0, nullptr, nullptr, nullptr, nullptr); @@ -425,9 +425,9 @@ void program_impl::compile(const std::string &Options) { void program_impl::build(const std::string &Options) { check_device_feature_support(MDevices); std::vector Devices(get_pi_devices()); - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); ProgramManager::getInstance().flushSpecConstants(*this); - RT::PiResult Err = Plugin.call_nocheck( + RT::PiResult Err = Plugin->call_nocheck( MProgram, Devices.size(), Devices.data(), Options.c_str(), nullptr, nullptr); @@ -457,21 +457,21 @@ program_impl::get_pi_kernel_arg_mask_pair(const std::string &KernelName) const { ProgramManager::getInstance().getOrCreateKernel( MProgramModuleHandle, detail::getSyclObjImpl(get_context()), detail::getSyclObjImpl(get_devices()[0]), KernelName, this); - getPlugin().call(Result.first); + getPlugin()->call(Result.first); } else { - const detail::plugin &Plugin = getPlugin(); - RT::PiResult Err = Plugin.call_nocheck( + const PluginPtr &Plugin = getPlugin(); + RT::PiResult Err = Plugin->call_nocheck( MProgram, KernelName.c_str(), &Result.first); if (Err == PI_ERROR_INVALID_KERNEL_NAME) { throw invalid_object_error( "This instance of program does not contain the kernel requested", Err); } - Plugin.checkPiResult(Err); + Plugin->checkPiResult(Err); // Some PI Plugins (like OpenCL) require this call to enable USM // For others, PI will turn this into a NOP. - Plugin.call( + Plugin->call( Result.first, PI_USM_INDIRECT_ACCESS, sizeof(pi_bool), &PI_TRUE); } @@ -556,7 +556,7 @@ void program_impl::flush_spec_constants(const RTDeviceBinaryImage &Img, auto [Id, Offset, Size] = Descriptors.consume(); - Ctx->getPlugin().call( + Ctx->getPlugin()->call( NativePrg, Id, Size, SC.getValuePtr() + Offset); } } @@ -565,9 +565,9 @@ void program_impl::flush_spec_constants(const RTDeviceBinaryImage &Img, pi_native_handle program_impl::getNative() const { const auto &Plugin = getPlugin(); if (getContextImplPtr()->getBackend() == backend::opencl) - Plugin.call(MProgram); + Plugin->call(MProgram); pi_native_handle Handle; - Plugin.call(MProgram, &Handle); + Plugin->call(MProgram, &Handle); return Handle; } diff --git a/sycl/source/detail/program_impl.hpp b/sycl/source/detail/program_impl.hpp index d2a6abed5524..6b5eb682702b 100644 --- a/sycl/source/detail/program_impl.hpp +++ b/sycl/source/detail/program_impl.hpp @@ -257,7 +257,7 @@ class program_impl { } /// \return the Plugin associated with the context of this program. - const plugin &getPlugin() const { + const PluginPtr &getPlugin() const { assert(!is_host() && "Plugin is not available for Host."); return MContext->getPlugin(); } diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index b97ca34c1900..fe6c48e31982 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -55,10 +55,10 @@ static constexpr char UseSpvEnv[]("SYCL_USE_KERNEL_SPV"); /// This function enables ITT annotations in SPIR-V module by setting /// a specialization constant if INTEL_LIBITTNOTIFY64 env variable is set. static void enableITTAnnotationsIfNeeded(const RT::PiProgram &Prog, - const plugin &Plugin) { + const PluginPtr &Plugin) { if (SYCLConfig::get() != nullptr) { constexpr char SpecValue = 1; - Plugin.call( + Plugin->call( Prog, ITTSpecConstId, sizeof(char), &SpecValue); } } @@ -71,13 +71,13 @@ static RT::PiProgram createBinaryProgram(const ContextImplPtr Context, const device &Device, const unsigned char *Data, size_t DataLen, const std::vector Metadata) { - const detail::plugin &Plugin = Context->getPlugin(); + const PluginPtr &Plugin = Context->getPlugin(); #ifndef _NDEBUG pi_uint32 NumDevices = 0; - Plugin.call(Context->getHandleRef(), - PI_CONTEXT_INFO_NUM_DEVICES, - sizeof(NumDevices), &NumDevices, - /*param_value_size_ret=*/nullptr); + Plugin->call(Context->getHandleRef(), + PI_CONTEXT_INFO_NUM_DEVICES, + sizeof(NumDevices), &NumDevices, + /*param_value_size_ret=*/nullptr); assert(NumDevices > 0 && "Only a single device is supported for AOT compilation"); #endif @@ -85,7 +85,7 @@ createBinaryProgram(const ContextImplPtr Context, const device &Device, RT::PiProgram Program; const RT::PiDevice PiDevice = getSyclObjImpl(Device)->getHandleRef(); pi_int32 BinaryStatus = CL_SUCCESS; - Plugin.call( + Plugin->call( Context->getHandleRef(), 1 /*one binary*/, &PiDevice, &DataLen, &Data, Metadata.size(), Metadata.data(), &BinaryStatus, &Program); @@ -100,9 +100,9 @@ static RT::PiProgram createSpirvProgram(const ContextImplPtr Context, const unsigned char *Data, size_t DataLen) { RT::PiProgram Program = nullptr; - const detail::plugin &Plugin = Context->getPlugin(); - Plugin.call(Context->getHandleRef(), Data, - DataLen, &Program); + const PluginPtr &Plugin = Context->getPlugin(); + Plugin->call(Context->getHandleRef(), Data, + DataLen, &Program); return Program; } @@ -377,7 +377,7 @@ static std::string getUint32PropAsOptStr(const RTDeviceBinaryImage &Img, static void appendCompileOptionsFromImage(std::string &CompileOpts, const RTDeviceBinaryImage &Img, const std::vector &Devs, - const detail::plugin &) { + const PluginPtr &) { // Build options are overridden if environment variables are present. // Environment variables are not changed during program lifecycle so it // is reasonable to use static here to read them only once. @@ -459,7 +459,7 @@ static void applyOptionsFromImage(std::string &CompileOpts, std::string &LinkOpts, const RTDeviceBinaryImage &Img, const std::vector &Devices, - const detail::plugin &Plugin) { + const PluginPtr &Plugin) { appendCompileOptionsFromImage(CompileOpts, Img, Devices, Plugin); appendLinkOptionsFromImage(LinkOpts, Img); } @@ -560,7 +560,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram( } pi_bool MustBuildOnSubdevice = PI_TRUE; - ContextImpl->getPlugin().call( + ContextImpl->getPlugin()->call( RootDevImpl->getHandleRef(), PI_DEVICE_INFO_BUILD_ON_SUBDEVICE, sizeof(pi_bool), &MustBuildOnSubdevice, nullptr); @@ -617,7 +617,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram( auto BuildF = [this, &Img, &Context, &ContextImpl, &Device, Prg, &CompileOpts, &LinkOpts, SpecConsts] { - const detail::plugin &Plugin = ContextImpl->getPlugin(); + const PluginPtr &Plugin = ContextImpl->getPlugin(); applyOptionsFromImage(CompileOpts, LinkOpts, Img, {Device}, Plugin); auto [NativePrg, DeviceCodeWasInCache] = getOrCreatePIProgram( @@ -631,7 +631,7 @@ RT::PiProgram ProgramManager::getBuiltPIProgram( } ProgramPtr ProgramManaged( - NativePrg, Plugin.getPiPlugin().PiFunctionTable.piProgramRelease); + NativePrg, Plugin->getPiPlugin().PiFunctionTable.piProgramRelease); // Link a fallback implementation of device libraries if they are not // supported by a device compiler. @@ -719,14 +719,14 @@ ProgramManager::getOrCreateKernel(OSModuleHandle M, auto BuildF = [this, &Program, &KernelName, &ContextImpl, M] { RT::PiKernel Kernel = nullptr; - const detail::plugin &Plugin = ContextImpl->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = ContextImpl->getPlugin(); + Plugin->call( Program, KernelName.c_str(), &Kernel); // Some PI Plugins (like OpenCL) require this call to enable USM // For others, PI will turn this into a NOP. - Plugin.call(Kernel, PI_USM_INDIRECT_ACCESS, - sizeof(pi_bool), &PI_TRUE); + Plugin->call(Kernel, PI_USM_INDIRECT_ACCESS, + sizeof(pi_bool), &PI_TRUE); const KernelArgMask *ArgMask = getEliminatedKernelArgMask(M, Program, KernelName); @@ -753,8 +753,8 @@ RT::PiProgram ProgramManager::getPiProgramFromPiKernel(RT::PiKernel Kernel, const ContextImplPtr Context) { RT::PiProgram Program; - const detail::plugin &Plugin = Context->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Context->getPlugin(); + Plugin->call( Kernel, PI_KERNEL_INFO_PROGRAM, sizeof(RT::PiProgram), &Program, nullptr); return Program; } @@ -762,24 +762,24 @@ ProgramManager::getPiProgramFromPiKernel(RT::PiKernel Kernel, std::string ProgramManager::getProgramBuildLog(const RT::PiProgram &Program, const ContextImplPtr Context) { size_t PIDevicesSize = 0; - const detail::plugin &Plugin = Context->getPlugin(); - Plugin.call(Program, PI_PROGRAM_INFO_DEVICES, 0, - nullptr, &PIDevicesSize); + const PluginPtr &Plugin = Context->getPlugin(); + Plugin->call(Program, PI_PROGRAM_INFO_DEVICES, 0, + nullptr, &PIDevicesSize); std::vector PIDevices(PIDevicesSize / sizeof(RT::PiDevice)); - Plugin.call(Program, PI_PROGRAM_INFO_DEVICES, - PIDevicesSize, PIDevices.data(), - nullptr); + Plugin->call(Program, PI_PROGRAM_INFO_DEVICES, + PIDevicesSize, PIDevices.data(), + nullptr); std::string Log = "The program was built for " + std::to_string(PIDevices.size()) + " devices"; for (RT::PiDevice &Device : PIDevices) { std::string DeviceBuildInfoString; size_t DeviceBuildInfoStrSize = 0; - Plugin.call( + Plugin->call( Program, Device, PI_PROGRAM_BUILD_INFO_LOG, 0, nullptr, &DeviceBuildInfoStrSize); if (DeviceBuildInfoStrSize > 0) { std::vector DeviceBuildInfo(DeviceBuildInfoStrSize); - Plugin.call( + Plugin->call( Program, Device, PI_PROGRAM_BUILD_INFO_LOG, DeviceBuildInfoStrSize, DeviceBuildInfo.data(), nullptr); DeviceBuildInfoString = std::string(DeviceBuildInfo.data()); @@ -787,13 +787,13 @@ std::string ProgramManager::getProgramBuildLog(const RT::PiProgram &Program, std::string DeviceNameString; size_t DeviceNameStrSize = 0; - Plugin.call(Device, PI_DEVICE_INFO_NAME, 0, - nullptr, &DeviceNameStrSize); + Plugin->call(Device, PI_DEVICE_INFO_NAME, 0, + nullptr, &DeviceNameStrSize); if (DeviceNameStrSize > 0) { std::vector DeviceName(DeviceNameStrSize); - Plugin.call(Device, PI_DEVICE_INFO_NAME, - DeviceNameStrSize, - DeviceName.data(), nullptr); + Plugin->call(Device, PI_DEVICE_INFO_NAME, + DeviceNameStrSize, + DeviceName.data(), nullptr); DeviceNameString = std::string(DeviceName.data()); } Log += "\nBuild program log for '" + DeviceNameString + "':\n" + @@ -912,9 +912,9 @@ static RT::PiProgram loadDeviceLibFallback(const ContextImplPtr Context, PI_ERROR_INVALID_VALUE); } - const detail::plugin &Plugin = Context->getPlugin(); + const PluginPtr &Plugin = Context->getPlugin(); // TODO no spec constants are used in the std libraries, support in the future - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( LibProg, /*num devices = */ 1, &Device, // Do not use compile options for library programs: it is not clear @@ -1003,7 +1003,7 @@ ProgramManager::getDeviceImage(OSModuleHandle M, KernelSetId KSId, for (unsigned I = 0; I < Imgs.size(); I++) RawImgs[I] = const_cast(&Imgs[I]->getRawData()); - Ctx->getPlugin().call( + Ctx->getPlugin()->call( getSyclObjImpl(Device)->getHandleRef(), RawImgs.data(), (pi_uint32)RawImgs.size(), &ImgInd); @@ -1144,12 +1144,12 @@ ProgramManager::build(ProgramPtr Program, const ContextImplPtr Context, static const char *ForceLinkEnv = std::getenv("SYCL_FORCE_LINK"); static bool ForceLink = ForceLinkEnv && (*ForceLinkEnv == '1'); - const detail::plugin &Plugin = Context->getPlugin(); + const PluginPtr &Plugin = Context->getPlugin(); if (LinkPrograms.empty() && !ForceLink) { const std::string &Options = LinkOptions.empty() ? CompileOptions : (CompileOptions + " " + LinkOptions); - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( Program.get(), /*num devices =*/1, &Device, Options.c_str(), nullptr, nullptr); if (Error != PI_SUCCESS) @@ -1159,13 +1159,13 @@ ProgramManager::build(ProgramPtr Program, const ContextImplPtr Context, } // Include the main program and compile/link everything together - Plugin.call(Program.get(), /*num devices =*/1, - &Device, CompileOptions.c_str(), 0, - nullptr, nullptr, nullptr, nullptr); + Plugin->call(Program.get(), /*num devices =*/1, + &Device, CompileOptions.c_str(), 0, + nullptr, nullptr, nullptr, nullptr); LinkPrograms.push_back(Program.get()); RT::PiProgram LinkedProg = nullptr; - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( Context->getHandleRef(), /*num devices =*/1, &Device, LinkOptions.c_str(), LinkPrograms.size(), LinkPrograms.data(), nullptr, nullptr, &LinkedProg); @@ -1179,7 +1179,7 @@ ProgramManager::build(ProgramPtr Program, const ContextImplPtr Context, throw compile_program_error(getProgramBuildLog(LinkedProg, Context), Error); } - Plugin.checkPiResult(Error); + Plugin->checkPiResult(Error); } return Program; } @@ -1601,7 +1601,7 @@ static bool compatibleWithDevice(RTDeviceBinaryImage *BinImage, pi_uint32 SuitableImageID = std::numeric_limits::max(); pi_device_binary DevBin = const_cast(&BinImage->getRawData()); - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( PIDeviceHandle, &DevBin, /*num bin images = */ (pi_uint32)1, &SuitableImageID); if (Error != PI_SUCCESS && Error != PI_ERROR_INVALID_BINARY) @@ -2019,7 +2019,7 @@ std::vector ProgramManager::getSYCLDeviceImages( static void setSpecializationConstants(const std::shared_ptr &InputImpl, - RT::PiProgram Prog, const plugin &Plugin) { + RT::PiProgram Prog, const PluginPtr &Plugin) { // Set ITT annotation specialization constant if needed. enableITTAnnotationsIfNeeded(Prog, Plugin); @@ -2033,7 +2033,7 @@ setSpecializationConstants(const std::shared_ptr &InputImpl, std::ignore = SpecConstNames; for (const device_image_impl::SpecConstDescT &SpecIDDesc : SpecConstDescs) { if (SpecIDDesc.IsSet) { - Plugin.call( + Plugin->call( Prog, SpecIDDesc.ID, SpecIDDesc.Size, SpecConsts.data() + SpecIDDesc.BlobOffset); } @@ -2053,7 +2053,7 @@ ProgramManager::compile(const device_image_plain &DeviceImage, const std::shared_ptr &InputImpl = getSyclObjImpl(DeviceImage); - const detail::plugin &Plugin = + const PluginPtr &Plugin = getSyclObjImpl(InputImpl->get_context())->getPlugin(); // TODO: Add support for creating non-SPIRV programs from multiple devices. @@ -2089,7 +2089,7 @@ ProgramManager::compile(const device_image_plain &DeviceImage, applyCompileOptionsFromEnvironment(CompileOptions); appendCompileOptionsFromImage( CompileOptions, *(InputImpl->get_bin_image_ref()), Devs, Plugin); - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( ObjectImpl->get_program_ref(), /*num devices=*/Devs.size(), PIDevices.data(), CompileOptions.c_str(), /*num_input_headers=*/0, /*input_headers=*/nullptr, @@ -2128,10 +2128,10 @@ ProgramManager::link(const device_image_plain &DeviceImage, } const context &Context = getSyclObjImpl(DeviceImage)->get_context(); const ContextImplPtr ContextImpl = getSyclObjImpl(Context); - const detail::plugin &Plugin = ContextImpl->getPlugin(); + const PluginPtr &Plugin = ContextImpl->getPlugin(); RT::PiProgram LinkedProg = nullptr; - RT::PiResult Error = Plugin.call_nocheck( + RT::PiResult Error = Plugin->call_nocheck( ContextImpl->getHandleRef(), PIDevices.size(), PIDevices.data(), /*options=*/LinkOptionsStr.c_str(), PIPrograms.size(), PIPrograms.data(), /*pfn_notify=*/nullptr, @@ -2142,7 +2142,7 @@ ProgramManager::link(const device_image_plain &DeviceImage, const std::string ErrorMsg = getProgramBuildLog(LinkedProg, ContextImpl); throw sycl::exception(make_error_code(errc::build), ErrorMsg); } - Plugin.reportPiError(Error, "link()"); + Plugin->reportPiError(Error, "link()"); } std::shared_ptr> KernelIDs{new std::vector}; @@ -2232,7 +2232,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, auto BuildF = [this, &Context, &Img, &Devs, &CompileOpts, &LinkOpts, &InputImpl, SpecConsts] { ContextImplPtr ContextImpl = getSyclObjImpl(Context); - const detail::plugin &Plugin = ContextImpl->getPlugin(); + const PluginPtr &Plugin = ContextImpl->getPlugin(); applyOptionsFromImage(CompileOpts, LinkOpts, Img, Devs, Plugin); // TODO: Add support for creating non-SPIRV programs from multiple devices. @@ -2254,7 +2254,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, setSpecializationConstants(InputImpl, NativePrg, Plugin); ProgramPtr ProgramManaged( - NativePrg, Plugin.getPiPlugin().PiFunctionTable.piProgramRelease); + NativePrg, Plugin->getPiPlugin().PiFunctionTable.piProgramRelease); // Link a fallback implementation of device libraries if they are not // supported by a device compiler. @@ -2310,9 +2310,9 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, // Cache supports key with once device only, but here we have multiple // devices a program is built for, so add the program to the cache for all // other devices. - const detail::plugin &Plugin = ContextImpl->getPlugin(); + const PluginPtr &Plugin = ContextImpl->getPlugin(); auto CacheOtherDevices = [ResProgram, &Plugin]() { - Plugin.call(ResProgram); + Plugin->call(ResProgram); return ResProgram; }; @@ -2333,7 +2333,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, // devive_image_impl shares ownership of PIProgram with, at least, program // cache. The ref counter will be descremented in the destructor of // device_image_impl - Plugin.call(ResProgram); + Plugin->call(ResProgram); DeviceImageImplPtr ExecImpl = std::make_shared( InputImpl->get_bin_image_ref(), Context, Devs, bundle_state::executable, @@ -2359,12 +2359,12 @@ ProgramManager::getOrCreateKernel(const context &Context, auto BuildF = [this, &Program, &KernelName, &Ctx] { RT::PiKernel Kernel = nullptr; - const detail::plugin &Plugin = Ctx->getPlugin(); - Plugin.call(Program, KernelName.c_str(), - &Kernel); + const PluginPtr &Plugin = Ctx->getPlugin(); + Plugin->call(Program, KernelName.c_str(), + &Kernel); - Plugin.call(Kernel, PI_USM_INDIRECT_ACCESS, - sizeof(pi_bool), &PI_TRUE); + Plugin->call(Kernel, PI_USM_INDIRECT_ACCESS, + sizeof(pi_bool), &PI_TRUE); const KernelArgMask *KernelArgMask = getEliminatedKernelArgMask(Program, KernelName); diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 886a9ec17c88..9c6d71bb3314 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -30,7 +30,7 @@ template <> uint32_t queue_impl::get_info() const { RT::PiResult result = PI_SUCCESS; if (!is_host()) - getPlugin().call( + getPlugin()->call( MQueues[0], PI_QUEUE_INFO_REFERENCE_COUNT, sizeof(result), &result, nullptr); return result; @@ -495,8 +495,8 @@ void queue_impl::wait(const detail::code_location &CodeLoc) { } } if (SupportsPiFinish) { - const detail::plugin &Plugin = getPlugin(); - Plugin.call(getHandleRef()); + const PluginPtr &Plugin = getPlugin(); + Plugin->call(getHandleRef()); assert(SharedEvents.empty() && "Queues that support calling piQueueFinish " "shouldn't have shared events"); } else { @@ -518,21 +518,21 @@ void queue_impl::wait(const detail::code_location &CodeLoc) { } pi_native_handle queue_impl::getNative() const { - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); if (getContextImplPtr()->getBackend() == backend::opencl) - Plugin.call(MQueues[0]); + Plugin->call(MQueues[0]); pi_native_handle Handle{}; - Plugin.call(MQueues[0], &Handle); + Plugin->call(MQueues[0], &Handle); return Handle; } pi_native_handle queue_impl::getNative2(int32_t &NativeHandleDesc) const { - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); if (getContextImplPtr()->getBackend() == backend::opencl) - Plugin.call(MQueues[0]); + Plugin->call(MQueues[0]); pi_native_handle Handle{}; - Plugin.call(MQueues[0], &Handle, - &NativeHandleDesc); + Plugin->call(MQueues[0], &Handle, + &NativeHandleDesc); return Handle; } @@ -548,7 +548,7 @@ bool queue_impl::ext_oneapi_empty() const { // Check the status of the backend queue if this is not a host queue. if (!is_host()) { pi_bool IsReady = false; - getPlugin().call( + getPlugin()->call( MQueues[0], PI_EXT_ONEAPI_QUEUE_INFO_EMPTY, sizeof(pi_bool), &IsReady, nullptr); if (!IsReady) diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index cdaf91e4bd83..f497b3fd8432 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -230,9 +230,9 @@ class queue_impl { MQueues.push_back(pi::cast(PiQueue)); RT::PiDevice DevicePI{}; - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); // TODO catch an exception and put it to list of asynchronous exceptions - Plugin.call( + Plugin->call( MQueues[0], PI_QUEUE_INFO_DEVICE, sizeof(DevicePI), &DevicePI, nullptr); MDevice = MContext->findMatchingDeviceImpl(DevicePI); if (MDevice == nullptr) { @@ -297,7 +297,7 @@ class queue_impl { #endif throw_asynchronous(); if (!MHostQueue) { - getPlugin().call(MQueues[0]); + getPlugin()->call(MQueues[0]); } } @@ -308,7 +308,7 @@ class queue_impl { "This instance of queue doesn't support OpenCL interoperability", PI_ERROR_INVALID_QUEUE); } - getPlugin().call(MQueues[0]); + getPlugin()->call(MQueues[0]); return pi::cast(MQueues[0]); } @@ -317,7 +317,7 @@ class queue_impl { return createSyclObjFromImpl(MContext); } - const plugin &getPlugin() const { return MContext->getPlugin(); } + const PluginPtr &getPlugin() const { return MContext->getPlugin(); } const ContextImplPtr &getContextImplPtr() const { return MContext; } @@ -480,7 +480,7 @@ class queue_impl { RT::PiQueue Queue{}; RT::PiContext Context = MContext->getHandleRef(); RT::PiDevice Device = MDevice->getHandleRef(); - const detail::plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); RT::PiQueueProperties Properties[] = { PI_QUEUE_FLAGS, createPiQueueProperties(MPropList, Order), 0, 0, 0}; @@ -491,9 +491,9 @@ class queue_impl { Properties[3] = static_cast(Idx); } RT::PiResult Error = - MBackend_L0_V3 ? Plugin.call_nocheck( + MBackend_L0_V3 ? Plugin->call_nocheck( Context, Device, Properties, &Queue) - : Plugin.call_nocheck( + : Plugin->call_nocheck( Context, Device, Properties, &Queue); // If creating out-of-order queue failed and this property is not @@ -503,7 +503,7 @@ class queue_impl { MEmulateOOO = true; Queue = createQueue(QueueOrder::Ordered); } else { - Plugin.checkPiResult(Error); + Plugin->checkPiResult(Error); } return Queue; @@ -535,7 +535,7 @@ class queue_impl { if (!ReuseQueue) *PIQ = createQueue(QueueOrder::Ordered); else - getPlugin().call(*PIQ); + getPlugin()->call(*PIQ); return *PIQ; } diff --git a/sycl/source/detail/sampler_impl.cpp b/sycl/source/detail/sampler_impl.cpp index c17d5be0ddf6..6dea3e2d5b5d 100644 --- a/sycl/source/detail/sampler_impl.cpp +++ b/sycl/source/detail/sampler_impl.cpp @@ -25,25 +25,25 @@ sampler_impl::sampler_impl(cl_sampler clSampler, const context &syclContext) { RT::PiSampler Sampler = pi::cast(clSampler); MContextToSampler[syclContext] = Sampler; - const detail::plugin &Plugin = getSyclObjImpl(syclContext)->getPlugin(); - Plugin.call(Sampler); - Plugin.call( + const PluginPtr &Plugin = getSyclObjImpl(syclContext)->getPlugin(); + Plugin->call(Sampler); + Plugin->call( Sampler, PI_SAMPLER_INFO_NORMALIZED_COORDS, sizeof(pi_bool), &MCoordNormMode, nullptr); - Plugin.call( + Plugin->call( Sampler, PI_SAMPLER_INFO_ADDRESSING_MODE, sizeof(pi_sampler_addressing_mode), &MAddrMode, nullptr); - Plugin.call(Sampler, PI_SAMPLER_INFO_FILTER_MODE, - sizeof(pi_sampler_filter_mode), - &MFiltMode, nullptr); + Plugin->call( + Sampler, PI_SAMPLER_INFO_FILTER_MODE, sizeof(pi_sampler_filter_mode), + &MFiltMode, nullptr); } sampler_impl::~sampler_impl() { std::lock_guard Lock(MMutex); for (auto &Iter : MContextToSampler) { // TODO catch an exception and add it to the list of asynchronous exceptions - const detail::plugin &Plugin = getSyclObjImpl(Iter.first)->getPlugin(); - Plugin.call(Iter.second); + const PluginPtr &Plugin = getSyclObjImpl(Iter.first)->getPlugin(); + Plugin->call(Iter.second); } } @@ -66,16 +66,16 @@ RT::PiSampler sampler_impl::getOrCreateSampler(const context &Context) { RT::PiResult errcode_ret = PI_SUCCESS; RT::PiSampler resultSampler = nullptr; - const detail::plugin &Plugin = getSyclObjImpl(Context)->getPlugin(); + const PluginPtr &Plugin = getSyclObjImpl(Context)->getPlugin(); - errcode_ret = Plugin.call_nocheck( + errcode_ret = Plugin->call_nocheck( getSyclObjImpl(Context)->getHandleRef(), sprops, &resultSampler); if (errcode_ret == PI_ERROR_INVALID_OPERATION) throw feature_not_supported("Images are not supported by this device.", errcode_ret); - Plugin.checkPiResult(errcode_ret); + Plugin->checkPiResult(errcode_ret); std::lock_guard Lock(MMutex); MContextToSampler[Context] = resultSampler; diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index a0add11f4288..cd7f1a6bd3d5 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -298,12 +298,12 @@ class DispatchHostTask { std::vector MReqToMem; pi_result waitForEvents() const { - std::map> + std::map> RequiredEventsPerPlugin; for (const EventImplPtr &Event : MThisCmd->MPreparedDepsEvents) { - const detail::plugin &Plugin = Event->getPlugin(); - RequiredEventsPerPlugin[&Plugin].push_back(Event); + const PluginPtr &Plugin = Event->getPlugin(); + RequiredEventsPerPlugin[Plugin].push_back(Event); } // wait for dependency device events @@ -458,7 +458,7 @@ void Command::waitForEvents(QueueImplPtr Queue, for (auto &CtxWithEvents : RequiredEventsPerContext) { std::vector RawEvents = getPiEvents(CtxWithEvents.second); - CtxWithEvents.first->getPlugin().call( + CtxWithEvents.first->getPlugin()->call( RawEvents.size(), RawEvents.data()); } } else { @@ -470,8 +470,8 @@ void Command::waitForEvents(QueueImplPtr Queue, std::vector RawEvents = getPiEvents(EventImpls); flushCrossQueueDeps(EventImpls, getWorkerQueue()); - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Queue->getHandleRef(), RawEvents.size(), &RawEvents[0], &Event); } } @@ -2093,7 +2093,7 @@ static pi_result SetKernelParamsAndLaunch( RT::PiKernel Kernel, NDRDescT &NDRDesc, std::vector &RawEvents, RT::PiEvent *OutEvent, const KernelArgMask *EliminatedArgMask, const std::function &getMemAllocationFunc) { - const detail::plugin &Plugin = Queue->getPlugin(); + const PluginPtr &Plugin = Queue->getPlugin(); auto setFunc = [&Plugin, Kernel, &DeviceImageImpl, &getMemAllocationFunc, &Queue](detail::ArgDesc &Arg, size_t NextTrueIndex) { @@ -2109,30 +2109,30 @@ static pi_result SetKernelParamsAndLaunch( RT::PiMem MemArg = (RT::PiMem)getMemAllocationFunc(Req); if (Queue->getDeviceImplPtr()->getBackend() == backend::opencl) { - Plugin.call(Kernel, NextTrueIndex, - sizeof(RT::PiMem), &MemArg); + Plugin->call(Kernel, NextTrueIndex, + sizeof(RT::PiMem), &MemArg); } else { - Plugin.call(Kernel, NextTrueIndex, - &MemArg); + Plugin->call(Kernel, NextTrueIndex, + &MemArg); } break; } case kernel_param_kind_t::kind_std_layout: { - Plugin.call(Kernel, NextTrueIndex, Arg.MSize, - Arg.MPtr); + Plugin->call(Kernel, NextTrueIndex, Arg.MSize, + Arg.MPtr); break; } case kernel_param_kind_t::kind_sampler: { sampler *SamplerPtr = (sampler *)Arg.MPtr; RT::PiSampler Sampler = detail::getSyclObjImpl(*SamplerPtr) ->getOrCreateSampler(Queue->get_context()); - Plugin.call(Kernel, NextTrueIndex, - &Sampler); + Plugin->call(Kernel, NextTrueIndex, + &Sampler); break; } case kernel_param_kind_t::kind_pointer: { - Plugin.call(Kernel, NextTrueIndex, - Arg.MSize, Arg.MPtr); + Plugin->call(Kernel, NextTrueIndex, + Arg.MSize, Arg.MPtr); break; } case kernel_param_kind_t::kind_specialization_constants_buffer: { @@ -2147,8 +2147,8 @@ static pi_result SetKernelParamsAndLaunch( // Avoid taking an address of nullptr RT::PiMem *SpecConstsBufferArg = SpecConstsBuffer ? &SpecConstsBuffer : nullptr; - Plugin.call(Kernel, NextTrueIndex, - SpecConstsBufferArg); + Plugin->call(Kernel, NextTrueIndex, + SpecConstsBufferArg); break; } case kernel_param_kind_t::kind_invalid: @@ -2172,7 +2172,7 @@ static pi_result SetKernelParamsAndLaunch( if (HasLocalSize) LocalSize = &NDRDesc.LocalSize[0]; else { - Plugin.call( + Plugin->call( Kernel, Queue->getDeviceImplPtr()->getHandleRef(), PI_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE, sizeof(RequiredWGSize), RequiredWGSize, /* param_value_size_ret = */ nullptr); @@ -2184,7 +2184,7 @@ static pi_result SetKernelParamsAndLaunch( LocalSize = RequiredWGSize; } - pi_result Error = Plugin.call_nocheck( + pi_result Error = Plugin->call_nocheck( Queue->getHandleRef(), Kernel, NDRDesc.Dims, &NDRDesc.GlobalOffset[0], &NDRDesc.GlobalSize[0], LocalSize, RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], OutEvent); @@ -2316,8 +2316,8 @@ pi_int32 enqueueImpKernel( // provided. if (KernelCacheConfig == PI_EXT_KERNEL_EXEC_INFO_CACHE_LARGE_SLM || KernelCacheConfig == PI_EXT_KERNEL_EXEC_INFO_CACHE_LARGE_DATA) { - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = Queue->getPlugin(); + Plugin->call( Kernel, PI_EXT_KERNEL_EXEC_INFO_CACHE_CONFIG, sizeof(RT::PiKernelCacheConfig), &KernelCacheConfig); } @@ -2365,22 +2365,23 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, assert(Program && "Program for this hostpipe is not compiled."); // Get plugin for calling opencl functions - const detail::plugin &Plugin = Queue->getPlugin(); + const PluginPtr &Plugin = Queue->getPlugin(); pi_queue pi_q = Queue->getHandleRef(); pi_result Error; if (read) { Error = - Plugin.call_nocheck( + Plugin->call_nocheck( pi_q, Program, PipeName.c_str(), blocking, ptr, size, RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], OutEvent); } else { Error = - Plugin.call_nocheck( - pi_q, Program, PipeName.c_str(), blocking, ptr, size, - RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], - OutEvent); + Plugin + ->call_nocheck( + pi_q, Program, PipeName.c_str(), blocking, ptr, size, + RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], + OutEvent); } return Error; } @@ -2504,8 +2505,8 @@ pi_int32 ExecCGCommand::enqueueImp() { if (!RawEvents.empty()) { // Assuming that the events are for devices to the same Plugin. - const detail::plugin &Plugin = EventImpls[0]->getPlugin(); - Plugin.call(RawEvents.size(), &RawEvents[0]); + const PluginPtr &Plugin = EventImpls[0]->getPlugin(); + Plugin->call(RawEvents.size(), &RawEvents[0]); } DispatchNativeKernel((void *)ArgsBlob.data()); @@ -2529,8 +2530,8 @@ pi_int32 ExecCGCommand::enqueueImp() { MemLocs.push_back(NextArg); NextArg++; } - const detail::plugin &Plugin = MQueue->getPlugin(); - pi_result Error = Plugin.call_nocheck( + const PluginPtr &Plugin = MQueue->getPlugin(); + pi_result Error = Plugin->call_nocheck( MQueue->getHandleRef(), DispatchNativeKernel, (void *)ArgsBlob.data(), ArgsBlob.size() * sizeof(ArgsBlob[0]), Buffers.size(), Buffers.data(), const_cast(MemLocs.data()), RawEvents.size(), @@ -2563,8 +2564,8 @@ pi_int32 ExecCGCommand::enqueueImp() { } if (!RawEvents.empty()) { // Assuming that the events are for devices to the same Plugin. - const detail::plugin &Plugin = EventImpls[0]->getPlugin(); - Plugin.call(RawEvents.size(), &RawEvents[0]); + const PluginPtr &Plugin = EventImpls[0]->getPlugin(); + Plugin->call(RawEvents.size(), &RawEvents[0]); } if (MQueue->is_host()) { @@ -2574,7 +2575,7 @@ pi_int32 ExecCGCommand::enqueueImp() { assert(MQueue->getDeviceImplPtr()->getBackend() == backend::ext_intel_esimd_emulator); - MQueue->getPlugin().call( + MQueue->getPlugin()->call( nullptr, reinterpret_cast(ExecKernel->MHostKernel->getPtr()), NDRDesc.Dims, &NDRDesc.GlobalOffset[0], &NDRDesc.GlobalSize[0], @@ -2661,14 +2662,14 @@ pi_int32 ExecCGCommand::enqueueImp() { return PI_SUCCESS; } case CG::CGTYPE::CodeplayInteropTask: { - const detail::plugin &Plugin = MQueue->getPlugin(); + const PluginPtr &Plugin = MQueue->getPlugin(); CGInteropTask *ExecInterop = (CGInteropTask *)MCommandGroup.get(); // Wait for dependencies to complete before dispatching work on the host // TODO: Use a callback to dispatch the interop task instead of waiting // for // the event if (!RawEvents.empty()) { - Plugin.call(RawEvents.size(), &RawEvents[0]); + Plugin->call(RawEvents.size(), &RawEvents[0]); } std::vector ReqMemObjs; // Extract the Mem Objects for all Requirements, to ensure they are @@ -2685,8 +2686,8 @@ pi_int32 ExecCGCommand::enqueueImp() { std::sort(std::begin(ReqMemObjs), std::end(ReqMemObjs)); interop_handler InteropHandler(std::move(ReqMemObjs), MQueue); ExecInterop->MInteropTask->call(InteropHandler); - Plugin.call(MQueue->getHandleRef(), 0, - nullptr, Event); + Plugin->call(MQueue->getHandleRef(), 0, + nullptr, Event); return PI_SUCCESS; } @@ -2754,8 +2755,8 @@ pi_int32 ExecCGCommand::enqueueImp() { // NOP for host device. return PI_SUCCESS; } - const detail::plugin &Plugin = MQueue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = MQueue->getPlugin(); + Plugin->call( MQueue->getHandleRef(), 0, nullptr, Event); return PI_SUCCESS; @@ -2769,8 +2770,8 @@ pi_int32 ExecCGCommand::enqueueImp() { // If Events is empty, then the barrier has no effect. return PI_SUCCESS; } - const detail::plugin &Plugin = MQueue->getPlugin(); - Plugin.call( + const PluginPtr &Plugin = MQueue->getPlugin(); + Plugin->call( MQueue->getHandleRef(), PiEvents.size(), &PiEvents[0], Event); return PI_SUCCESS; diff --git a/sycl/source/detail/sycl_mem_obj_t.cpp b/sycl/source/detail/sycl_mem_obj_t.cpp index cdcd3a05af99..7ea7f852b24c 100644 --- a/sycl/source/detail/sycl_mem_obj_t.cpp +++ b/sycl/source/detail/sycl_mem_obj_t.cpp @@ -39,18 +39,18 @@ SYCLMemObjT::SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext, PI_ERROR_INVALID_CONTEXT); RT::PiContext Context = nullptr; - const plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); - Plugin.call( + Plugin->call( MemObject, MInteropContext->getHandleRef(), OwnNativeHandle, &MInteropMemObject); // Get the size of the buffer in bytes - Plugin.call( + Plugin->call( MInteropMemObject, PI_MEM_SIZE, sizeof(size_t), &MSizeInBytes, nullptr); - Plugin.call(MInteropMemObject, PI_MEM_CONTEXT, - sizeof(Context), &Context, nullptr); + Plugin->call(MInteropMemObject, PI_MEM_CONTEXT, + sizeof(Context), &Context, nullptr); if (MInteropContext->getHandleRef() != Context) throw sycl::invalid_parameter_error( @@ -58,7 +58,7 @@ SYCLMemObjT::SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext, PI_ERROR_INVALID_CONTEXT); if (MInteropContext->getBackend() == backend::opencl) - Plugin.call(MInteropMemObject); + Plugin->call(MInteropMemObject); } RT::PiMemObjectType getImageType(int Dimensions) { @@ -89,7 +89,7 @@ SYCLMemObjT::SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext, PI_ERROR_INVALID_CONTEXT); RT::PiContext Context = nullptr; - const plugin &Plugin = getPlugin(); + const PluginPtr &Plugin = getPlugin(); RT::PiMemImageFormat Format{Order, Type}; RT::PiMemImageDesc Desc; @@ -104,12 +104,12 @@ SYCLMemObjT::SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext, Desc.num_samples = 0; Desc.buffer = nullptr; - Plugin.call( + Plugin->call( MemObject, MInteropContext->getHandleRef(), OwnNativeHandle, &Format, &Desc, &MInteropMemObject); - Plugin.call(MInteropMemObject, PI_MEM_CONTEXT, - sizeof(Context), &Context, nullptr); + Plugin->call(MInteropMemObject, PI_MEM_CONTEXT, + sizeof(Context), &Context, nullptr); if (MInteropContext->getHandleRef() != Context) throw sycl::invalid_parameter_error( @@ -117,7 +117,7 @@ SYCLMemObjT::SYCLMemObjT(pi_native_handle MemObject, const context &SyclContext, PI_ERROR_INVALID_CONTEXT); if (MInteropContext->getBackend() == backend::opencl) - Plugin.call(MInteropMemObject); + Plugin->call(MInteropMemObject); } void SYCLMemObjT::releaseMem(ContextImplPtr Context, void *MemAllocation) { @@ -159,12 +159,12 @@ void SYCLMemObjT::updateHostMemory() { releaseHostMem(MShadowCopy); if (MOpenCLInterop) { - const plugin &Plugin = getPlugin(); - Plugin.call( + const PluginPtr &Plugin = getPlugin(); + Plugin->call( pi::cast(MInteropMemObject)); } } -const plugin &SYCLMemObjT::getPlugin() const { +const PluginPtr &SYCLMemObjT::getPlugin() const { assert((MInteropContext != nullptr) && "Trying to get Plugin from SYCLMemObjT with nullptr ContextImpl."); return (MInteropContext->getPlugin()); @@ -173,9 +173,9 @@ const plugin &SYCLMemObjT::getPlugin() const { size_t SYCLMemObjT::getBufSizeForContext(const ContextImplPtr &Context, pi_native_handle MemObject) { size_t BufSize = 0; - const detail::plugin &Plugin = Context->getPlugin(); + const PluginPtr &Plugin = Context->getPlugin(); // TODO is there something required to support non-OpenCL backends? - Plugin.call( + Plugin->call( detail::pi::cast(MemObject), PI_MEM_SIZE, sizeof(size_t), &BufSize, nullptr); return BufSize; diff --git a/sycl/source/detail/sycl_mem_obj_t.hpp b/sycl/source/detail/sycl_mem_obj_t.hpp index 438b968d5d26..40898e89563e 100644 --- a/sycl/source/detail/sycl_mem_obj_t.hpp +++ b/sycl/source/detail/sycl_mem_obj_t.hpp @@ -87,7 +87,7 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI { virtual ~SYCLMemObjT() = default; - const plugin &getPlugin() const; + const PluginPtr &getPlugin() const; size_t getSizeInBytes() const noexcept override { return MSizeInBytes; } __SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead") diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 6c305d5aa71b..a06a79da63e6 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -78,7 +78,7 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, } } else { pi_context C = CtxImpl->getHandleRef(); - const detail::plugin &Plugin = CtxImpl->getPlugin(); + const PluginPtr &Plugin = CtxImpl->getPlugin(); pi_result Error; switch (Kind) { @@ -100,7 +100,7 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, assert(PropsIter >= Props.begin() && PropsIter < Props.end()); *PropsIter++ = 0; // null-terminate property list - Error = Plugin.call_nocheck( + Error = Plugin->call_nocheck( &RetVal, C, Props.data(), Size, Alignment); break; @@ -149,7 +149,7 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, } } else { pi_context C = CtxImpl->getHandleRef(); - const detail::plugin &Plugin = CtxImpl->getPlugin(); + const PluginPtr &Plugin = CtxImpl->getPlugin(); pi_result Error; pi_device Id; @@ -174,7 +174,7 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, assert(PropsIter >= Props.begin() && PropsIter < Props.end()); *PropsIter++ = 0; // null-terminate property list - Error = Plugin.call_nocheck( + Error = Plugin->call_nocheck( &RetVal, C, Id, Props.data(), Size, Alignment); break; @@ -204,7 +204,7 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, assert(PropsIter >= Props.begin() && PropsIter < Props.end()); *PropsIter++ = 0; // null-terminate property list - Error = Plugin.call_nocheck( + Error = Plugin->call_nocheck( &RetVal, C, Id, Props.data(), Size, Alignment); break; @@ -259,8 +259,8 @@ void freeInternal(void *Ptr, const context_impl *CtxImpl) { detail::OSUtil::alignedFree(Ptr); } else { pi_context C = CtxImpl->getHandleRef(); - const detail::plugin &Plugin = CtxImpl->getPlugin(); - Plugin.call(C, Ptr); + const PluginPtr &Plugin = CtxImpl->getPlugin(); + Plugin->call(C, Ptr); } } @@ -578,9 +578,9 @@ alloc get_pointer_type(const void *Ptr, const context &Ctxt) { pi_usm_type AllocTy; // query type using PI function - const detail::plugin &Plugin = CtxImpl->getPlugin(); + const detail::PluginPtr &Plugin = CtxImpl->getPlugin(); RT::PiResult Err = - Plugin.call_nocheck( + Plugin->call_nocheck( PICtx, Ptr, PI_MEM_ALLOC_TYPE, sizeof(pi_usm_type), &AllocTy, nullptr); @@ -589,7 +589,7 @@ alloc get_pointer_type(const void *Ptr, const context &Ctxt) { return alloc::unknown; // otherwise PI_SUCCESS is expected if (Err != PI_SUCCESS) { - Plugin.reportPiError(Err, "get_pointer_type()"); + Plugin->reportPiError(Err, "get_pointer_type()"); } alloc ResultAlloc; @@ -642,8 +642,8 @@ device get_pointer_device(const void *Ptr, const context &Ctxt) { pi_device DeviceId; // query device using PI function - const detail::plugin &Plugin = CtxImpl->getPlugin(); - Plugin.call( + const detail::PluginPtr &Plugin = CtxImpl->getPlugin(); + Plugin->call( PICtx, Ptr, PI_MEM_ALLOC_DEVICE, sizeof(pi_device), &DeviceId, nullptr); // The device is not necessarily a member of the context, it could be a diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 0d920f85f0ab..9409b02c0d2d 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -37,12 +37,12 @@ device::device(cl_device_id DeviceId) { // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.) detail::RT::PiDevice Device; auto Plugin = detail::RT::getPlugin(); - Plugin.call( + Plugin->call( detail::pi::cast(DeviceId), nullptr, &Device); auto Platform = detail::platform_impl::getPlatformFromPiDevice(Device, Plugin); impl = Platform->getOrMakeDeviceImpl(Device, Platform); - Plugin.call(impl->getHandleRef()); + Plugin->call(impl->getHandleRef()); } device::device(const device_selector &deviceSelector) { diff --git a/sycl/source/event.cpp b/sycl/source/event.cpp index 57c47930ba24..8a7033fc8b30 100644 --- a/sycl/source/event.cpp +++ b/sycl/source/event.cpp @@ -30,7 +30,7 @@ event::event(cl_event ClEvent, const context &SyclContext) detail::pi::cast(ClEvent), SyclContext)) { // This is a special interop constructor for OpenCL, so the event must be // retained. - impl->getPlugin().call( + impl->getPlugin()->call( detail::pi::cast(ClEvent)); } diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 341f770a2f82..ee48a32731c6 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -202,7 +202,7 @@ event handler::finalize() { } else { if (MQueue->getDeviceImplPtr()->getBackend() == backend::ext_intel_esimd_emulator) { - MQueue->getPlugin().call( + MQueue->getPlugin()->call( nullptr, reinterpret_cast(MHostKernel->getPtr()), MNDRDesc.Dims, &MNDRDesc.GlobalOffset[0], &MNDRDesc.GlobalSize[0], &MNDRDesc.LocalSize[0], 0, nullptr, @@ -829,9 +829,9 @@ checkContextSupports(const std::shared_ptr &ContextImpl, detail::RT::PiContextInfo InfoQuery) { auto &Plugin = ContextImpl->getPlugin(); pi_bool SupportsOp = false; - Plugin.call(ContextImpl->getHandleRef(), - InfoQuery, sizeof(pi_bool), - &SupportsOp, nullptr); + Plugin->call(ContextImpl->getHandleRef(), + InfoQuery, sizeof(pi_bool), + &SupportsOp, nullptr); return SupportsOp; } diff --git a/sycl/source/interop_handle.cpp b/sycl/source/interop_handle.cpp index 4900329a2eec..110ae33944d7 100644 --- a/sycl/source/interop_handle.cpp +++ b/sycl/source/interop_handle.cpp @@ -34,8 +34,8 @@ pi_native_handle interop_handle::getNativeMem(detail::Requirement *Req) const { auto Plugin = MQueue->getPlugin(); pi_native_handle Handle; - Plugin.call(Iter->second, - &Handle); + Plugin->call(Iter->second, + &Handle); return Handle; } diff --git a/sycl/source/interop_handler.cpp b/sycl/source/interop_handler.cpp index 651f37fd0372..981266abea9c 100644 --- a/sycl/source/interop_handler.cpp +++ b/sycl/source/interop_handler.cpp @@ -28,8 +28,8 @@ pi_native_handle interop_handler::GetNativeMem(detail::Requirement *Req) const { auto Plugin = MQueue->getPlugin(); pi_native_handle Handle; - Plugin.call(Iter->second, - &Handle); + Plugin->call(Iter->second, + &Handle); return Handle; } diff --git a/sycl/source/kernel.cpp b/sycl/source/kernel.cpp index 69f6f2a09b7f..f73735fba8ff 100644 --- a/sycl/source/kernel.cpp +++ b/sycl/source/kernel.cpp @@ -22,7 +22,7 @@ kernel::kernel(cl_kernel ClKernel, const context &SyclContext) detail::getSyclObjImpl(SyclContext), nullptr, nullptr)) { // This is a special interop constructor for OpenCL, so the kernel must be // retained. - impl->getPlugin().call( + impl->getPlugin()->call( detail::pi::cast(ClKernel)); } diff --git a/sycl/test-e2e/Plugin/sycl-ls-unified-runtime.cpp b/sycl/test-e2e/Plugin/sycl-ls-unified-runtime.cpp index 0d61d99ed429..7166cd2d2e17 100644 --- a/sycl/test-e2e/Plugin/sycl-ls-unified-runtime.cpp +++ b/sycl/test-e2e/Plugin/sycl-ls-unified-runtime.cpp @@ -1,12 +1,10 @@ -// REQUIRES: TEMPORARY_DISABLED -// Unified Runtime will soon be changing its reporting. -// -// RUN: env ONEAPI_DEVICE_SELECTOR="ext_oneapi_level_zero:*" sycl-ls --verbose 2>&1 | FileCheck %s +// REQUIRES: gpu, level_zero +// RUN: env ONEAPI_DEVICE_SELECTOR="ext_oneapi_level_zero:*" sycl-ls 2>&1 | FileCheck --check-prefixes=CHECK-PI %s +// RUN: env SYCL_PREFER_UR=0 ONEAPI_DEVICE_SELECTOR="ext_oneapi_level_zero:*" sycl-ls 2>&1 | FileCheck --check-prefixes=CHECK-PI %s +// RUN: env SYCL_PI_TRACE=-1 SYCL_PREFER_UR=1 ONEAPI_DEVICE_SELECTOR="ext_oneapi_level_zero:*" sycl-ls 2>&1 | FileCheck --check-prefixes=CHECK-UR %s -// CHECK: Platforms: 1 -// CHECK-NEXT: Platform [#1]: -// CHECK-NEXT: Version : 1.3 -// CHECK-NEXT: Name : Intel(R) oneAPI Unified Runtime over Level-Zero +// CHECK-PI: Intel(R) Level-Zero +// CHECK-UR: Intel(R) oneAPI Unified Runtime over Level-Zero //==-- sycl-ls-unified-runtime.cpp ----- Test Unified Runtime platform ----==// // diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 680fb25c7688..9a870619fb8b 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3917,10 +3917,10 @@ _ZN4sycl3_V16detail28getPixelCoordNearestFiltModeENS0_3vecIfLi4EEENS0_15addressi _ZN4sycl3_V16detail2pi25contextSetExtendedDeleterERKNS0_7contextEPFvPvES6_ _ZN4sycl3_V16detail2pi3dieEPKc _ZN4sycl3_V16detail2pi9assertionEbPKc -_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE1EEERKNS1_6pluginEv -_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE2EEERKNS1_6pluginEv -_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE3EEERKNS1_6pluginEv -_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE5EEERKNS1_6pluginEv +_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE1EEERKSt10shared_ptrINS1_6pluginEEv +_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE2EEERKSt10shared_ptrINS1_6pluginEEv +_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE3EEERKSt10shared_ptrINS1_6pluginEEv +_ZN4sycl3_V16detail2pi9getPluginILNS0_7backendE5EEERKSt10shared_ptrINS1_6pluginEEv _ZN4sycl3_V16detail33reduGetMaxNumConcurrentWorkGroupsESt10shared_ptrINS1_10queue_implEE _ZN4sycl3_V16detail36get_empty_interop_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6deviceESaIS6_EE _ZN4sycl3_V16detail6OSUtil10getDirNameB5cxx11EPKc diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index ac93b3f6305e..2cb94e1270c3 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -13,10 +13,10 @@ ??$create_sub_devices@$0BAIH@@device@_V1@sycl@@QEBA?AV?$vector@Vdevice@_V1@sycl@@V?$allocator@Vdevice@_V1@sycl@@@std@@@std@@AEBV?$vector@_KV?$allocator@_K@std@@@4@@Z ??$create_sub_devices@$0BAII@@device@_V1@sycl@@QEBA?AV?$vector@Vdevice@_V1@sycl@@V?$allocator@Vdevice@_V1@sycl@@@std@@@std@@W4partition_affinity_domain@info@12@@Z ??$create_sub_devices@$0BAIJ@@device@_V1@sycl@@QEBA?AV?$vector@Vdevice@_V1@sycl@@V?$allocator@Vdevice@_V1@sycl@@@std@@@std@@XZ -??$getPlugin@$00@pi@detail@_V1@sycl@@YAAEBVplugin@123@XZ -??$getPlugin@$01@pi@detail@_V1@sycl@@YAAEBVplugin@123@XZ -??$getPlugin@$02@pi@detail@_V1@sycl@@YAAEBVplugin@123@XZ -??$getPlugin@$04@pi@detail@_V1@sycl@@YAAEBVplugin@123@XZ +??$getPlugin@$00@pi@detail@_V1@sycl@@YAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ +??$getPlugin@$01@pi@detail@_V1@sycl@@YAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ +??$getPlugin@$04@pi@detail@_V1@sycl@@YAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ +??$getPlugin@$02@pi@detail@_V1@sycl@@YAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ ??$getPluginOpaqueData@$04@detail@_V1@sycl@@YAPEAXPEAX@Z ??$get_info@Umemory_clock_rate@device@info@intel@ext@_V1@sycl@@@device_impl@detail@_V1@sycl@@QEBAIXZ ??$get_info@Umemory_bus_width@device@info@intel@ext@_V1@sycl@@@device_impl@detail@_V1@sycl@@QEBAIXZ @@ -984,7 +984,7 @@ ?getOrWaitEvents@detail@_V1@sycl@@YA?AV?$vector@PEAU_pi_event@@V?$allocator@PEAU_pi_event@@@std@@@std@@V?$vector@Vevent@_V1@sycl@@V?$allocator@Vevent@_V1@sycl@@@std@@@5@V?$shared_ptr@Vcontext_impl@detail@_V1@sycl@@@5@@Z ?getPixelCoordLinearFiltMode@detail@_V1@sycl@@YA?AV?$vec@H$07@23@V?$vec@M$03@23@W4addressing_mode@23@V?$range@$02@23@AEAV523@@Z ?getPixelCoordNearestFiltMode@detail@_V1@sycl@@YA?AV?$vec@H$03@23@V?$vec@M$03@23@W4addressing_mode@23@V?$range@$02@23@@Z -?getPlugin@SYCLMemObjT@detail@_V1@sycl@@QEBAAEBVplugin@234@XZ +?getPlugin@SYCLMemObjT@detail@_V1@sycl@@QEBAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ ?getPropList@AccessorBaseHost@detail@_V1@sycl@@QEBAAEBVproperty_list@34@XZ ?getPropList@LocalAccessorBaseHost@detail@_V1@sycl@@QEBAAEBVproperty_list@34@XZ ?getPtr@AccessorBaseHost@detail@_V1@sycl@@QEAAPEAXXZ diff --git a/sycl/tools/abi_check.py b/sycl/tools/abi_check.py index 55129598c1a7..e66b75ff608f 100644 --- a/sycl/tools/abi_check.py +++ b/sycl/tools/abi_check.py @@ -68,10 +68,10 @@ def parse_readobj_output(output): # # Case 1: # pi.hpp: - # template __SYCL_EXPORT const plugin &getPlugin(); + # template __SYCL_EXPORT const PluginPtr &getPlugin(); # # pi.cpp: - # template const plugin &getPlugin() { + # template const PluginPtr &getPlugin() { # static const plugin *Plugin = nullptr; # ... # } diff --git a/sycl/unittests/helpers/PiMock.hpp b/sycl/unittests/helpers/PiMock.hpp index d08bd8890b93..0a0ce57ecfc5 100644 --- a/sycl/unittests/helpers/PiMock.hpp +++ b/sycl/unittests/helpers/PiMock.hpp @@ -198,16 +198,16 @@ class PiMock { // Create new mock plugin platform and plugin handles // Note: Mock plugin will be generated if it has not been yet. MPlatformImpl = GetMockPlatformImpl(Backend); - std::shared_ptr NewPluginPtr; + detail::PluginPtr NewPluginPtr; { - const detail::plugin &OriginalPiPlugin = MPlatformImpl->getPlugin(); + const detail::PluginPtr &OriginalPlugin = MPlatformImpl->getPlugin(); // Copy the PiPlugin, thus untying our to-be mock platform from other // platforms within the context. Reset our platform to use the new plugin. NewPluginPtr = std::make_shared( - OriginalPiPlugin.getPiPluginPtr(), Backend, - OriginalPiPlugin.getLibraryHandle()); + OriginalPlugin->getPiPluginPtr(), Backend, + OriginalPlugin->getLibraryHandle()); // Save a copy of the platform resource - OrigFuncTable = OriginalPiPlugin.getPiPlugin().PiFunctionTable; + OrigFuncTable = OriginalPlugin->getPiPlugin().PiFunctionTable; } MPlatformImpl->setPlugin(NewPluginPtr, Backend); // Extract the new PiPlugin instance by a non-const pointer, @@ -347,7 +347,7 @@ class PiMock { // This makes sure that the mock plugin is the only available plugin. detail::pi::initialize(); detail::GlobalHandler::instance().unloadPlugins(); - std::vector &Plugins = + std::vector &Plugins = detail::GlobalHandler::instance().getPlugins(); assert(Plugins.empty() && "Clear failed to remove all plugins."); @@ -356,9 +356,9 @@ class PiMock { RT::PiPlugin{"pi.ver.mock", "plugin.ver.mock", /*Targets=*/nullptr, getProxyMockedFunctionPointers()}); - MMockPluginPtr = std::make_unique(RTPlugin, Backend, + MMockPluginPtr = std::make_shared(RTPlugin, Backend, /*Library=*/nullptr); - Plugins.push_back(*MMockPluginPtr); + Plugins.push_back(MMockPluginPtr); } private: @@ -378,7 +378,7 @@ class PiMock { MMockPluginPtr->call_nocheck( 1, &PiPlatform, nullptr); return detail::platform_impl::getOrMakePlatformImpl(PiPlatform, - *MMockPluginPtr); + MMockPluginPtr); } std::shared_ptr MPlatformImpl; @@ -392,7 +392,7 @@ class PiMock { // Pointer to the mock plugin pointer. This is static to avoid // reinitialization and re-registration of the same plugin. - static inline std::unique_ptr MMockPluginPtr = nullptr; + static inline detail::PluginPtr MMockPluginPtr = nullptr; }; } // namespace unittest diff --git a/sycl/unittests/pi/BackendString.hpp b/sycl/unittests/pi/BackendString.hpp index 57cbb9648a34..ea90e3ff3eb5 100644 --- a/sycl/unittests/pi/BackendString.hpp +++ b/sycl/unittests/pi/BackendString.hpp @@ -5,15 +5,16 @@ #pragma once #include +#include namespace pi { -inline std::string GetBackendString(const sycl::detail::plugin &Plugin) { +inline std::string GetBackendString(const sycl::detail::PluginPtr &Plugin) { std::stringstream Str; for (sycl::backend Backend : {sycl::backend::opencl, sycl::backend::ext_oneapi_level_zero, sycl::backend::ext_oneapi_cuda, sycl::backend::ext_intel_esimd_emulator, sycl::backend::ext_oneapi_hip}) { - if (Plugin.hasBackend(Backend)) { + if (Plugin->hasBackend(Backend)) { Str << Backend; } } diff --git a/sycl/unittests/pi/EnqueueMemTest.cpp b/sycl/unittests/pi/EnqueueMemTest.cpp index 80671cf3f37e..d6439654f7bb 100644 --- a/sycl/unittests/pi/EnqueueMemTest.cpp +++ b/sycl/unittests/pi/EnqueueMemTest.cpp @@ -14,7 +14,7 @@ using namespace sycl; namespace { -class EnqueueMemTest : public testing::TestWithParam { +class EnqueueMemTest : public testing::TestWithParam { protected: constexpr static size_t _numElementsX = 8; constexpr static size_t _numElementsY = 4; @@ -30,27 +30,27 @@ class EnqueueMemTest : public testing::TestWithParam { void SetUp() override { - detail::plugin plugin = GetParam(); + const detail::PluginPtr &plugin = GetParam(); pi_platform platform = nullptr; - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( 1, &platform, nullptr)), PI_SUCCESS); - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( platform, PI_DEVICE_TYPE_DEFAULT, 1, &_device, nullptr)), PI_SUCCESS); pi_result result = PI_ERROR_INVALID_VALUE; - result = plugin.call_nocheck( + result = plugin->call_nocheck( nullptr, 1u, &_device, nullptr, nullptr, &_context); ASSERT_EQ(result, PI_SUCCESS); - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( _context, _device, 0, &_queue)), PI_SUCCESS); - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( _context, PI_MEM_FLAGS_ACCESS_RW, _numElementsX * _numElementsY * sizeof(pi_int32), nullptr, &_mem, nullptr)), @@ -59,20 +59,20 @@ class EnqueueMemTest : public testing::TestWithParam { void TearDown() override { - detail::plugin plugin = GetParam(); + const detail::PluginPtr &plugin = GetParam(); - ASSERT_EQ((plugin.call_nocheck(_mem)), + ASSERT_EQ((plugin->call_nocheck(_mem)), PI_SUCCESS); - ASSERT_EQ((plugin.call_nocheck(_queue)), + ASSERT_EQ((plugin->call_nocheck(_queue)), PI_SUCCESS); ASSERT_EQ( - (plugin.call_nocheck(_context)), + (plugin->call_nocheck(_context)), PI_SUCCESS); } template void TestBufferFill(const T &pattern) { - detail::plugin plugin = GetParam(); + const detail::PluginPtr &plugin = GetParam(); T inValues[_numElementsX] = {}; @@ -81,20 +81,21 @@ class EnqueueMemTest : public testing::TestWithParam { } pi_event event; - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( _queue, _mem, PI_TRUE, 0, _numElementsX * sizeof(T), inValues, 0, nullptr, &event)), PI_SUCCESS); - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( _queue, _mem, &pattern, sizeof(T), 0, sizeof(inValues), 0, nullptr, &event)), PI_SUCCESS); - ASSERT_EQ((plugin.call_nocheck(1, &event)), - PI_SUCCESS); + ASSERT_EQ( + (plugin->call_nocheck(1, &event)), + PI_SUCCESS); T outValues[_numElementsX] = {}; - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( _queue, _mem, PI_TRUE, 0, _numElementsX * sizeof(T), outValues, 0, nullptr, &event)), PI_SUCCESS); diff --git a/sycl/unittests/pi/PiMock.cpp b/sycl/unittests/pi/PiMock.cpp index 97342a692255..c7014162f9cf 100644 --- a/sycl/unittests/pi/PiMock.cpp +++ b/sycl/unittests/pi/PiMock.cpp @@ -62,11 +62,11 @@ TEST(PiMockTest, ConstructFromQueue) { } const auto &NormalPiPlugin = - detail::getSyclObjImpl(NormalQ)->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(NormalQ)->getPlugin()->getPiPlugin(); const auto &MockedQueuePiPlugin = - detail::getSyclObjImpl(MockQ)->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(MockQ)->getPlugin()->getPiPlugin(); const auto &PiMockPlugin = - detail::getSyclObjImpl(Mock.getPlatform())->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(Mock.getPlatform())->getPlugin()->getPiPlugin(); EXPECT_EQ(&MockedQueuePiPlugin, &PiMockPlugin) << "The mocked object and the PiMock instance must share the same plugin"; EXPECT_EQ(&NormalPiPlugin, &MockedQueuePiPlugin) @@ -79,11 +79,11 @@ TEST(PiMockTest, ConstructFromPlatform) { platform NormalPlatform(default_selector{}); const auto &NormalPiPlugin = - detail::getSyclObjImpl(NormalPlatform)->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(NormalPlatform)->getPlugin()->getPiPlugin(); const auto &MockedPlatformPiPlugin = - detail::getSyclObjImpl(MockPlatform)->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(MockPlatform)->getPlugin()->getPiPlugin(); const auto &PiMockPlugin = - detail::getSyclObjImpl(Mock.getPlatform())->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(Mock.getPlatform())->getPlugin()->getPiPlugin(); EXPECT_EQ(&MockedPlatformPiPlugin, &PiMockPlugin) << "The mocked object and the PiMock instance must share the same plugin"; EXPECT_EQ(&NormalPiPlugin, &MockedPlatformPiPlugin) @@ -93,7 +93,7 @@ TEST(PiMockTest, ConstructFromPlatform) { TEST(PiMockTest, RedefineAPI) { sycl::unittest::PiMock Mock; const auto &MockPiPlugin = - detail::getSyclObjImpl(Mock.getPlatform())->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(Mock.getPlatform())->getPlugin()->getPiPlugin(); const auto &Table = MockPiPlugin.PiFunctionTable; // Pass a function pointer @@ -130,7 +130,7 @@ TEST(PiMockTest, RedefineAfterAPI) { sycl::unittest::PiMock Mock; const auto &MockPiPlugin = - detail::getSyclObjImpl(Mock.getPlatform())->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(Mock.getPlatform())->getPlugin()->getPiPlugin(); const auto &Table = MockPiPlugin.PiFunctionTable; // Pass a function pointer @@ -151,7 +151,7 @@ TEST(PiMockTest, RedefineBeforeAPI) { sycl::unittest::PiMock Mock; const auto &MockPiPlugin = - detail::getSyclObjImpl(Mock.getPlatform())->getPlugin().getPiPlugin(); + detail::getSyclObjImpl(Mock.getPlatform())->getPlugin()->getPiPlugin(); const auto &Table = MockPiPlugin.PiFunctionTable; // Pass a function pointer diff --git a/sycl/unittests/pi/PlatformTest.cpp b/sycl/unittests/pi/PlatformTest.cpp index 95be726e1055..61834dbb14ff 100644 --- a/sycl/unittests/pi/PlatformTest.cpp +++ b/sycl/unittests/pi/PlatformTest.cpp @@ -17,7 +17,7 @@ namespace { using namespace sycl; -class PlatformTest : public testing::TestWithParam { +class PlatformTest : public testing::TestWithParam { protected: std::vector _platforms; PlatformTest() : _platforms{} {}; @@ -26,7 +26,7 @@ class PlatformTest : public testing::TestWithParam { void SetUp() override { - detail::plugin plugin = GetParam(); + const detail::PluginPtr &plugin = GetParam(); ASSERT_NO_FATAL_FAILURE(Test::SetUp()); @@ -39,7 +39,7 @@ class PlatformTest : public testing::TestWithParam { // TODO: Change the test to check this for all plugins present. // Currently, it is only checking for the first plugin attached. - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( 0, nullptr, &platform_count)), PI_SUCCESS); @@ -56,7 +56,7 @@ class PlatformTest : public testing::TestWithParam { _platforms.resize(platform_count, nullptr); - ASSERT_EQ((plugin.call_nocheck( + ASSERT_EQ((plugin->call_nocheck( _platforms.size(), _platforms.data(), nullptr)), PI_SUCCESS); } @@ -76,18 +76,18 @@ TEST_P(PlatformTest, piPlatformsGet) { TEST_P(PlatformTest, piPlatformGetInfo) { - detail::plugin plugin = GetParam(); + const detail::PluginPtr &plugin = GetParam(); auto get_info_test = [&](pi_platform platform, _pi_platform_info info) { size_t reported_string_length = 0; - EXPECT_EQ((plugin.call_nocheck( + EXPECT_EQ((plugin->call_nocheck( platform, info, 0u, nullptr, &reported_string_length)), PI_SUCCESS); // Create a larger result string to catch overwrites. std::vector param_value(reported_string_length * 2u, '\0'); EXPECT_EQ( - (plugin.call_nocheck( + (plugin->call_nocheck( platform, info, param_value.size(), param_value.data(), nullptr)), PI_SUCCESS) << "piPlatformGetInfo for " << detail::pi::platformInfoToString(info) diff --git a/sycl/unittests/pi/TestGetPlugin.hpp b/sycl/unittests/pi/TestGetPlugin.hpp index 90d6658410fe..774d65c02f42 100644 --- a/sycl/unittests/pi/TestGetPlugin.hpp +++ b/sycl/unittests/pi/TestGetPlugin.hpp @@ -11,12 +11,13 @@ #include namespace pi { -inline std::optional +inline std::optional initializeAndGet(sycl::backend backend) { - auto plugins = sycl::detail::pi::initialize(); - auto it = std::find_if( - plugins.begin(), plugins.end(), - [=](sycl::detail::plugin p) -> bool { return p.hasBackend(backend); }); + const auto &plugins = sycl::detail::pi::initialize(); + auto it = std::find_if(plugins.begin(), plugins.end(), + [=](sycl::detail::PluginPtr p) -> bool { + return p->hasBackend(backend); + }); if (it == plugins.end()) { std::stringstream strstr; strstr << backend; @@ -25,18 +26,18 @@ initializeAndGet(sycl::backend backend) { std::cerr << "Warning: " << msg << " Tests using it will be skipped.\n"; return std::nullopt; } - return std::optional(*it); + return std::optional(*it); } -inline std::vector initializeAndRemoveInvalid() { - auto plugins = sycl::detail::pi::initialize(); +inline std::vector initializeAndRemoveInvalid() { + auto &plugins = sycl::detail::pi::initialize(); auto end = std::remove_if( plugins.begin(), plugins.end(), - [](const sycl::detail::plugin &plugin) -> bool { + [](const sycl::detail::PluginPtr &plugin) -> bool { pi_uint32 num = 0; - plugin.call_nocheck(0, nullptr, - &num); + plugin->call_nocheck( + 0, nullptr, &num); bool removePlugin = num <= 0; diff --git a/sycl/unittests/pi/cuda/test_base_objects.cpp b/sycl/unittests/pi/cuda/test_base_objects.cpp index e200a908213c..d0799a08cfff 100644 --- a/sycl/unittests/pi/cuda/test_base_objects.cpp +++ b/sycl/unittests/pi/cuda/test_base_objects.cpp @@ -25,7 +25,7 @@ using namespace sycl; class CudaBaseObjectsTest : public ::testing::Test { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); void SetUp() override { diff --git a/sycl/unittests/pi/cuda/test_commands.cpp b/sycl/unittests/pi/cuda/test_commands.cpp index 0af31c910649..6c794fe51c89 100644 --- a/sycl/unittests/pi/cuda/test_commands.cpp +++ b/sycl/unittests/pi/cuda/test_commands.cpp @@ -22,7 +22,7 @@ using namespace sycl; struct CudaCommandsTest : public ::testing::Test { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); pi_platform platform_; diff --git a/sycl/unittests/pi/cuda/test_contexts.cpp b/sycl/unittests/pi/cuda/test_contexts.cpp index eb34ed5fe98d..7113537ebf14 100644 --- a/sycl/unittests/pi/cuda/test_contexts.cpp +++ b/sycl/unittests/pi/cuda/test_contexts.cpp @@ -9,8 +9,8 @@ #include "gtest/gtest.h" #include -#include #include +#include #include @@ -26,7 +26,7 @@ using namespace sycl; struct CudaContextsTest : public ::testing::Test { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); pi_platform platform_; @@ -227,7 +227,8 @@ TEST_F(CudaContextsTest, ContextThread) { plugin->call(queue); }); - // wait for the thread to be done with the first queue to release the first context + // wait for the thread to be done with the first queue to release the first + // context std::unique_lock lock(m); cv.wait(lock, [&] { return thread_done; }); plugin->call(context1); diff --git a/sycl/unittests/pi/cuda/test_device.cpp b/sycl/unittests/pi/cuda/test_device.cpp index 23ff69c98fcc..9ddb62ca1a51 100644 --- a/sycl/unittests/pi/cuda/test_device.cpp +++ b/sycl/unittests/pi/cuda/test_device.cpp @@ -21,7 +21,7 @@ using namespace sycl; struct CudaDeviceTests : public ::testing::Test { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); pi_platform platform_; diff --git a/sycl/unittests/pi/cuda/test_kernels.cpp b/sycl/unittests/pi/cuda/test_kernels.cpp index 5ec27480ccac..af681ae9bf74 100644 --- a/sycl/unittests/pi/cuda/test_kernels.cpp +++ b/sycl/unittests/pi/cuda/test_kernels.cpp @@ -24,7 +24,7 @@ using namespace sycl; struct CudaKernelsTest : public ::testing::Test { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); pi_platform platform_; pi_device device_; diff --git a/sycl/unittests/pi/cuda/test_mem_obj.cpp b/sycl/unittests/pi/cuda/test_mem_obj.cpp index 33d39438b96a..b0693ff30830 100644 --- a/sycl/unittests/pi/cuda/test_mem_obj.cpp +++ b/sycl/unittests/pi/cuda/test_mem_obj.cpp @@ -23,7 +23,7 @@ using namespace sycl; struct CudaTestMemObj : public ::testing::Test { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); pi_platform platform_; diff --git a/sycl/unittests/pi/cuda/test_sampler_properties.cpp b/sycl/unittests/pi/cuda/test_sampler_properties.cpp index 346156d17cd4..793703d2bd1c 100644 --- a/sycl/unittests/pi/cuda/test_sampler_properties.cpp +++ b/sycl/unittests/pi/cuda/test_sampler_properties.cpp @@ -23,7 +23,7 @@ class SamplerPropertiesTest : public ::testing::TestWithParam> { protected: - std::optional plugin = + std::optional &plugin = pi::initializeAndGet(backend::ext_oneapi_cuda); pi_platform platform_;