-
Notifications
You must be signed in to change notification settings - Fork 157
Various handle-related changes and improvements #463
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
Conversation
Program
/Linker
have consistent .backend
and .handle
/ok to test |
|
||
#include <type_traits> | ||
|
||
// In cuda.bindings 12.8, the private member name was renamed from "_ptr" to "_pvt_ptr". |
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.
@vzhurba01 do you recall what prompted this change when updating to 12.8?
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.
We're using a private member? Do we own the code with the private member?
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.
Yes we own everything, they are autogen'd, for example for CUstream
:
cuda-python/cuda_bindings/cuda/bindings/driver.pxd.in
Lines 185 to 197 in 02a4178
cdef class CUstream: | |
""" | |
CUDA stream | |
Methods | |
------- | |
getPtr() | |
Get memory address of class instance | |
""" | |
cdef cydriver.CUstream _pvt_val | |
cdef cydriver.CUstream* _pvt_ptr |
hence I feel SFINAE over all possibilities is OK. I think if we accidentally change the codegen in the future, the added Cython test should be able to catch it.
This comment has been minimized.
This comment has been minimized.
/ok to test |
1 similar comment
/ok to test |
/ok to test |
/ok to test |
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 only have a few minor comments. I didn't see anything troubling, except the raise
vs pass
question maybe.
|
||
#include <type_traits> | ||
|
||
// In cuda.bindings 12.8, the private member name was renamed from "_ptr" to "_pvt_ptr". |
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.
We're using a private member? Do we own the code with the private member?
Oh wait, did the |
item = py_func(item) | ||
setattr(sys.modules[__name__], name, item) | ||
except ImportError: | ||
raise |
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.
Here it is, I accidentally lost my original comment.
Did you mean to write pass
here?
Also, it's safer to make the try-except scope as narrow as possible, e.g. (untested):
try:
# For each callable in `mod` with name `test_*`,
# wrap the callable in a plain Python function
# and set the result as an attribute of this module.
mod = importlib.import_module(mod)
except ImportError:
pass
else:
for name in dir(mod):
item = getattr(mod, name)
if callable(item) and name.startswith("test_"):
item = py_func(item)
setattr(sys.modules[__name__], name, item)
If there is any tooling that might import this file for analysis: Moving the for
loop into a function and using if __name__ == "__main__":
could guard against surprises.
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.
This file is copied/pasted from cuda-bindings. I think Vlad (or @shwina? 🙂) was the original author:
https://shwina.github.io/cython-testing/
Did you mean to write
pass
here?
I suspect the answer was yes (based on Ashwin's blog post) but perhaps it caused some issues, so it was changed to raise
? I can see that this is a cheap way to ensure the listed modules must exist and get tested. But then the whole try-except can be removed (or refactored). Perhaps @vzhurba01 can confirm the intention?
In any case, since this is a copy/paste let's change both files in a separate PR.
/ok to test |
#!/bin/bash | ||
|
||
SCRIPTPATH=$(dirname $(realpath "$0")) | ||
CPLUS_INCLUDE_PATH=$SCRIPTPATH/../../cuda/core/experimental/include:$CUDA_HOME/include:$CPLUS_INCLUDE_PATH cythonize -3 -i $(dirname "$0")/test_*.pyx |
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.
Note: This approach left a bug uncaught (fixed in commit 37a6850): Ideally, we want to have a cmdline functionality like PyBind11 that returns the header path, something like python -m cuda.core --include-path
. Here, we use the header from the local clone of this repo (hence using $SCRIPTPATH
) instead of the installed cuda.core package, meaning we do not check if the header is actually packaged (and it was not before the fix). However, I think the said functionality needs to be done in a separate PR...
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.
Example that I added to cuQuantum: https://docs.nvidia.com/cuda/cuquantum/latest/python/api/cuquantum.html#command-line-support
/ok to test |
/ok to test |
|
Close #370. Close #433.
Program
/Linker
have consistent.backend
and.handle
CXXProgram
,PTXProgram
, ... in the future without breaking changes (ExposeObjectCode
as public API + prune unnecessary input arguments #435 (comment))get_cuda_native_handle()
to fetch the underlying CUDA C object from the correspondingcuda.bindings
Python-layer object<some_cuda_core_object>.handle
get_cuda_native_handle()
, and the underlying C object is returned (no refcount or lifetime management)cuda.core
is not yet cythonized, this is currently the best solution for Python/Cython/C++ interoperability. Once we lower to Cython we can also apply a similar treatment to allcuda.core
objects.shared_ptr
or other C++ machinery to keep track of lifetime across C++ and Python. We are not there yet.cuda.bindings
is also needed (Turn allcdef class
objects in the Python layer tocdef public class
#464)cuda.bindings
infrastructure):tests/cython/test_get_cuda_native_handle.pyx
cuda/core/experimental/include/utility.hpp