cuda::stream_ref: a wrapper around a hipStream_t

cuda::stream_ref: a wrapper around a hipStream_t#

2026-10-07

1 min read time

Applies to Linux and Windows

This page documents cuda::stream_ref, a type-safe wrapper around hipStream_t that prevents implicit conversions and provides wait and ready member functions.

HIP stream-ordered allocations rely on hipStream_t as a handle to the HIP stream.

However, as this is just an alias for a plain pointer type it carries with it common pitfalls around implicit conversions from, for example, nullptr or a literal 0.

These hard to spot bugs can be avoided through cuda::stream_ref, which is a simple wrapper around a hipStream_t that prevents implicit conversions. It also provides the wait() and ready() member functions to facilitate waiting for a stream to finish and checking whether it is finished.

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

ref.wait();          // synchronizes the stream via hipStreamSynchronize
assert(ref.ready()); // verifies that the stream has finished all operations via hipStreamQuery
hipStreamDestroy(stream);