ENH: add locking to python lapacklite interface #26687
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #22509.
lapack-lite is not thread safe, with tons of static global state.
This PR adds a global lock to every call into the thread-unsafe low-level lapack-lite code. I'm sure it adds some overhead but we can ameliorate that in the future leveraging PyMutex. lapack-lite is thread-unsafe even in the standard python build, it just doesn't get hit very often, and usually in CI under odd build configurations.
With this change applied the scikit-image tests referred to in #24512, which still fail under lapacklite, pass. Ping @stefanv in case scikit-image is going out of its way to avoid lapacklite in tests.
I don't have a simple numpy-only reproducer that crashes without this change. Does anyone have a simple way to crash a non-thread-safe lapack so I can add a test?
I might make it harder to install lapack-lite in the free-threaded build as a followup.