Skip to content

Conversation

againull
Copy link
Contributor

@againull againull commented Oct 15, 2025

Current device_impl implementation assumes shared ownership and manages the handle via urRetain/urRelease in constructor/destructor. Whenever we get temporary device handles via urDeviceGet/urDevicePartition (which implicitly return device handle with refcount == 1) and wrap those handles in device_impl, we have to release temporary handles at
the end of scope to avoid memory leak.

It's done here for devices:

// The reference counter for handles, that we used to create sycl objects, is
// incremented, so we need to call release here.
for (ur_device_handle_t &UrDev : UrDevicesToCleanUp)
MAdapter->call<UrApiKind::urDeviceRelease>(UrDev);

Same needs to be done when we create sub-devices. But currently we were missing release calls for temporary handles after creating device_impl objects wrapping those handles. This PR fixes that issue by releasing temporary handles at the end of the scope.

Current `device_impl` implementation assumes shared ownership and
manages the handle via urRetain/urRelease in constructor/destructor.
Whenver we get temporary device handles via urDeviceGet/urDevicePartition
(which implicitely return device handle with `refcount == 1`) and wrap
those handles in `device_impl`, we have to release temporary handles at
 the end of scope to avoid memory leak.

It's done here for devices: https://github.com/intel/llvm/blob/6b29cf120c267118dc8ad737e54e8b844bfb4e06/sycl/source/detail/platform_impl.cpp#L560-L563

Same needs to be done when we create sub-devices. But currently we were
missing release calls for temporoary handles after creating `device_impl`
objects wrapping those handles. This PR fixes that issue by releasing
temporary handles at the end of the scope.
Copy link
Contributor

@ldorau ldorau left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks a lot for this fix!

@ldorau
Copy link
Contributor

ldorau commented Oct 16, 2025

@pbalcer please review

@ldorau ldorau requested review from kswiecicki and pbalcer October 16, 2025 06:50
@ldorau
Copy link
Contributor

ldorau commented Oct 16, 2025

This patch fixes the Jira issue URT-961.

@againull againull merged commit 8456b01 into intel:sycl Oct 16, 2025
28 checks passed
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.

3 participants