-
Notifications
You must be signed in to change notification settings - Fork 201
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
Fix rmm ._lib
imports
#1693
Fix rmm ._lib
imports
#1693
Conversation
# limitations under the License. | ||
|
||
from rmm.pylibrmm.memory_resource import ( # noqa: F401 | ||
BinningMemoryResource, |
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.
These classes are cdef
'd, why are they importable from python? Should they be cpdef
'd?
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 cdef class
is a normal python class that can also hold C properties. (https://cython.readthedocs.io/en/latest/src/tutorial/cdef_classes.html)
cpdef
is for (predominantly) functions which should have a "fast-path" calling route from typed code in cython, and also a "slow-path" python-like calling route.
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.
So its only cpdef
functions that can be called from C and Python?
Edit: I think that's true https://cython.readthedocs.io/en/latest/src/userguide/pyrex_differences.html#cpdef-functions
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.
Not exactly.
- cdef functions can only be called from Cython and in typed contexts (i.e. you cannot pass arbitrary Python objects to them, you need to pass objects that have already been cdefed appropriately themselves).
- def functions can be called from Python or Cython. They are pure Python functions, so all arguments are treated as normal Python objects.
- cpdef functions can be called from Python or Cython. When called from Python, they behave like def functions. When called from Cython with untyped arguments, they also behave like def functions. When called from Cython with typed arguments, they behave like cdef functions.
There's more information here.
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.
Thanks for the clarification (def and cpdef make sense to me). Can you give an example of a "typed context"?
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.
Can a typed context be in a *.py file?
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.
Is it the body of cpdef and cdef functions/methods?
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.
cdef class A:
cpdef class f(self):
pass
A().f() # Called like a Python def function
cdef A a = A()
a.f() # Called like a cdef function.
So no, a typed context cannot be in a *.py file, or at least not in the way that we use Cython. With newer versions of Cython you can use py files and compile them too, but the point is that you have to use Cython-specific syntax.
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.
LGTM. I notice that helper.py is missing, but since that only contains a cdef function it's correct not to have it here since it doesn't expose anything that would be visible to Python.
I'm going to go ahead and merge because this is currently breaking some users. If we have more changes that we want, we can address them in follow-ups, but I'd like to be able to experiment ASAP to make sure that the underlying issues are resolved in all cases. |
/merge |
Description
This PR fixes a bug in #1676. It makes sure that rmm imports work correctly using both
from rmm._lib...
andimport rmm._lib...
syntax.Checklist