You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Could I share my CUDA context with a PyZEDCamera? #35
Hi,
I've noticed that I can use CUDA context switching (push & pop) to run my CUDA programs with PyZED rather than trying to share the contexts, which is sufficient for my purpose.
Yet it'd be convenient if context sharing will be implemented on PyZED in future :)
@oha08 I'm new to this and trying to figure out how to do the same (I need to run a DNN and query the ZED In the same process). Any code you can share? How exactly does one switch cuda contexts? Thanks!
@frk2 Hi, Your module looks pretty nice and simple enough for working! In my case, I'm using PyCUDA to create and push/pop my context. Because PyCUDA doesn't provide any interface to get the current context, I've selected to keep the context made by ZED stacked and push my context on top of it:
open ZED Camera where a context is created
create my context, which is automatically stacked on top of the previous context
pop my context when calling ZED functions
push my context when calling my CUDA kernels (if it is popped before)
and so on
Your module enables more flexible control than this :) Thanks a lot!
I was thinking of doing the same - but the bummer is that you can't pass a created context to either ZED or Pytorch (they both create one) and hence pycuda was useless since it doesn't let me get the current context.
Thanks for the tip though definitely guided me in the right direction!
@frk2 By default the ZED SDK creates a new context, but with the C++ SDK you can pass your own context to the ZED with InitParameters::sdk_cuda_ctx.
As mentioned in the original post, this feature is missing from the python wrapper though.
@adujardin yup totally am aware - since im trying to use pytorch in the same process the simplest approach was to juggle contexts using pop and push from within python. Temporary approach till you guys add context passing through pycuda or similar. Thanks!
Any update whether context sharing is possible with ZED camera and the python API? I'm trying to work with the ZED camera an CuPy an have probably encountered an issue related to this.
Just to update on my solution for this issue. The ZED runs its own context internally and therefore processing images using CuPy should be handled in a different thread. My best solution relied on the ZED-TensorFlow example which worked pretty good.
Hello. I use a zed camera, and the cuda is 11.7. When I run the get_python_api.py file, I am prompted with permission error: [errno13] Permission denied:' C: \ \ Program files (x86) \ \ ZED SDK \ \ PYZED-3.8-CP39-CP39-Win-amd64.whl', but after installing the whl file, what causes this error to appear repeatedly?
Activity
adujardin commentedon Apr 9, 2018
Hi,
Yes, it's a missing feature, you currently can't (without modifying the plugin).
It is planned though. It will probably require PyCUDA.
oha08 commentedon Apr 10, 2018
Hi,
thank you for clarification. For now, I will try to modify the plugin to run it with PyCUDA.
oha08 commentedon Jun 1, 2018
Hi,
I've noticed that I can use CUDA context switching (push & pop) to run my CUDA programs with PyZED rather than trying to share the contexts, which is sufficient for my purpose.
Yet it'd be convenient if context sharing will be implemented on PyZED in future :)
frk2 commentedon Jul 1, 2018
@oha08 I'm new to this and trying to figure out how to do the same (I need to run a DNN and query the ZED In the same process). Any code you can share? How exactly does one switch cuda contexts? Thanks!
frk2 commentedon Jul 1, 2018
I made a tiny cython module to do this and it works! Thanks for the tip guys!
https://github.com/frk2/cuda-fun
oha08 commentedon Jul 2, 2018
@frk2 Hi, Your module looks pretty nice and simple enough for working! In my case, I'm using PyCUDA to create and push/pop my context. Because PyCUDA doesn't provide any interface to get the current context, I've selected to keep the context made by ZED stacked and push my context on top of it:
and so on
Your module enables more flexible control than this :) Thanks a lot!
frk2 commentedon Jul 2, 2018
I was thinking of doing the same - but the bummer is that you can't pass a created context to either ZED or Pytorch (they both create one) and hence pycuda was useless since it doesn't let me get the current context.
Thanks for the tip though definitely guided me in the right direction!
adujardin commentedon Jul 4, 2018
@frk2 By default the ZED SDK creates a new context, but with the C++ SDK you can pass your own context to the ZED with InitParameters::sdk_cuda_ctx.
As mentioned in the original post, this feature is missing from the python wrapper though.
frk2 commentedon Jul 4, 2018
@adujardin yup totally am aware - since im trying to use pytorch in the same process the simplest approach was to juggle contexts using pop and push from within python. Temporary approach till you guys add context passing through pycuda or similar. Thanks!
yuvalg1987 commentedon Oct 3, 2021
Any update whether context sharing is possible with ZED camera and the python API? I'm trying to work with the ZED camera an CuPy an have probably encountered an issue related to this.
yuvalg1987 commentedon Oct 4, 2021
Just to update on my solution for this issue. The ZED runs its own context internally and therefore processing images using CuPy should be handled in a different thread. My best solution relied on the ZED-TensorFlow example which worked pretty good.
zcy1113 commentedon Mar 11, 2023
你好。我用的是zed相机,cuda是11.7, 运行get_python_api.py文件时,提示PermissionError: [Errno 13] Permission denied: 'C:\Program Files (x86)\ZED SDK\pyzed-3.8-cp39-cp39-win_amd64.whl',但是安装whl文件之后,继续重复出现这个错误,是什么原因导致的呢
zcy1113 commentedon Mar 11, 2023
Hello. I use a zed camera, and the cuda is 11.7. When I run the get_python_api.py file, I am prompted with permission error: [errno13] Permission denied:' C: \ \ Program files (x86) \ \ ZED SDK \ \ PYZED-3.8-CP39-CP39-Win-amd64.whl', but after installing the whl file, what causes this error to appear repeatedly?