Skip to content
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

Status of Cython compatibility #4

Open
lysnikolaou opened this issue Apr 8, 2024 · 6 comments
Open

Status of Cython compatibility #4

lysnikolaou opened this issue Apr 8, 2024 · 6 comments
Labels
status tracking Issue that tracks the status of compatibility and ongoing work in one or more open source projects

Comments

@lysnikolaou
Copy link

lysnikolaou commented Apr 8, 2024

First PR opened on cython/cython#6137.

This allows the test suite to run. All of the falures are related to the refnanny.

cython/cython#6147 enables vectorcall and fixes issues related to compiling in C99 mode.

@rgommers rgommers added the status tracking Issue that tracks the status of compatibility and ongoing work in one or more open source projects label Apr 10, 2024
@scoder
Copy link

scoder commented Apr 18, 2024

cython/cython#6137 was merged

@rgommers
Copy link
Member

Awesome, thanks @scoder and @lysnikolaou!

@ngoldbaum
Copy link
Contributor

I noticed today there are some cython tests that assume PyObject has an ob_refcnt field. I also saw a segfault in parallel.parallel_exc_replace, which uses with gil. It doesn't particularly surprise me that with gil is broken.

We should probably have a brainstorming session about how to deal with prange code that does with gil.

@da-woods
Copy link

We should probably have a brainstorming session about how to deal with prange code that does with gil.

I think there's a number of levels of that:

  • There's some user-code that assumes with gil can be used a lock around non-parallel bits of their code. That's never really been the right thing to do and probably isn't Cython's problem or your problem to fix.
  • There's some general Cython-generated code that isn't thread safe. That isn't specifically a prange problem since you could likely reproduce bugs with any threading mechanism. It should probably be fixed for nogil builds but it'll likely be a long process of finding the corner-cases. Avoiding borrowed references may solve a lot.
  • There's bit of Cython's internal code to do with prange/parallel that uses the GIL as a lock to juggle exception state between the Python interpreter and local variables. For that I suspect we'll need to guard it with a mutex in the nogil builds.
  • Eventually we'll probably want a nice way of doing prange that contains Python code for nogil builds (without having to wrap everything in meaningless with gil: blocks). That's a future problem since it's a new feature rather than a bugfix.

@ngoldbaum
Copy link
Contributor

Thanks for that @da-woods!

One thing in response to what you wrote:

Avoiding borrowed references may solve a lot.

This seems worth doing. Not every case is unsafe and it's probably unwise to manually convert every borrowed reference usage in human-authored C API code, but there's no reason for cython to use unsafe C API constructions when there are safe alternatives available.

I spent some time working on cython this morning and opened cython/cython#6154 to report what I found about the test suite in the nogil build.

@da-woods
Copy link

Avoiding borrowed references may solve a lot.

This seems worth doing. Not every case is unsafe and it's probably unwise to manually convert every borrowed reference usage in human-authored C API code, but there's no reason for cython to use unsafe C API constructions when there are safe alternatives available.

I meant setting the CYTHON_AVOID_BORROWED_REFS flag (which isn't perfect and doesn't cover everything but does a lot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status tracking Issue that tracks the status of compatibility and ongoing work in one or more open source projects
Projects
None yet
Development

No branches or pull requests

5 participants