Repository navigation
ENH: Migrate _multiarray_umath global variables to per-module state - #31992
Conversation
d9b01c3 to
dd4e3ca
Compare
|
This looks correct to me so far. Do we have module teardown tests to make sure the GC paths are hit? You can try adding a temporary debug print statement in the |
I Added temporary sys.stderr.flush()
n = gc.collect()
sys.stderr.flush()Also I am ready with the next commit locally, please let me know when can I push it! |
|
Is the global state the only blocker for subinterpreter support or are there more nuances I am not aware of? Maybe we could add a xfailing test that adds a subinterpreter and shuts it down, I don't think it should segfault. Then in that test you could make sure it hits the code paths but still fails since we do not yet support subinterpreters. Go ahead with the next commit as well. |
73aee9d to
ac1c949
Compare
|
If someone could please "approve" Migrate npy_static_cdata to module state, then I will push the next migration commit afterwards thanks. Edit: Oops I had to push Migrate npy_global_state to per-module state since I did some minor ref in Migrate npy_static_cdata to module state |
e44a7cf to
131f8e9
Compare
|
Does this have performance overhead? I looked over the diff and didn’t see any spots where we call the function in a tight loop so I doubt there is, but I want to make sure you’re thinking about that. |
This comment was marked as outdated.
This comment was marked as outdated.
|
Why did you choose that benchmark to look at? Would you expect the changes in this PR to have a significant impact? If so, why? It’s not clear to me and I suspect you’re measuring noise. |
|
I first ran
Nope, I think it should be little to none till now atleast (this is my intuition - needs reliable testing)
Yes I was measuring noise. Here are the |
36cd184 to
5fffd0c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
00bb6af to
7f05969
Compare
…dict to per-module state
473d087 to
5a7399a
Compare
|
Dug into the remaining scattered globals ( Two categories:
Questions for you all:
None of this blocks what this PR already have, it only blocks the final |
seberg
left a comment
There was a problem hiding this comment.
Just silly comments browsing through, don't worry about them.
I suppose until there is actually more than one global state this effectively does nothing (e.g. we can't remove the guards against reloading NumPy -- although I guess the full thing there may be harder and also require dealing with heap types, etc... seems like a very long tail to get somewhere).
(I am slightly wondering if we should just almost always use an early function level state = ... even if ... is _npy_module_state for now. But it also doesn't matter here, more of a mid-term code style question.)
| * | ||
| * FIXME: Remove once all access sites receive the module or state pointer. | ||
| */ | ||
| NPY_VISIBILITY_HIDDEN extern multiarray_umath_state *_npy_module_state; |
There was a problem hiding this comment.
(pretty unrelated to merging) So I guess we mentioned it yesterday a bit, but what is the plan here, how much of this can we fix up in a relatively quick followup and how much of it is blocked/hard to do?
There was a problem hiding this comment.
I don't think this will take a lot of time, I can create 5 parallel PRs (or a single big one) for propagation and after this the FIXME can be addressed. But I am thinking if I should do limited api work first or the one I just mentioned since per module state is not requirement for LIMITED API (it is for subinterpreters).
There was a problem hiding this comment.
I would like to see progress on limited API. Can we open a follow-on issue for the remaining fixup?
| extern "C" { | ||
| #endif | ||
|
|
||
| #define NPY_INTERNED_STR_FIELDS(F) \ |
There was a problem hiding this comment.
Likely it's just the way to do it, but my first reaction to seeing this is "there should be way to avoid duplicating all fields".
There was a problem hiding this comment.
Let's address this later and merge this PR since so I can work on LIMITED API asynchronously :)
|
I'll merge this so that @prathamhole14 can work on further limited API changes, the remaining fixups can be done in follow up PRs. Thanks all for reviews. |
The global ``npy_static_pydata`` struct was migrated to per-module state in numpygh-31992, which broke the build after merging main. Co-Authored-By: Claude Fable 5.1 <[email protected]>
PR summary
Planner for this migration is this #31930 (comment), but instead of multiple PRs there will be multiple commits in this PR itself.
Related to: #31930
Request to reviewers
I am planning on having 7 major commits in this PR, first commit is for infra, then next 5 for all structs and the 7th is for scattered globals.
So at each stage before I push next commit I would like to get an approval, so I can maintain clean history and this might also turn out useful in future if we want to go back/revert a particular stage or in debugging.
CC: @mattip @ngoldbaum @rgommers
AI Disclosure
Used AI (claude and gemini) for researching and finding out what I have to work on and writing comments (intentionally asked it to make comments verbose for now -- so they can be used as trackers and later I will make them concise) other than that most of the code, logic, and architecture were written by me.