Skip to content

Feat/enable free threaded python - #213

Merged
ndgrigorian merged 11 commits into
IntelPython:masterfrom
vchamarthi:feat/enable-free-threaded-python
Aug 6, 2026
Merged

Feat/enable free threaded python#213
ndgrigorian merged 11 commits into
IntelPython:masterfrom
vchamarthi:feat/enable-free-threaded-python

Conversation

@vchamarthi

@vchamarthivchamarthi commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Enable free threading support for mkl-service

Depends on gh-174 (meson-python migration), which is now merged.

Free-threading declarations

Two declarations tell the interpreter the extensions are safe without the GIL:

  • mkl/_py_mkl_service.pyx now sets # cython: freethreading_compatible=True.
  • mkl/_mklinitmodule.c calls PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED)
    in PyInit__mklinit, guarded by #ifdef Py_GIL_DISABLED so it is a no-op on
    regular builds.

Cython 3.1.0 floor

freethreading_compatible was introduced in Cython 3.1.0. Verified against the
sources: the directive is absent from Cython/Compiler/Options.py in 3.0.12
(the final 3.0.x) and present in 3.1.0. On older releases the directive is an
unrecognised option and the declaration silently does not happen.

The floor is applied consistently in pyproject.toml, both conda recipes, all
pip-based workflows, and the README build instructions. This is a floor, not a cap.

CopilotAI review requested due to automatic review settings June 23, 2026 14:05

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds initial support for CPython’s free-threaded (GIL-disabled) builds in mkl-service, and (as a prerequisite / in anticipation of PR #174) migrates the build and packaging flow from setuptools/setup.py to meson-python across pip/CI/conda recipes.

Changes:

  • Enable free-threading compatibility in the Cython extension and declare the _mklinit C extension as GIL-independent for free-threaded interpreters.
  • Switch to meson-python (meson.build, pyproject.toml) and remove setup.py.
  • Update CI workflows and conda recipes to build via PEP 517 / Meson and expand Python coverage to 3.14.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 7 comments.

Show a summary per file
FileDescription
setup.pyRemoved legacy setuptools build script.
pyproject.tomlSwitch build backend to mesonpy and update build requirements.
meson.buildNew Meson build defining _mklinit and _py_mkl_service extension builds and install layout.
mkl/_py_mkl_service.pyxMark Cython extension as free-threading compatible.
mkl/_mklinitmodule.cDeclare module GIL usage as “not used” on free-threaded builds.
README.mdAdd source build instructions for Meson/PEP517 flow.
AGENTS.mdUpdate repo-level build/CI documentation to Meson + new workflows.
mkl/AGENTS.mdUpdate Cython wrapper file naming references.
.github/workflows/build-with-clang.ymlUpdate CI build steps for Meson/PEP517 and Python 3.14.
.github/workflows/build-with-standard-clang.ymlNew workflow to build/test with system clang.
.github/workflows/build_pip.ymlNew workflow to validate pip editable build + tests via conda env.
conda-recipe/meta.yamlUpdate host deps for Meson/PEP517 and remove python-gil constraints.
conda-recipe/build.shBuild via python -m build instead of setup.py; clean build dir.
conda-recipe/bld.batBuild via python -m build instead of setup.py.
conda-recipe-cf/meta.yamlUpdate host deps for Meson/PEP517 and remove python-gil constraints.
conda-recipe-cf/build.shBuild/install via pip (PEP517) instead of setup.py.
conda-recipe-cf/bld.batBuild/install via pip (PEP517) instead of setup.py.
.github/copilot-instructions.mdUpdate API-contract file reference to _py_mkl_service.pyx.
.github/AGENTS.mdDocument newly added workflows.
Comments suppressed due to low confidence (1)

mkl/_py_mkl_service.pyx:28

  • Free-threading support is being enabled here, but there’s no corresponding test ensuring the package imports/operates correctly under a free-threaded (GIL-disabled) Python build (e.g., that importing mkl does not re-enable the GIL and basic API calls still work). Adding a small conditional test in mkl/tests/test_mkl_service.py would help prevent regressions.

Comment threadREADME.md Outdated
Comment threadAGENTS.md Outdated
Comment thread.github/copilot-instructions.md
Comment threadmeson.build
Comment thread.github/workflows/build-with-standard-clang.yml
Comment thread.github/workflows/build_pip.yml Outdated
Comment thread.github/workflows/build_pip.yml Outdated
@vchamarthi

Copy link
Copy Markdown
ContributorAuthor

the copilot review comments are basically on the meson python PR #174
This will be cleanly reviewed after it gets meged.

@antonwolfyantonwolfy added this to the 2.9.0 release milestone Jul 24, 2026
Comment thread.github/workflows/build-with-clang.yml
Comment threadconda-recipe/meta.yaml Outdated
Comment thread.github/workflows/build-with-clang.yml
Comment thread.github/workflows/build-with-clang.yml
Comment threadconda-recipe/meta.yaml Outdated
Comment threadpyproject.toml
Comment thread.github/workflows/build-with-clang.yml
Comment thread.github/workflows/conda-package-cf.yml Outdated
Comment thread.github/workflows/conda-package-cf.yml Outdated
Comment thread.github/workflows/conda-package-cf.yml Outdated
Comment thread.github/workflows/conda-package-cf.yml Outdated

@antonwolfyantonwolfy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Only few small nits below, but overall LGTM

Comment threadCHANGELOG.md Outdated
Comment thread.github/AGENTS.md Outdated
Comment thread.github/workflows/conda-package.yml Outdated

@antonwolfyantonwolfy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @vchamarthi, no more comments from me

@vchamarthi

Copy link
Copy Markdown
ContributorAuthor

Please merge this PR. I cannot do it myself.

@ndgrigorian
ndgrigorian merged commit 7b76c55 into IntelPython:masterAug 6, 2026
79 checks passed
Sign up for freeto 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.

4 participants

@vchamarthi@ndgrigorian@antonwolfy