Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Allow access to CUDA pointers for interoperability with other libraries#16513
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
leofang commentedFeb 7, 2020
Hi@pwuertz, thanks for joining the discussion on Numba. I don't have comment for your effort here (yet), but I'd like to kindly ask that when this PR (and any subsequent ones) is merged, it'd be nice if you could follownumba/numba#5104 and add opencv to the list 🙂 Thank you. |
alalek commentedFeb 10, 2020
I believe it should own upstream |
pwuertz commentedFeb 10, 2020
@alalek Please note that For out-of-the-box interoperability with other libraries like Numba and Cupy I was planning on implementing the CUDA array interface (CAI) in a follow-up PR. As described earlier, I'm having trouble figuring out some OpenCV python binding generator details though. Also note that within the current CAI specification (version 2), the responsibility for lifetime and synchronization resides with the user (similar to using cv::Mat constructors with data pointers). If this changes in some future version I'd be willing to update the CAI version on the OpenCV side of course. |
| operatorbool_type()const; | ||
| //! return Pointer to CUDA stream | ||
| CV_WRAPvoid*cudaPtr()const; |
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.
There isStreamAccessor to do it:https://docs.opencv.org/master/d6/df1/structcv_1_1cuda_1_1StreamAccessor.html. I think it's better to wrap accessor rather expose private fields.
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.
StreamAccessor
Not sure that this can help to reach the final goal:
to implement
__cuda_array_interface__within theGpuMatpython binding
| inline | ||
| void*GpuMat::cudaPtr()const | ||
| { | ||
| return data; |
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.
There isCV_PROP_RW macro that allows to expose object properties to Python and other languages. You do not need own method for it.
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 believe current approach is fine.
We should not allow changing of this pointer throughCV_PROP_RW.
pwuertz commentedFeb 14, 2020
|
pwuertz commentedFeb 14, 2020
@alalek It's true that # allocated dataX_cpu, dataX_gpu_cv, stream_cv# (proof of principle numba views dataX_gpu_nb, stream_nb)t1=time.time()data1_gpu_cv.upload(arr=data1_cpu,stream=stream_cv)# OpenCV uploadkernel_nb(data1_gpu_nb,out=data2_gpu_nb,stream=stream_nb)# Numba operationdata2_gpu_cv.download(dst=data2_cpu,stream=stream_cv)# OpenCV downloadt2=time.time()# CPU time: 0.001 sstream_nb.synchronize()t3=time.time()# GPU time: 0.042 s# verified data2_cpu So you can freely mix OpenCV and Numba operations on a single, fully async stream. @asmorkalov Oh sorry, haven't noticed the |
pwuertz commentedFeb 14, 2020
@asmorkalov Even with How to proceed? Using |
alalek 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 to me 👍
Uh oh!
There was an error while loading.Please reload this page.
This is a proposal for adding
CV_WRAPcompatiblecudaPtr()getter methods toGpuMatandStream, required for enabling interoperability betweenOpenCV and other CUDA supporting python libraries likeNumba,CuPy,PyTorch, etc.Here is an example for sharing a
GpuMatwithCuPy:In this example
CudaArrayInterfaceis a (incomplete) adapter class that implements thecuda array interface used by other frameworks:If possible, I'd like to implement
__cuda_array_interface__within theGpuMatpython binding in a future PR (not sure how to define a python property using the wrapper generator though).