Skip to content

[SYCL] Make ur::getAdapter return raw adapter pointer instead of shared_ptr #19102

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

Merged
merged 10 commits into from
Jun 25, 2025

Conversation

uditagarwal97
Copy link
Contributor

@uditagarwal97 uditagarwal97 commented Jun 23, 2025

Currently, ur::getAdapter returns a shared pointer to the adapter. However, that's unnecessary.
This PR makes ur::getAdapter return a raw ptr instead and let global handler manage lifetime of the adapter object.

@uditagarwal97 uditagarwal97 self-assigned this Jun 23, 2025
@uditagarwal97 uditagarwal97 requested a review from vinser52 June 23, 2025 18:15
@uditagarwal97 uditagarwal97 marked this pull request as ready for review June 23, 2025 18:15
@uditagarwal97 uditagarwal97 requested review from a team as code owners June 23, 2025 18:15
@uditagarwal97 uditagarwal97 requested a review from slawekptak June 23, 2025 18:15
@uditagarwal97
Copy link
Contributor Author

Followup PR to pass adapter by ref instead of pointer: #19105

@@ -34,7 +34,7 @@ namespace detail {
class context_impl;
class event_impl;
class Adapter;
using AdapterPtr = std::shared_ptr<Adapter>;
using AdapterPtr = Adapter *;
Copy link
Contributor

Choose a reason for hiding this comment

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

We have the AdapterPtr type still defined, so is there a reason to mix the use of AdapterPtr and Adapter *? Would it be possible to unify to one or the other? I think that typically, the *Ptr types are shared_ptrs in SYCL code, so maybe just remove this type and use a raw pointer everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a follow-up PR (#19105) where I removed AdapterPtr completely and returned Adapter reference instead of a pointer. Removing AdapterPtr is a big, mostly-NFC change so I created a seperate PR.

std::weak_ptr<Adapter> AdapterWeakPtr;
KernelBuildResult(const AdapterPtr &Adapter) : AdapterWeakPtr(Adapter) {
AdapterPtr adapter;
KernelBuildResult(const AdapterPtr &_adapter) : adapter(_adapter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just pass a raw pointer by value instead of reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the subsequent PR, I'll be replacing Adapter* with Adapter reference instead so, this change is aligned with it.

@uditagarwal97
Copy link
Contributor Author

@intel/unified-runtime-reviewers ping

Copy link
Contributor

@nrspruit nrspruit left a comment

Choose a reason for hiding this comment

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

LGTM

@uditagarwal97 uditagarwal97 merged commit a0062cf into sycl Jun 25, 2025
25 checks passed
@uditagarwal97 uditagarwal97 deleted the private/udit/urgetadapter branch June 25, 2025 22:34
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.

4 participants