Skip to content

[doc-only] docs: clarify cuda.core concurrency and thread-safety policy#2318

Open
Andy-Jost wants to merge 1 commit into
NVIDIA:mainfrom
Andy-Jost:ajost/docs-concurrency-thread-safety
Open

[doc-only] docs: clarify cuda.core concurrency and thread-safety policy#2318
Andy-Jost wants to merge 1 commit into
NVIDIA:mainfrom
Andy-Jost:ajost/docs-concurrency-thread-safety

Conversation

@Andy-Jost

@Andy-Jost Andy-Jost commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

  • Concurrent reads of a cuda.core object from multiple host threads are supported.
  • Concurrent mutation of the same object is not supported; the application must provide external synchronization (as is customary for NumPy, CuPy, and PyTorch).
  • The library protects the integrity of its own internal state, so concurrent reads of one object and concurrent use of distinct objects cannot corrupt the interpreter. This is an integrity guarantee only.
  • Distinct objects can still collide through shared CUDA driver/context state (e.g. changing peer device access while another thread accesses affected memory); synchronizing those cases is also the caller's responsibility.

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 like Device, 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

@Andy-Jost Andy-Jost added this to the cuda.core next milestone Jul 7, 2026
@Andy-Jost Andy-Jost added documentation Improvements or additions to documentation cuda.core Everything related to the cuda.core module labels Jul 7, 2026
@Andy-Jost Andy-Jost self-assigned this Jul 7, 2026
@Andy-Jost Andy-Jost requested review from leofang, mdboom and seberg July 7, 2026 23:20
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

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).
@Andy-Jost Andy-Jost force-pushed the ajost/docs-concurrency-thread-safety branch from f3b7a51 to d826eb3 Compare July 8, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant