Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/free threaded #2260

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/freethreading.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Kept seperate from core.yml because it uses a quantsight-built python setup
name: freethreading

on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.13t"]
cpp-version: [g++-8, clang-7]
steps:
- uses: actions/checkout@v2
- name: Install native dependencies
run: |
sudo apt install ${{ matrix.cpp-version }}
sudo apt install libopenblas-dev # for meson integration testing
- name: Setup Python ${{ matrix.python-version }}
uses: quansight-labs/setup-python@v5.3.1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install scipy-openblas64
pip install pytest-xdist
- name: Setup
run: |
python -m pip install .
printf '[compiler]\nblas=scipy-openblas\n' > ~/.config/.pythranrc
printf 'cflags=-std=c++11 -Wall -Werror -Wno-unknown-pragmas -Wno-unused-local-typedefs -Wno-cpp -Wno-deprecated-declarations' >> ~/.config/.pythranrc
if test "${{ matrix.cpp-version }}" = "clang-7" ; then printf -- " -Wno-absolute-value -Wno-parentheses-equality\n" ; else printf "\n" ; fi >> ~/.config/.pythranrc
- name: Testing minimal CLI
run: |
pythran --version
pythran --help
pythran-config -vvv
- name: Testing sequential
run: |
export CC=`echo ${{ matrix.cpp-version }} | sed -e 's/g++/gcc/'`
export CXX=`echo ${{ matrix.cpp-version }} | sed -e 's/clang/clang++/'`
pytest pythran/tests/test_base.py -v -x
7 changes: 7 additions & 0 deletions docs/MANUAL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,13 @@ This controls some behavior of the C++ backend, so the default should be safe::
# to the original python code
annotate = false

# set to 'lineno' if you want to generate line number instead of python extract
annotation_kind = 'comment'

# make generated module compatible with freethreading, see
# https://py-free-threading.github.io/
freethreading_compatible = true


F.A.Q.
------
Expand Down
6 changes: 6 additions & 0 deletions pythran/cxxgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#

from textwrap import dedent
from pythran.config import cfg
from pythran.tables import pythran_ward
from pythran.spec import signatures_to_string
from pythran.utils import quote_cxxstring
Expand Down Expand Up @@ -732,11 +733,16 @@ def __str__(self):
theDoc);

{extraobjects}
{freethreading}
return theModule;
}}
'''.format(name=self.name,
import_umath="import_umath();" if self.ufuncs else "",
extraobjects='\n'.join(theextraobjects),
freethreading="""
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(theModule, Py_MOD_GIL_NOT_USED);
#endif""" if cfg.getboolean("backend", "freethreading_compatible") else "",
**self.metadata))

body = (self.preamble +
Expand Down
4 changes: 4 additions & 0 deletions pythran/pythran.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ annotate = false

# set to 'lineno' if you want to generate line number instead of python extract
annotation_kind = 'comment'

# make generated module compatible with freethreading, see
# https://py-free-threading.github.io/
freethreading_compatible = true