CUDA:Stream
lastmod 2024-08-14created 2017-08-179 edits
Checking support
Device overlap must be supported.
cudaDeviceProp prop;
int nDevice;
cudaGetDevice(&nDevice);
cudaGetDeviceProperties(&prop, nDevice);
if (!prop.deviceOverlap)
printf("Device will not handle overlaps, so no"
"speed up from streams \n");
Synchronization
- cudaDeviceSynchronize
- Use when you need to synchronize the operations in a stream with host code.
- Blocks host code until all previously started operations on the device have finished.
- Therefore, using this function stalls other device threads or host threads, degrading performance.
- cudaStreamSynchronize(stream)
- Blocks the host thread until all operations started in a particular stream have finished.
- cudaStreamQuery(stream)
- Lets you test whether all operations in a particular stream have finished.
- cudaEventSynchronize(event), cudaEventQuery(event)
- Synchronizes using whether a particular event has been recorded.
- cudaStreamWaitEvent(event)
- Lets you synchronize the operations in a stream with a particular event.