From 8f787d1e9db984ba4c2f25fe70aa3f5339035c12 Mon Sep 17 00:00:00 2001 From: vchamarthi Date: Wed, 17 Jun 2026 12:41:48 -0500 Subject: [PATCH] add free threading pythoon support --- .github/workflows/build-with-clang.yml | 2 +- .github/workflows/build-with-standard-clang.yml | 2 +- .github/workflows/build_pip.yml | 2 +- conda-recipe-cf/meta.yaml | 4 +--- conda-recipe/meta.yaml | 4 +--- mkl/_mklinitmodule.c | 6 ++++++ mkl/_py_mkl_service.pyx | 1 + pyproject.toml | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-with-clang.yml b/.github/workflows/build-with-clang.yml index 4af204a..9c2aa7e 100644 --- a/.github/workflows/build-with-clang.yml +++ b/.github/workflows/build-with-clang.yml @@ -55,7 +55,7 @@ jobs: - name: Install mkl-service dependencies run: | - pip install meson-python cython cmake ninja + pip install meson-python "cython>=3.1.0" cmake ninja - name: List oneAPI folder content run: ls ${{ env.ONEAPI_ROOT }}/compiler diff --git a/.github/workflows/build-with-standard-clang.yml b/.github/workflows/build-with-standard-clang.yml index 4652f89..7fcfa2f 100644 --- a/.github/workflows/build-with-standard-clang.yml +++ b/.github/workflows/build-with-standard-clang.yml @@ -46,7 +46,7 @@ jobs: - name: Install mkl-service dependencies run: | - pip install meson-python cython cmake ninja mkl-devel + pip install meson-python "cython>=3.1.0" cmake ninja mkl-devel - name: Build mkl-service run: | diff --git a/.github/workflows/build_pip.yml b/.github/workflows/build_pip.yml index 1a21d61..c51adfd 100644 --- a/.github/workflows/build_pip.yml +++ b/.github/workflows/build_pip.yml @@ -42,7 +42,7 @@ jobs: - name: Build conda package run: | - pip install --no-cache-dir meson-python ninja cmake cython + pip install --no-cache-dir meson-python ninja cmake "cython>=3.1.0" pip install -e ".[test]" --no-build-isolation --verbose pip list python -m pytest -v mkl/tests diff --git a/conda-recipe-cf/meta.yaml b/conda-recipe-cf/meta.yaml index 3dc85a4..daef60a 100644 --- a/conda-recipe-cf/meta.yaml +++ b/conda-recipe-cf/meta.yaml @@ -24,15 +24,13 @@ requirements: - cmake - ninja - python - - python-gil # [py>=314] - pip >=25.0 - mkl-devel # [not osx] - mkl-devel <2024 # [osx] - - cython + - cython >=3.1.0 - wheel >=0.45.1 run: - python - - python-gil # [py>=314] - {{ pin_compatible('mkl') }} test: diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 577c792..3101306 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -23,15 +23,13 @@ requirements: - cmake - ninja - python - - python-gil # [py>=314] - python-build - pip >=25.0 - mkl-devel - - cython + - cython >=3.1.0 - wheel >=0.45.1 run: - python - - python-gil # [py>=314] - {{ pin_compatible('mkl') }} test: diff --git a/mkl/_mklinitmodule.c b/mkl/_mklinitmodule.c index 33abdf5..11571dd 100644 --- a/mkl/_mklinitmodule.c +++ b/mkl/_mklinitmodule.c @@ -200,6 +200,12 @@ PyMODINIT_FUNC PyInit__mklinit(void) return NULL; } +#ifdef Py_GIL_DISABLED + /* Declare that this module supports running without the GIL so the + * free-threaded interpreter does not re-enable it on import. */ + PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); +#endif + return m; } #else diff --git a/mkl/_py_mkl_service.pyx b/mkl/_py_mkl_service.pyx index 975a454..72908fe 100644 --- a/mkl/_py_mkl_service.pyx +++ b/mkl/_py_mkl_service.pyx @@ -25,6 +25,7 @@ # distutils: language = c # cython: language_level=3 +# cython: freethreading_compatible=True import numbers import warnings diff --git a/pyproject.toml b/pyproject.toml index 3e89d35..ee76a6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ build-backend = "mesonpy" requires = [ "meson-python>=0.13.0", "ninja", - "Cython", + "Cython>=3.1.0", "mkl-devel", "cmake" ]