Repository navigation
Drop host_task in favor of dpctl's deferred releases - #3224
Draft
ndgrigorian wants to merge 3 commits into
Draft
ndgrigorian wants to merge 3 commits into
ndgrigorian wants to merge 3 commits into
Conversation
dpctl 0.24.0dev0 (IntelPython/dpctl#2359) no longer uses `host_task` to keep Python objects alive during offload: `dpctl::utils::keep_args_alive` now hands a release callback to `SyclQueue_DeferRelease`, which runs it with the GIL held once an empty kernel submitted after the dependencies completes. `dpnp::utils::keep_args_alive` in `dpnp4pybind11.hpp` reimplements the dpctl helper so that it also recognizes dpnp's `usm_ndarray`, and still submitted up to two host tasks: one holding the shared pointers owning USM allocations, and one taking the GIL to decref every other object. It now fills a `detail::held_args<num>` the same way and defers its release with the public `dpctl::utils::defer_release`. The returned event is that of the empty kernel, so its completion means that the arguments are no longer in use rather than that they have been released. The build requirement in pyproject.toml keeps dpctl 0.23.0, the latest on PyPI, with a TODO until dpctl 0.24.0 is released. test_vm_gil.py no longer describes host tasks: it now checks that the work keeping arguments alive needs no GIL.
libtensor and the `lapack` and `sparse` extensions used `host_task` to keep host data alive until copies complete and to free USM temporaries and scratchpads once the work using them is done. A `host_task` may not free USM per the SYCL spec, and AdaptiveCpp does not implement it. `dpnp::tensor::alloc_utils::async_release(q, depends, objs...)` in `utils/sycl_alloc_utils.hpp` moves the objects into a release deferred with `dpctl::utils::defer_release`, which destroys them once the work covered by `depends` completes. If the release cannot be deferred, it waits for that work before rethrowing, so nothing in use is freed. `async_smart_free` and `device_allocate_and_pack` are built on it, and the remaining sites in `choose`, `integer_advanced_indexing`, `triul_ctor`, the LAPACK routines (including `potrs`) and sparse `gemv` call it directly. The events these return are now those of an empty kernel, so the vectors and variables holding them are renamed from `host_task_events`, `host_tasks`, `ht_ev` and the like to `cleanup_events`, `cleanup_ev`, `cleanup_event` and `keep_args_alive_ev`. With the previous commit alone, the GPU test suite hung intermittently on an Intel iGPU with the default Level Zero adapter, and a loop of strided binary operations lost the device after about 2M calls. With this commit, the same loop completes 3M calls and the suite passes. The loop also completes on the v2 adapter without this commit, so the hang appears to be in the v1 adapter; a standalone SYCL loop of a copy followed by a kernel depending on it stalls there too.
The FFT extension kept only the input and output arrays alive, and _compute_result drops the descriptor on return, so the transform could run on a freed descriptor. A blocking scalar copy when scaling the result has hidden it so far; builds with oneMath hit it once that copy is asynchronous (#3182). With keep_args_alive deferring releases through dpctl, the extension now keeps the Python object wrapping the descriptor alive too, which a host task could not release with oneMath without deadlocking. The FFT functions also return the keep-alive event first and the transform's event second, as the other extensions do and as _compute_result already unpacks them.
ndgrigorian
force-pushed
the
drop-host-tasks-and-reuse-dpctl-deferral
branch
from
December 3, 2026 22:58
9858451 to
b9fd596
Compare
ndgrigorian
changed the base branch from
make-scalar-operands-in-binary-ops-asynchronous
to
master
December 3, 2026 22:58
2 of 7 tasks
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3224/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.22.0dev3+79.gcbc76836e ran successfully. |
Collaborator
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR removes every
host_taskfrom dpnp in favor of the deferred releases that dpctl now runs on its own thread (IntelPython/dpctl#2359).dpnp::utils::keep_args_aliveindpnp4pybind11.hpphands its arguments todpctl::utils::defer_releaseinstead of submitting up to two host tasks, one of which took the GIL. It still holds ausm_ndarraythrough theshared_ptrowning its allocation, which dpctl's ownkeep_args_alivecan't do fordpnp.tensor.usm_ndarray.lapackandsparseextensions free temporaries and scratchpads throughasync_release, a new helper inutils/sycl_alloc_utils.hppbuilt ondefer_release, instead of callingsycl::freein a host task, which the SYCL spec doesn't allow and AdaptiveCpp doesn't implement.The keep-alive events are now those of an empty kernel submitted after the work, so their completion means that the arguments are no longer in use, not that they have been released. The Python side still passes them to dpctl's deprecated
add_event_pair; moving toadd_event/add_cleanup_eventis left for a follow-up.Checked on a Level Zero iGPU (0x7d41, WSL):
add_event_pairwithadd_cleanup_eventandadd_event#3225 on top. Before the rebase, the FFT, VM GIL and DLPack tests also passed on the OpenCL CPU device.keep_args_alivechange, the GPU suite hung intermittently, and a loop of stridedx[::2] + y[::2]calls lost the device after about 2M calls on the default Level Zero adapter. With all host tasks gone, the loop completes 3M calls. The v2 adapter runs it clean either way, and a standalone SYCL loop of a copy followed by a dependent kernel also stalls on v1, so the cause looks like the v1 adapter rather than host tasks as such.Not checked locally: the oneMath build, where the FFT descriptor change matters most, devices without fp64, and performance.