Skip to content

[SYCL] Less shared_ptr for platform_impl #18143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: sycl
Choose a base branch
from

Conversation

aelovikov-intel
Copy link
Contributor

@aelovikov-intel aelovikov-intel commented Apr 22, 2025

GlobalHandler::MPlatformCache keeps (shared) ownership of platform_impl objects, so none of them could be destroyed until SYCL RT library shutdown/unload process. As such, using raw pointers/reference to platform_impl throughout the SYCL RT is totally fine and avoids extra costs of std::shared_ptr. On the other hand, extending lifetime of any object past that shutdown would mean that we have a SYCL object, but all the UR adapters have been unloaded already. As such, tying the lifetime to the exact moment library is unloaded seems to be the only reasonable choice.

I'm relatively sure sycl::platform could avoid using std::shared_ptr<detail::platform_impl> impl as well, but that would be a breaking change so not being implemented at this moment.

This change means that unittests/Extensions/CurrentDevice.cpp can't work anymore because unittests/mock don't use libsycl.so and lifetimes aren't managed the same way as for the actual SYCL programs.

@uditagarwal97 uditagarwal97 requested a review from Copilot April 24, 2025 17:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the SYCL runtime to reduce unnecessary use of std::shared_ptr for platform_impl objects by replacing them with raw references or pointers in critical parts of the code, thereby reducing ownership overhead. The changes update several interfaces and call sites throughout the codebase.

  • Changed the platform interface in tests and source files (e.g. printers.cpp, platform.cpp) to use platform_impl references.
  • Updated device and program manager implementations to adjust method calls and data access to the new raw reference API.
  • Refactored platform_impl.hpp/.cpp and related files to expose getSharedPtrToSelf() and return references instead of smart pointers.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sycl/test/gdb/printers.cpp Updated comments to reflect the change from shared_ptr to references for platform_impl.
sycl/source/platform.cpp Modified platform_impl acquisition to return a shared pointer via getSharedPtrToSelf() and updated related call sites.
sycl/source/device.cpp Adjusted device_impl initialization to use the new platform_impl API with references.
sycl/source/detail/usm/usm_impl.cpp Replaced arrow operator calls with dot operator calls on platform_impl references.
sycl/source/detail/program_manager/program_manager.cpp Refactored access to platform_impl from pointer to reference in option handling and backend option retrieval.
sycl/source/detail/platform_impl.hpp/.cpp Changed several methods in platform_impl to return references instead of shared_ptr, including updates to helper methods and caching.
Other Files (global_handler.hpp/.cpp, device_impl.hpp/.cpp, context_impl.hpp/.cpp, backend files, etc.) Updated all affected call sites and interface definitions to conform with the new ownership model.

@aelovikov-intel aelovikov-intel changed the title [NFCI][SYCL] Less shared_ptr for platform_impl [SYCL] Less shared_ptr for platform_impl Apr 25, 2025
`GlobalHandler::MPlatformCache` keeps (shared) ownership of
`platform_impl` objects, so none of them could be destroyed until SYCL
RT library shutdown/unload process. As such, using raw
pointers/reference to `platform_impl` throughout the SYCL RT is totally
fine and avoids extra costs of `std::shared_ptr`

I'm relatively sure `sycl::platform` could avoid using
`std::shared_ptr<detail::platform_impl> impl` as well, but that would be
a breaking change so not being implemented at this moment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant