-
Notifications
You must be signed in to change notification settings - Fork 29
Fix sycl::queue leak in usm_ndarray get_queue()/get_device()
#3042
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -489,17 +489,26 @@ class usm_ndarray : public py::object | |
| PyUSMArrayObject *raw_ar = usm_array_ptr(); | ||
|
|
||
| auto const &api = detail::dpnp_capi::get(); | ||
| // UsmNDArray_GetQueueRef_ returns an owning copy (DPCTLQueue_Copy, | ||
| // i.e. `new sycl::queue`); wrap it in a unique_ptr to avoid leaking a | ||
| // queue per call. | ||
| DPCTLSyclQueueRef QRef = api.UsmNDArray_GetQueueRef_(raw_ar); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return *(reinterpret_cast<sycl::queue *>(QRef)); | ||
| std::unique_ptr<sycl::queue> q_ptr{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One point worth considering: freeing via
Non-blocking, but to honor the documented contract we could use a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A cleaner option that honors the contract and avoids the link dependency: add a
cdef api void UsmNDArray_RemoveQueueRef(c_dpctl.DPCTLSyclQueueRef QRef):
"""Delete a DPCTLSyclQueueRef previously returned by UsmNDArray_GetQueueRef"""
c_dpctl.DPCTLQueue_Delete(QRef) # safe on NULL
DPCTLSyclQueueRef QRef = api.UsmNDArray_GetQueueRef_(raw_ar);
auto qref_deleter = [](sycl::queue *q) {
detail::dpnp_capi::get().UsmNDArray_RemoveQueueRef_(
reinterpret_cast<DPCTLSyclQueueRef>(q));
};
std::unique_ptr<sycl::queue, decltype(qref_deleter)> q_ptr{
reinterpret_cast<sycl::queue *>(QRef), qref_deleter};
return *q_ptr;This keeps allocation and deallocation on dpctl's side of the ABI and gives a symmetric Get/Remove pair (the capi test would be the natural place for a round-trip check). That change is non-blocking for the PR — the current |
||
| reinterpret_cast<sycl::queue *>(QRef)}; | ||
| return *q_ptr; | ||
| } | ||
|
|
||
| sycl::device get_device() const | ||
| { | ||
| PyUSMArrayObject *raw_ar = usm_array_ptr(); | ||
|
|
||
| auto const &api = detail::dpnp_capi::get(); | ||
| // UsmNDArray_GetQueueRef_ returns an owning copy; wrap it in a | ||
| // unique_ptr to avoid leaking a queue per call. | ||
| DPCTLSyclQueueRef QRef = api.UsmNDArray_GetQueueRef_(raw_ar); | ||
| return reinterpret_cast<sycl::queue *>(QRef)->get_device(); | ||
| std::unique_ptr<sycl::queue> q_ptr{ | ||
| reinterpret_cast<sycl::queue *>(QRef)}; | ||
| return q_ptr->get_device(); | ||
| } | ||
|
|
||
| int get_typenum() const | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a shorter comment?