cudaStreamWaitEvent()Up to this point, all of the synchronization functions described in this chapter have pertained to CPU/GPU synchronization. They either wait for or query the status of a GPU operation.
| Function | Description |
|---|---|
cuCtxSynchronize()/ | Wait until GPU is idle. |
cudaDeviceSynchronize() | | |
|
cu(da)EventQuery() |
Check if event has been recorded. |
cu(da)EventSynchronize() |
Wait until event has been recorded. |
cu(da)StreamSynchronize() |
Wait until all operations in stream have completed. |
cu(da)StreamQuery() |
Check if all operations in stream are completed. |
Another function, cudaStreamWaitEvent(), is asynchronous with respect
to the CPU and causes the specified stream to wait until an event has
been recorded. The stream and event need not be associated with the same
CUDA device; Section 9.3 describes how such inter-GPU synchronization
may be performed and uses the feature to implement a peer-to-peer memcpy
(Listing 9-1).
Streams and events exist in the scope of the context (or device)
– when cuCtxDestroy() or cudaDeviceReset() is called, the associated
streams and events are destroyed.
Kernel launches and cu(da)EventRecord() can only use CUDA streams
in the same context/device.
cudaMemcpy() can be called with any stream, but it is best to
call it from the source context/device.
cudaStreamWaitEvent() may be called on any event, using any
stream.