Multithreading WIth Jetson Utilities Library (jetson-utils)?


Is it possible to use the Jetson C++ Utilities library as is, with a multithreaded application where multiple calls are being made to the cuda convenience libraries on separate threads? Or is a cuda stream required? If it is possible, are there any example available of this? If not, any examples of how to do this?


Hi @catch22, the CUDA functions from jetson-utils don’t currently take a cudaStream parameter from the user to run their kernel(s) on (although I’ll add that) - although I’m not sure that they’re strictly required, it’d probably be advised to use multiple streams if possible. Is there an error or issue you are having?

Hi @dusty_nv , Thanks for the response, I’m trying to manipulate multiple camera streams at once with separate threads for each one. The threads are doing the same processing, but concurrently accessing the GPU using the jetson cuda utility library, (resize, crop, ect…). I’m wondering if this is okay to do with multiple threads, or will it cause problems with GPU access? I’m fairly new to cuda programming in general and GPU multithreaded access. Note, I could use a mutex lock to protect the GPU but I really need the threads to be able to run and process as fast as they can. Thanks!

@catch22 in theory yes, you should be able to run multiple CPU threads each launching CUDA kernels to the same CUDA stream (in this case the default/NULL CUDA stream). Those CUDA kernels won’t run concurrently though, and you can use cudaEvents/cudaEventSynchronize to synchronize your application as opposed to CPU locks.

What I would probably do is architect your application in such a way that you can run the cameras either in their own thread or the same thread (the camera aquisition/capture itself is already multithreaded through GStreamer), and test both ways. There is also a threading class from jetson-utils that you can use:

You may also be interested to check out DeepStream because it’s more optimized for multi-camera applications.

Thanks Dusty!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.