-
Notifications
You must be signed in to change notification settings - Fork 43
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
Support releasing the GIL in the cython algorithms #226
Comments
Having something builtin to Cython that allows us to do this would be good. One potential option - though a bit inefficient - would be to split this into 3 loops:
We'd always have the latter 2 loops (depending on return type), and looping over pointers should be pretty fast, so this seems potentially better than having to hold the |
I found another potential issue: Provided I'm seeing this correctly, this means that we should not declare the exception value for GEOS functions within I think the fix is simply to state the exception value in a comment next to the declaration in |
Correction: it looks fine to declare the exception value for GEOS functions; these do not automatically require use of the It looks like we can have avoid
Not sure of the performance implications of this, but the compiler allowed this, and testing it produced the expected |
Indeed, that's the typical way to raise exceptions in a nogil block (see also my example linked in the top post where I use the same pattern). This shouldn't have a performance impact, at least not yet for the typical case you care about when no errors are raised, as this |
As a follow-up on #197, we can investigate if we can release the GIL in the cython with similar tricks as in the C code.
In any case, just putting a
with nogil:
context around the for loop does not work, as cython does not allow accessing elements in an object dtype numpy array in a nogil context.We might need to discuss this with the cython team about ways to force cython to allow this (in cases the user can guarantee this doesn't give problems, a bit similar like the
@cython.boundscheck(False)
also disables safety checks giving the developer the responsibility to not violate the assumptions).I was experimenting with this using a small toy example (that doesn't involve the full GEOS/pygeos setup, and so easier to discuss with cython people as well): an object array of floats (where the actual C floating point value is also accessible on the PyObjec struct, similarly as our GEOS pointer): https://nbviewer.jupyter.org/gist/jorisvandenbossche/b03bfe660d02eb43922cd632f3fa9857
The text was updated successfully, but these errors were encountered: