Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantage of using a CUDA Stream

I am trying to understand where a Stream might help me with processing multiple Regions of Interest on a video frame. If using NPP functions that support a stream, is this a case where one would launch as many streams as there are ROIs? Possibly even creating a CPU thread for each Stream? Or is the benefit in using one stream to process all the ROIs and possibly using this single stream from multiple threads in the CPU?

like image 244
AeroClassics Avatar asked Feb 01 '17 00:02

AeroClassics


People also ask

What is CUDA stream used for?

A stream in CUDA is a sequence of operations that execute on the device in the order in which they are issued by the host code. While operations within a stream are guaranteed to execute in the prescribed order, operations in different streams can be interleaved and, when possible, they can even run concurrently.

How many CUDA streams can I have?

There is no realistic limit to the number of streams you can create (at least 1000's). However, there's a limit to the number of streams you can use effectively to achieve concurrency. In Fermi, the architecture supports 16-way concurrent kernel launches, but there is only a single connection from the host to the GPU.

What is a stream in GPU?

What is a Stream? In the context of CUDA, stream refers to a single operation sequence on a GPU device. Every CUDA kernel is invoked on an independent stream; not always true for other architectures, but true for K20 architecture. If only one kernel is invoked, the default stream, stream0, is used.

What are the opportunities of concurrency in CUDA?

First, it gives each host thread its own default stream. This means that commands issued to the default stream by different host threads can run concurrently. Second, these default streams are regular streams. This means that commands in the default stream may run concurrently with commands in non-default streams.


1 Answers

In CUDA, usage of streams generally helps to better utilize GPU in two ways. Firstly, memory copies between host and device can be overlapped by kernel execution if copying and execution occur in different streams. Secondly, individual kernels running in different streams can overlap if there are enough resources on the GPU.

Further, whether creating a thread for each ROI would help depends on comparison of GPU vs CPU (if any) utilization. If there is a lot of processing on CPU and CPU holds off GPU computation, creating more threads helps.

There are further details (see the documentation for actual version of CUDA) which constrain overlapping of operations in the streams. A memory copy overlaps with a kernel execution only if memory source or destination in RAM is page-locked. Or, synchronization between streams occurs when host thread issues command(s) in the default stream. (Since CUDA 7 each thread has its own default stream, so processing ROIs in different threads would help again.)

Hence, satisfying certain conditions, it should improve performance of your algorithm if the processing of ROIs occurs in different streams up to certain limit (depending on resource consumption of the kernels, ratio of memory copies and computation, etc...)

like image 90
stuhlo Avatar answered Sep 20 '22 04:09

stuhlo