Streams

Streams#

2026-10-23

1 min read time

Applies to Linux and Windows

This page documents cuda::stream_ref and cuda::stream, which wrap a hipStream_t.

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. See Streams and concurrent execution for an introduction to HIP streams.

cuda::stream_ref#

cuda::stream_ref is a non-owning wrapper around a hipStream_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 cuda::stream_ref or hipStream_t

Availability: libhipcxx 2.7

Example:

#include <cuda/stream>

hipStream_t stream;
hipStreamCreate(&stream);
cuda::stream_ref ref{stream};

ref.sync();            // synchronizes the stream via hipStreamSynchronize
assert(ref.is_done()); // verifies that the stream has finished all operations via hipStreamQuery

// compare against other stream_ref or hipStream_t
assert(ref == stream);
assert(ref != cuda::invalid_stream);

hipStreamDestroy(stream);

cuda::stream#

cuda::stream is an owning wrapper around a hipStream_t that manages the lifetime of the underlying HIP stream. It derives from cuda::stream_ref, provides all of its functionality, and can be used anywhere a cuda::stream_ref is expected. It can be constructed for a specific cuda::device_ref, moved (but not copied), and converted from or to a hipStream_t via from_native_handle/release().

Availability: libhipcxx 3.4

#include <cuda/stream>
#include <cuda/devices>

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
}