DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

image/docs/usecase4.md
Go to the documentation of this file.
1 # Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
2 
3 @page image_usecase4 Image Streamer Multi-Thread
4 @tableofcontents
5 
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 
8 In addition to using the ImageStreamer module in a [single thread](@ref image_usecase2), you can also use it across multiple threads.
9 
10 This workflow is similar to the single thread case since the same APIs are thread safe.<br>
11 For details on how to stream an image from CPU to CUDA memory, please refer to \n @ref image_usecase2. All other details are left out of this tutorial for simplicity.
12 
13 @section image_usecase4_threadA Initializing the ImageStreamer Module in Thread A
14 
15 In the following example, the ImageStreamer is initialized in Thread A before it is used to send images:
16 
17 ```{.cpp}
18  // Thread A:
19  // streamer from CPU to CUDA
20  dwImageStreamerHandle_t streamerCPU2CUDA = DW_NULL_HANDLE;
21 
22  dwImageStreamer_initialize(streamerCPU2CUDA, &cpuProp, DW_IMAGE_CUDA, dwContext);
23  while(true)
24  {
25  // CODE: Get an image to stream
26  dwImageStreamer_producerSend(imgCPU, streamerCPU2CUDA);
27  dwImageStreamer_producerReturn(nullptr, TIMEOUT, streamerCPU2CUDA);
28  }
29 ```
30 
31 @section image_usecase4_retrieving_output Retrieving the Output from Thread B
32 
33 After sending the images from Thread A, retrieve the output from Thread B:
34 
35 ```{.cpp}
36  // Thread B:
37  while(true)
38  {
39  dwImageStreamer_consumerReceive(&imageCuda, TIMEOUT, streamerCPU2CUDA);
40  // CODE: Use the streamed image
41  dwImageStreamer_consumerReturn(&imageCuda, streamerCPU2CUDA);
42  }
43 ```
44 
45 @section image_usecase4_releasing_handle Releasing the Handle
46 
47 ```
48 dwImageStreamer_release(...);
49 ```
50 
51 To see a full demonstration of this workflow, please refer to @ref dwx_image_streamer_multi_sample.