diff --git a/CHANGELOG.md b/CHANGELOG.md index 7153412dece..96f956a0c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ This release is compatible with NumPy 2.5. * Fixed `dpnp.repeat` raising an unclear `TypeError` for a nested sequence of `repeats` [#3024](https://github.com/IntelPython/dpnp/pull/3024) * Fixed `dpnp.ndarray.view` ignoring the USM element offset of a sliced array, which also caused `dpnp.einsum` to silently return wrong results for a single sliced operand with no summed index [#3037](https://github.com/IntelPython/dpnp/pull/3037) * Fixed `dpnp.all` and `dpnp.any` aborting when reducing over an empty axis (e.g. an array with a zero-length dimension) [#3021](https://github.com/IntelPython/dpnp/pull/3021) +* Fixed a per-call `sycl::queue` leak in `usm_ndarray::get_queue()`/`get_device()` [#3042](https://github.com/IntelPython/dpnp/pull/3042) ### Security diff --git a/dpnp/include/dpnp4pybind11.hpp b/dpnp/include/dpnp4pybind11.hpp index d80dac8be2b..2cc55648bf4 100644 --- a/dpnp/include/dpnp4pybind11.hpp +++ b/dpnp/include/dpnp4pybind11.hpp @@ -489,8 +489,13 @@ 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); - return *(reinterpret_cast(QRef)); + std::unique_ptr q_ptr{ + reinterpret_cast(QRef)}; + return *q_ptr; } sycl::device get_device() const @@ -498,8 +503,12 @@ 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; wrap it in a + // unique_ptr to avoid leaking a queue per call. DPCTLSyclQueueRef QRef = api.UsmNDArray_GetQueueRef_(raw_ar); - return reinterpret_cast(QRef)->get_device(); + std::unique_ptr q_ptr{ + reinterpret_cast(QRef)}; + return q_ptr->get_device(); } int get_typenum() const