Skip to content

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

Open
antonwolfy wants to merge 1 commit into
masterfrom
fix-sparse-free-threading
Open

antonwolfy wants to merge 1 commit 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

Copy link
Copy Markdown
Collaborator

Coverage Status

No base build to compare — fix-sparse-free-threading into master

@github-actions

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
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.

2 participants