.. _cccl-runtime-stream: Streams ======== Stream is conceptually a queue of operations for a specific device. It is passed as an argument to all asynchronous operations like kernel launch, memory copy and allocations. :cpp:class:`cuda::stream_ref` ------------------------------- .. _cccl-runtime-stream-stream-ref: :cpp:class:`cuda::stream_ref` is a non-owning wrapper around a ``cudaStream_t``. It prevents unsafe implicit constructions from ``nullptr`` or integer literals and provides convenient helpers for: - ``sync()``: wait for the recorded work to complete - ``is_done()``: non-blocking completion query - comparison operators against other :cpp:class:`cuda::stream_ref` or ``cudaStream_t`` Availability: CCCL 2.2.0 / CUDA 12.3 Example: .. code:: cpp #include cudaStream_t stream; cudaStreamCreate(&stream); cuda::stream_ref ref{stream}; ref.sync(); // synchronizes the stream via cudaStreamSynchronize assert(ref.is_done()); // verifies that the stream has finished all operations via cudaStreamQuery // compare against other stream_ref or cudaStream_t assert(ref == stream); assert(ref != cuda::invalid_stream); cudaStreamDestroy(stream); :cpp:struct:`cuda::stream` --------------------------- .. _cccl-runtime-stream-stream: :cpp:struct:`cuda::stream` is an owning wrapper around a ``cudaStream_t`` that manages the lifetime of the underlying CUDA stream. It derives from :cpp:class:`cuda::stream_ref`, provides all of its functionality, and can be used anywhere a :cpp:class:`cuda::stream_ref` is expected. It can be constructed for a specific :cpp:class:`cuda::device_ref`, moved (but not copied), and converted from or to a ``cudaStream_t`` via ``from_native_handle``/``release()``. Constructing a new :cpp:struct:`cuda::stream` always creates a non-blocking stream; see :ref:`non-blocking stream creation ` for CUDA Runtime interop details. Availability: CCCL 3.1.0 / CUDA 13.1 .. code:: cpp #include #include int main() { { // Create a stream on a specific device cuda::stream s{cuda::devices[0]}; // Pass to a stream-ordered API // Synchronize the stream s.sync(); } // Stream is automatically destroyed here }