| | 252 | === Streams and Events === |
| | 253 | |
| | 254 | A Cuda stream is represented as a queue of kernel instances. When a kernel is launched on a stream, a kernel instance is push onto the back of the queue, and will block until reaching the front of the queue, at which point it can begin executing. The null stream, however, must be treated differently. The null stream is the default stream and it has different semantics. Kernels enqueued on the default stream cannot be executed concurrently with any other kernels, so all kernels before a kernel in the null stream must finish before it can execute, and all kernels after a kernel in the null stream must block until it is finished. All non-null streams will be stored in a list in a _cudaContext struct. Additionally, the null stream is stored separately in a Cuda context because of its special semantics. |
| | 255 | |
| | 256 | Cuda events are a way to save a reference to a particular point in a Cuda stream. This allows events to be compared to perform timing measurements on certain actions, but more importantly, allows the programmer an additional way to synchronize streams with each and the host. Events are represented as a reference to the last kernel instance that must complete before the event is said to have occurred. |
| | 257 | |
| | 258 | A kernel instance is a struct containing the $proc that is the kernel itself and a flag indicating whether the kernel is blocked and waiting to execute, executing, or finished executing. |
| | 259 | |