Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork10.9k
GH-29021: Convert _simd.c to multi-phase init (PEP 489)#29025
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
|
static struct PyModuleDef defs = { | ||
.m_base = PyModuleDef_HEAD_INIT, | ||
.m_name = "numpy._core._simd", | ||
.m_size = 0, |
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.
This was -1, did it become 0 on purpose?
AA-TurnerMay 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
A value of-1
indicates to Python that the module has global state (PyModuleDef.m_size
). It forbids any use of subinterpreters, re-initialisation, etc.
Changing to 0 was perhaps a gamble, seeing if tests passed. To be more conservative though, we could keepm_size
to-1
and defer changing it to a non-negative number to a future PR. What would you suggest?
A
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.
Yes, I think we should change it to 0 in a future PR. Please only change it in a single PR, lets get one of these in before the mass move of all the other ones. Does the change impact performance? I would suggest redoing this in#29030, or one of the others that touch a commonly used module, and then running the benchmarks to see if there is a regression when using multi-phase init.
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.
Ok, I've updated#29030 to keepm_size = -1
.
Is there infrastructure to benchmark a PR? My laptop isn't an ideal environment & I don't have a spare computer to run thelocal benchmarks.
AA-TurnerMay 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Fromhttps://github.com/numpy/numpy/actions/runs/15179012580/job/42684537494?pr=29030
m_size may not be negative for multi-phase initialization
I'll get the Python documentation updated, this isn't very obvious! In the meantime, I'll revert the change to#29030.
I believe0
is the correct value to keep, as there is currently no per-module state and hence nothing to allocate memory for.
Uh oh!
There was an error while loading.Please reload this page.