# Using different CUDA devices for different dnn::Net

**URL:** <https://forum.opencv.org/t/using-different-cuda-devices-for-different-dnn-net/4179>\
**Category:** C++\
**Tags:** dnn, cuda\
**Created:** [July 5, 2021, 3:54pm UTC](https://forum.opencv.org/t/using-different-cuda-devices-for-different-dnn-net/4179 "2021-07-05T15:54:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielEliasibTW](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/danieleliasibtw/32/2582_2.png) [@DanielEliasibTW](https://forum.opencv.org/u/DanielEliasibTW)\
**Post date:** [July 5, 2021, 3:54pm UTC](https://forum.opencv.org/t/using-different-cuda-devices-for-different-dnn-net/4179/1 "2021-07-05T15:54:03Z")

</div>

Hi.  
I’m working on a project that loads several NN as `dnn::Net` objects were speed it’s an important factor, so I’m trying to figure out if I can spread the work to different CUDA devices.

I searched the internet and found that you can select what CUDA device you want to use with `cv::cuda::setDevice` but, I was wondering if this would work trying to load two different `dnn::Net` to different CUDA devices, would I have to call `setDevice` every time before calling forward in the respective `dnn::Net`, or once loaded with a specific device the `dnn::Net` will use it’s assigned device automatically. Or maybe this is not even posible with OpenCV, I can’t seem to find a answer for this.

Right now I’m unable to test this because I only have one GPU, but as mention before speed is a priority for this project so I’m trying to figure out if I could spread the work on different devices before buying another GPU.

Anyway, Thank you.

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [July 6, 2021, 8:08am UTC](https://forum.opencv.org/t/using-different-cuda-devices-for-different-dnn-net/4179/2 "2021-07-06T08:08:15Z")

</div>

That’s an interesting question, I have never tried it in the same thread but I can’t think of a reason why it wouldn’t work. It should definitely works in separate threads, at least it works 100% for standard CUDA functions.

It should be easy for you to try?

---

<div class="post-metadata">

**Author:** ![DanielEliasibTW](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/danieleliasibtw/32/2582_2.png) [@DanielEliasibTW](https://forum.opencv.org/u/DanielEliasibTW)\
**Post date:** [July 6, 2021, 4:43pm UTC](https://forum.opencv.org/t/using-different-cuda-devices-for-different-dnn-net/4179/3 "2021-07-06T16:43:57Z")

</div>

Thank you for your answer. I also think it would be fairly easy to test but right now I only have one graphics card and with current prices I don’t think I can get one just to test this theory.

It’s good to know that it’s probably posible when I’m able to get one.
