-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use HPy to define the ndarray type #2
Conversation
Also, ensure that the C sources for HPy are compiled in.
85865ae
to
0371393
Compare
Maybe you could tie the pypy download to the latest nightly instead of the 7.3.3 release |
setup_requires=['hpy.devel'], | ||
# distuils doesn't load hpy.devel unless hpy_ext_modules is present | ||
# as a keyword | ||
hpy_ext_modules=[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rlamy I'm not sure what the final fix should be yet, but in the mean time this small change made what was happening much more understandable. With it, --hpy-abi
no longer gives an error for me. I still need to see what actually happens during the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
It doesn't compile on PyPy (because it lacks _HPyGetContext() ATM)
this comment is no longer true, isn't it?
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE), | ||
.slots = PyArray_Type_slots, | ||
.flags = (HPy_TPFLAGS_DEFAULT | HPy_TPFLAGS_BASETYPE), | ||
.legacy_slots = PyArray_Type_slots, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a note: looking at how it is easy to migrate an existing extension, I think that the invention of .legacy_slots
is a Very Good Idea :)
@@ -4767,12 +4773,12 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) { | |||
if (initumath(m) != 0) { | |||
goto err; | |||
} | |||
return m; | |||
return HPy_FromPyObject(ctx, m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, this is interesting. I always assumed that the first thing to do to port a module to HPy would be to convert PyModuleDef
into HPyModuleDef
and thus using HPyModule_Create
, but indeed, it's not required.
It is worth adding a note to docs/porting-guide.rst
, maybe showing an example of the minimal diff which is required to hpy-ify a module.
@@ -4,6 +4,7 @@ requires = [ | |||
"setuptools<49.2.0", | |||
"wheel<=0.35.1", | |||
"Cython>=0.29.21,<3.0", # Note: keep in sync with tools/cythonize.py | |||
"hpy.devel @ git+https://github.com/hpyproject/hpy.git@8e20b89116c2993188157c09a6070a64f8efbd82#egg=hpy.devel" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should start to tag/release "real" revisions
@@ -49,6 +49,7 @@ pip install --upgrade pip 'setuptools<49.2.0' wheel | |||
# requirement using `grep cython test_requirements.txt` instead of simply | |||
# writing 'pip install setuptools wheel cython'. | |||
pip install `grep cython test_requirements.txt` | |||
pip install `grep hpy.devel test_requirements.txt` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed for a good reason, or simply because we haven't released hpy.devel
on PyPI? In theory the setup_requires=['hpy.devel']
should be enough for setuptools to do the "right thing", isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think that the comment about Cython applies to HPy as well: we probably want to ensure that we have a specific version of HPy and setup_requires may not be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think that the comment about Cython applies to HPy as well
not necessarily: Cython has a weird way of integrating with setuptools: you need to call cythonize
before the call to setup()
, so setuptools doesn't even have a chance to install it even if you put in setup_requires
.
HPy have a different approach, which is the same as cffi: it uses setuptool's entry points, so you don't need to be able to import hpy.devel
before calling setup()
.
we probably want to ensure that we have a specific version of HPy and setup_requires may not be enough.
I think that setup_requires=['hpy.devel==0.123']
would work, once we have proper releases
@@ -25,7 +25,8 @@ if [ -n "$PYTHON_OPTS" ]; then | |||
fi | |||
|
|||
# make some warnings fatal, mostly to match windows compilers | |||
werrors="-Werror=vla -Werror=nonnull -Werror=pointer-arith" | |||
# werrors="-Werror=vla -Werror=nonnull -Werror=pointer-arith" | |||
werrors="-Werror=nonnull -Werror=pointer-arith" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because ATM HPy uses Variable Length Arrays, so the build fails with "-Werror=vla" on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See discussion in hpyproject/hpy#125.
Current status:
|
I'm confused: currently Moreover, I'm not even sure if we can support the very same semantics as |
These are CPython slots, not HPy slots. They are trivially supported on CPython, with both ABIs. On PyPy, however, it's a lot more difficult. I think that the only way to support them is to fall back to cpyext and create a |
I think |
|
I think |
I'm confused again. We already support
well, we already have machinery to convert Also, keep on mind that using
|
That's because you're thinking of HPy slots, again ;-) I'm only discussing legacy CPython slots here.
The problem is that we'd have an HPy type whose instances are cpyext objects, which is likely to cause some headaches. In any case, there is a more fundamental issue. In the CPython API,
In numpy's case, the temporary solution is likely to last for a long time. It would be rather sad if numpy had to stop supporting pypy because of HPy! But I guess it's fine if we say that tp_new et al. must be converted to be supported on pypy. |
yes, but that's something we surely need to solve, probably sooner than later. Some relevant discussions:
To have any chance to implement any What are the "tricky
well, with my proposed solution above, this problem will be automatically solved I think.
why do you say so? Is there any fundamental issue which prevents |
Yes, I agree that falling back to a cpyext type is the only solution to make it work on pypy. I guess the exact rules will be determined by the outcome of hpyproject/hpy#156. |
commit 9c833bed5879d77e625556260690c349de18b433 Author: Thomas Li <[email protected]> Date: Wed Nov 17 16:21:27 2021 -0800 Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Update LICENSE_win32.txt Update LICENSE_win32.txt Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Update LICENSE_win32.txt Update LICENSE_win32.txt Update cibw_test_command.sh commit 4bd12df Author: Thomas Li <[email protected]> Date: Mon Nov 15 17:28:47 2021 -0800 # This is a combination of 14 commits. # This is the 1st commit message: Add Windows config to GHA # This is the commit message #2: update script [wheel build] # This is the commit message #3: typo [wheel build] # This is the commit message #4: fix typo? [wheel build] # This is the commit message #5: fix linux builds? [wheel build] # This is the commit message #6: typo [wheel build] # This is the commit message #7: add license and pin to windows 2016 # This is the commit message #8: skip tests [wheel build] # This is the commit message #9: pin to windows 2019 instead [wheel build] # This is the commit message #10: try to find out the error on windows [wheel build] # This is the commit message #11: maybe fix? [wheel build] # This is the commit message #12: maybe fix? [wheel build] # This is the commit message #13: fix? [wheel build] # This is the commit message #14: cleanup [wheel build]
PyArray_Type
is now defined usingHPyType_FromSpec()
, which is a straightforward change. The difficulty was more in hacking the build and CI systems to support HPy.Note that there are a few issues with this:
It doesn't compile on PyPy (because it lacks_HPyGetContext()
ATM)tp_weaklistoffset
.