-
Notifications
You must be signed in to change notification settings - Fork 14
Cuda array interface #43
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
9e356cf to
e176586
Compare
fc4cfa8 to
a6729f8
Compare
f7a5762 to
214cfbe
Compare
214cfbe to
dd33430
Compare
|
@SimonRit please review. The code has been updated to consume cuda_array_interface. Below is a quick code snippet to test: |
|
TODO:
|
7e8572b to
94dced1
Compare
SimonRit
left a comment
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.
Looks good in general. I think we need to be more general than CuPy and Torch as it can be used with many packages. We should add a few hyperlinks.
cuda_array_interface.md
Outdated
|
|
||
| ## Overview | ||
|
|
||
| ITK's `CudaImage` implements the `__cuda_array_interface__` protocol, allowing it to be used directly as a CuPy array or PyTorch tensor without copying data to/from the GPU. |
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.
Maybe make __cuda_array_interface__ an hyperlink to https://numba.pydata.org/numba-doc/0.43.0/cuda/cuda_array_interface.html
cuda_array_interface.md
Outdated
| @@ -0,0 +1,26 @@ | |||
| # CUDA Array Interface in ITK | |||
|
|
|||
| The CUDA Array Interface allows seamless interoperability between ITK's `CudaImage` and GPU arrays from libraries like CuPy and PyTorch. This enables zero-copy data sharing, efficient GPU operations, and integration with deep learning pipelines. | |||
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 would indicate in parentheses the structure names in the libraries, i.e., CuPy (cupy.ndarray) and PyTorch (torch.Tensor).
cuda_array_interface.md
Outdated
|
|
||
| ITK's `CudaImage` implements the `__cuda_array_interface__` protocol, allowing it to be used directly as a CuPy array or PyTorch tensor without copying data to/from the GPU. | ||
|
|
||
| - **Zero-copy access**: Convert `CudaImage` to CuPy/Torch views instantly. |
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 would use cupy.ndarray / torch.Tensor.
ee768ae to
22bdfbb
Compare
5b1a577 to
e19ca53
Compare
bb453c4 to
726ff1b
Compare
ba4828d to
e19ca53
Compare
e19ca53 to
726ff1b
Compare
726ff1b to
cb1e549
Compare
cb1e549 to
611b407
Compare
|
@LucasGandel I changed your wrapping/itkCudaImageFromCudaArray.py code in the last forced push because I don't think it makes sense to set buffered region without setting the other regions. @axel-grc Your examples and test, presumably based on this, have also been modified. Note that the same code with an itk.Image would crash with a seg fault. |
Prior to this commit CudaDataManager::GetGPUBufferPointer() returned a pointer to the GPU buffer pointer. Its return type should have been void**. Every usage of this method across RTK and CudaCommon dereference the returned pointer pointer, so just return the buffer pointer directly as it required for future commits adding support for __cuda_array_interface__
Adapt ITK's PyBuffer approach to inject __cuda_array_interface__ in wrapped code. Closes RTKConsortium#10
This allows modules like RTK to easily reuse files from the CudaCommon sources, e.g. CudaImage.i.init and CudaImage.i.in
Add function to create a CudaImage from an object providing __cuda_array_interface__
Allows the CPU buffer to be allocated automatically when only the GPU pointer is set on the image.
Suppresses the message: ``` ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. ```
611b407 to
2bef773
Compare
|
Thanks again @LucasGandel, time to merge! |
Adding export code to #42