Uh oh!
There was an error while loading. Please reload this page.
Various handle-related changes and improvements - #463
Conversation
Program/Linker have consistent .backend and .handleleofang
commented
Feb 24, 2025
/ok to test |
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
leofang
commented
Feb 24, 2025
/ok to test |
1 similar comment
leofang
commented
Feb 24, 2025
/ok to test |
leofang
commented
Feb 24, 2025
/ok to test |
leofang
commented
Feb 24, 2025
/ok to test |
rwgk
left a comment
There was a problem hiding this comment.
I only have a few minor comments. I didn't see anything troubling, except the raise vs pass question maybe.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rwgk
commented
Feb 24, 2025
Oh wait, did the |
| item = py_func(item) | ||
| setattr(sys.modules[__name__], name, item) | ||
| except ImportError: | ||
| raise |
There was a problem hiding this comment.
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.
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
passhere?
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.
Uh oh!
There was an error while loading. Please reload this page.
leofang
commented
Feb 24, 2025
/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.
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.
Example that I added to cuQuantum: https://docs.nvidia.com/cuda/cuquantum/latest/python/api/cuquantum.html#command-line-support
Uh oh!
There was an error while loading. Please reload this page.
leofang
commented
Feb 24, 2025
/ok to test |
rwgk
commented
Feb 25, 2025
/ok to test |
|
Close#370. Close#433.
Program/Linkerhave consistent.backendand.handleCXXProgram,PTXProgram, ... in the future without breaking changes (ExposeObjectCodeas public API + prune unnecessary input arguments #435 (comment))get_cuda_native_handle()to fetch the underlying CUDA C object from the correspondingcuda.bindingsPython-layer object<some_cuda_core_object>.handleget_cuda_native_handle(), and the underlying C object is returned (no refcount or lifetime management)cuda.coreis 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.coreobjects.shared_ptror other C++ machinery to keep track of lifetime across C++ and Python. We are not there yet.cuda.bindingsis also needed (Turn allcdef classobjects in the Python layer tocdef public class#464)cuda.bindingsinfrastructure):tests/cython/test_get_cuda_native_handle.pyxcuda/core/experimental/include/utility.hpp