-
Notifications
You must be signed in to change notification settings - Fork 200
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
Add a missed except *
#1057
Add a missed except *
#1057
Conversation
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. (Also I fixed the title of the PR.)
I discovered while reviewing that except +
is for C++ exceptions and except *
is for Python exceptions! That was new to me - I hadn't used except *
before, only except +
.
You can also do things like |
rerun tests |
@@ -344,7 +344,7 @@ cdef void _copy_async(const void* src, | |||
void* dst, | |||
size_t count, | |||
ccudart.cudaMemcpyKind kind, | |||
cuda_stream_view stream) nogil: | |||
cuda_stream_view stream) nogil except *: |
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 except *
compatible with nogil
? Or are we holding the GIL when raising that exception
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.
Nice catch, John! Should this function even be marked nogil
? It clearly needs the GIL to raise the RuntimeError
that it does
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.
Yeah it's an interesting question. Was thinking this might be permissible, but maybe only in Cython 3 ( cython/cython#3558 )
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.
Suppose there are a few options:
- Drop the
nogil
- Use a
with gil
block in this function if an error comes up - Return
-1
(or the error code) and raise outside this function - ?
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.
Good call, I didn't even think about that. I think we should probably not mark the function nogil, but just wrap the cudaMemcpyAsync
call in a with nogil
block.
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.
Sounds good to me
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.
It's worth noting there is some overhead to releasing the GIL. So if the function is fast, it might not be worth releasing the GIL.
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.
I think we can leave this as nogil
even with the raise
?
Oh, and the
with gil:
is no longer required for the raise since 0.29. It's injected automatically whenraise
is used in anogil
section.
Also confirmed in this Changelog entry from 0.29:
Raising exceptions from nogil code will automatically acquire the GIL, instead of requiring an explicit
with gil
block.
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 Bradley! 🙏
Was looking for that text in the docs as I was thinking that might be the case, but only found it in relation to 3.0.0. Missed the changelog entry.
As we already require Cython 0.29 as a minimum, we should be good here.
@gpucibot merge |
No description provided.