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

Copy link
Copy Markdown
Contributor

Summary

Documents cuda.core's concurrency and thread-safety expectations, which were previously agreed only in review threads (#2280) and never written down. Adds a user-facing policy and a contributor-facing set of invariants. Docs only; no code or behavior changes.

Changes

  • docs/source/support.rst: new "Concurrency and Thread Safety" section stating that concurrent operations on the same object are not guaranteed thread-safe and require external synchronization (consistent with the CUDA driver and with NumPy/CuPy/PyTorch convention), while the library protects the integrity of its own internal state. Links the tracking issue Address known thread-safety issues in cuda.core #1389.
  • cuda_core/AGENTS.md: new "Concurrency and free-threading" section capturing the invariants contributors and agents should uphold: same-object mutation is the caller's responsibility, protect internal cached/module-level state against refcount-corrupting races (critical sections/atomics/setdefault), entry points assume the GIL is held, and release the GIL before entering the driver from callback/__del__ paths.

Related Work

Document the previously-implicit concurrency contract that was agreed in
review threads but never written down: concurrent operations on the same
cuda.core object are not guaranteed thread-safe and require external
synchronization, while the library protects the integrity of its own
internal state (caches, reference counting).

- support.rst: user-facing "Concurrency and Thread Safety" section.
- cuda_core/AGENTS.md: contributor-facing invariants (user-synchronized
  mutation, protecting internal cached state, GIL-held entry points, and
  releasing the GIL before entering the driver from callback/__del__ paths).

Refs NVIDIA#1389, NVIDIA#2280, NVIDIA#350.
@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

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