Skip to content

Commit 9f747fd

Browse files
committed
Address review and bugs in release watcher
Start dpctl's thread with the first release deferred instead of at import. Start it again in the child of a fork, through os.register_at_fork, and replace it if it ended on its own while the interpreter is still live. stop() waits at most a second for a release that blocks and then detaches the thread. It no longer holds the watcher's lock while waiting, so a concurrent start cannot deadlock. The thread stays stopped until started again, and releases it has not run yet go back on the list. collect_due queries events without holding the list's lock, so a long list does not hold up defer. The poll interval is capped at 100 ms. The interpreter's forced unwind of the thread now propagates through the watcher, run_collected and drain, and still reports the thread finished. The GIL is released if run_collected throws. A failure to start the thread after an item is pushed no longer makes async_dec_ref report a scheduled release as failed. keep_args_alive copies depends into a tuple, so the event count matches what it iterates over, and calls async_dec_ref without the GIL. dpctl4pybind11.hpp loads dpctl_capi outside the static initializer of get_deferred_releases(). Add tests for an exit and a stop with a release that blocks, a start during a stop, releases in a forked child, and a depends whose length differs from its iteration.
1 parent 4c9a77e commit 9f747fd

7 files changed

Lines changed: 574 additions & 100 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
* Added `add_event` and `add_cleanup_event` methods and `cleanup_events` and `num_cleanup_events` properties to the order manager, for tracking the events that gate the release of objects used by offloaded tasks [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
1212

1313
### Changed
14-
* Object lifetime during offload is now managed by a list of releases deferred until the events that gate them have completed, rather than by a `host_task`. `dpctl` keeps one thread for looking over the list and running the releases that have come due, which takes the GIL to do so and lets a release call into the interpreter and free USM allocations [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
14+
* Object lifetime during offload is now managed by a list of releases deferred until the events that gate them have completed, rather than by a `host_task`. `dpctl` keeps one thread for looking over the list and running the releases that have come due, started by the first release deferred and again in the child of a `fork`, which takes the GIL to do so and lets a release call into the interpreter and free USM allocations [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
1515
* The event returned by `dpctl.SyclQueue.keep_args_alive`, `dpctl::utils::keep_args_alive` and `dpctl.SyclQueue._submit_keep_args_alive` is now for an empty kernel that gates the deferred release rather than for a `host_task` that performs it, so its completion means that the objects are no longer in use rather than that they have been released [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
1616

1717
### Deprecated

0 commit comments

Comments
 (0)