Uh oh!
There was an error while loading. Please reload this page.
[doc-only] docs: clarify cuda.core concurrency and thread-safety policy - #2318
Conversation
This comment has been minimized.
This comment has been minimized.
Document the concurrency contract that was previously agreed only in review threads: concurrent reads of a cuda.core object are supported, but concurrent mutation of the same object requires application-provided synchronization. Distinct objects can still collide through shared CUDA driver/context state (e.g. peer device access), which is also the caller's responsibility. - docs/source/concurrency.rst: new user-facing "Concurrency and Thread Safety" page, linked into the docs toctree. - cuda_core/AGENTS.md: contributor-facing invariants (reads-safe/mutation boundary, prefer immutable designs, shared-driver-state collisions, guarding internal cached state only for legitimately-shared objects, GIL-held entry points, and releasing the GIL before entering the driver from callback/__del__ paths).
f3b7a51 to
d826eb3Compare
seberg
left a comment
There was a problem hiding this comment.
Thanks, much nicer than what I could have come up with! And I don't have a concrete improvement thought.
(My small thoughts are at best if we are comfortable to say that e.g. memory pools is, I believe, safe and might seem mutable. And I suspect most things are thread-safe in the sense of not corrupting state, unless it's a green context or so, but I got a feeling that information likely wouldn't add much even if we were comfortable to note it.)
| (#2217). Guard state only on objects that are legitimately shared between threads; | ||
| objects that are not meant to be shared (e.g., the thread-local `Device`) do not | ||
| need such guards (see #2321). Reference-count integrity is guaranteed; cache | ||
| value-identity/idempotency is not. |
There was a problem hiding this comment.
Yeah, I think there are a few objects where we want idempotency. But not everwhere (places that use dict.setdefault() to ensure this).
Uh oh!
There was an error while loading. Please reload this page.
|
Summary
Writes down cuda.core's concurrency and thread-safety expectations, which were previously agreed only in review threads (#2280) and a follow-up Slack discussion, but never documented. Adds a short user-facing policy page and a matching set of contributor-facing invariants. Docs only; no code or behavior changes.
The policy is intentionally minimal, per the discussion: state what users can rely on today without overcommitting to guarantees we would have to maintain long-term.
Policy
Changes
docs/source/concurrency.rst: new user-facing "Concurrency and Thread Safety" page, linked into the docs toctree (docs/source/index.rst).cuda_core/AGENTS.md: new "Concurrency and free-threading" section for contributors and reviewers -- reads-safe/mutation boundary, prefer immutable designs, shared-driver-state collisions, guarding internal cached state only for legitimately-shared objects (not thread-local ones likeDevice, cf. Revert SMResource splitting fix, the problem was the test #2321), GIL-held entry points, and releasing the GIL before entering the driver from callback/__del__paths.Related Work