Skip to content

Declare free-threading support in the sparse extension - #3101

Merged
antonwolfy merged 2 commits into
masterfrom
fix-sparse-free-threading
Oct 22, 2026
Merged

antonwolfy merged 2 commits into
masterfrom
fix-sparse-free-threading

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

dpnp.backend.extensions.sparse._sparse_impl was the only dpnp extension module declared without py::mod_gil_not_used(). On a free-threaded Python build, importing it (through dpnp.scipy.sparse) re-enabled the GIL for the whole process, with a RuntimeWarning. Every other pybind11 extension and every Cython module in dpnp already declares free-threading support.

The extension keeps no shared mutable state beyond its dispatch tables, which are filled once at import, so it can be declared safe like the others.

A new dpnp/tests/test_free_threading.py runs on free-threaded builds only (the 3.14t CI jobs). In a subprocess it imports every compiled dpnp module and checks that the GIL stays disabled, so a future extension that forgets the declaration is caught too. It skips if a dependency has already re-enabled the GIL.

The C++ change was not built locally; the new test was checked locally only for its module discovery (it finds and imports all 25 compiled modules) and its skip paths, so the CI 3.14t jobs are the real check.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

_sparse_impl was the only dpnp extension module without
py::mod_gil_not_used(), so importing dpnp.scipy.sparse on a free-threaded
Python build re-enabled the GIL for the whole process.

Add a test that imports every compiled dpnp module on a free-threaded
build and checks the GIL stays disabled.
@antonwolfy antonwolfy self-assigned this Oct 14, 2026
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3101/index.html

@coveralls

coveralls commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 82.62% (-0.002%) from 82.622% — fix-sparse-free-threading into master

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev15=np2py314h8d9cdd5_13 ran successfully.
Passed: 1376
Failed: 0
Skipped: 6

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thank you @antonwolfy

@antonwolfy
antonwolfy merged commit c513688 into master Oct 22, 2026
93 of 110 checks passed
@antonwolfy
antonwolfy deleted the fix-sparse-free-threading branch October 22, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants