Skip to content

Could I share my CUDA context with a PyZEDCamera? #35

Open

Description

@oha08

Though the ZED SDK provides a way to share my CUDA context with a ZED camera,
it seems that the current version of its python wrapper lacks it:

  • InitParameters::sdk_cuda_ctx
  • Camera::getCUDAContext

Is there any way to share my context with a PyZEDCamera?
I'm grad if ZED cameras could be used in CUDA applications developed on python.

Activity

  1. adujardin commented on Apr 9, 2018

    @adujardin
    Member

    Hi,
    Yes, it's a missing feature, you currently can't (without modifying the plugin).
    It is planned though. It will probably require PyCUDA.

  2. oha08 commented on Apr 10, 2018

    @oha08
    Author

    Hi,
    thank you for clarification. For now, I will try to modify the plugin to run it with PyCUDA.

  3. oha08 commented on Jun 1, 2018

    @oha08
    Author

    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 :)

  4. frk2 commented on Jul 1, 2018

    @frk2

    @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!

  5. frk2 commented on Jul 1, 2018

    @frk2

    I made a tiny cython module to do this and it works! Thanks for the tip guys!

    https://github.com/frk2/cuda-fun

  6. oha08 commented on Jul 2, 2018

    @oha08
    Author

    @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:

    1. open ZED Camera where a context is created
    2. create my context, which is automatically stacked on top of the previous context
    3. pop my context when calling ZED functions
    4. 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!

  7. frk2 commented on Jul 2, 2018

    @frk2

    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!

  8. adujardin commented on Jul 4, 2018

    @adujardin
    Member

    @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.

  9. frk2 commented on Jul 4, 2018

    @frk2

    @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!

  10. yuvalg1987 commented on Oct 3, 2021

    @yuvalg1987

    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.

  11. yuvalg1987 commented on Oct 4, 2021

    @yuvalg1987

    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.

  12. zcy1113 commented on Mar 11, 2023

    @zcy1113

    你好。我用的是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文件之后,继续重复出现这个错误,是什么原因导致的呢

  13. zcy1113 commented on Mar 11, 2023

    @zcy1113

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions