19 #include <rmm/cuda_stream_view.hpp>
20 #include <rmm/detail/error.hpp>
22 #include <cuda_runtime_api.h>
60 auto* stream =
new cudaStream_t;
61 RMM_CUDA_TRY(cudaStreamCreate(stream));
64 [](cudaStream_t* stream) {
65 RMM_ASSERT_CUDA_SUCCESS(cudaStreamDestroy(*stream));
77 [[nodiscard]]
bool is_valid()
const {
return stream_ !=
nullptr; }
84 [[nodiscard]] cudaStream_t
value()
const
93 explicit operator cudaStream_t() const noexcept {
return value(); }
125 RMM_ASSERT_CUDA_SUCCESS(cudaStreamSynchronize(
value()));
129 std::unique_ptr<cudaStream_t, std::function<void(cudaStream_t*)>> stream_;
void synchronize() const
Synchronize the owned CUDA stream.
Definition: cuda_stream.hpp:116
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:34
bool is_valid() const
Returns true if the owned stream is non-null.
Definition: cuda_stream.hpp:77
cuda_stream & operator=(cuda_stream &&)=default
Move copy assignment operator (default)
cuda_stream()
Construct a new cuda stream object.
Definition: cuda_stream.hpp:58
cuda_stream_view view() const
Creates an immutable, non-owning view of the wrapped CUDA stream.
Definition: cuda_stream.hpp:100
cuda_stream(cuda_stream &&)=default
Move constructor (default)
Owning wrapper for a CUDA stream.
Definition: cuda_stream.hpp:33
cudaStream_t value() const
Get the value of the wrapped CUDA stream.
Definition: cuda_stream.hpp:84
void synchronize_no_throw() const noexcept
Synchronize the owned CUDA stream. Does not throw if there is an error.
Definition: cuda_stream.hpp:123