19 #include <rmm/detail/error.hpp>
21 #include <cuda_runtime_api.h>
23 #include <cuda/stream_ref>
68 constexpr
cuda_stream_view(cuda::stream_ref stream) noexcept : stream_{stream.get()} {}
75 [[nodiscard]] constexpr cudaStream_t
value() const noexcept {
return stream_; }
82 constexpr
operator cudaStream_t() const noexcept {
return value(); }
89 constexpr
operator cuda::stream_ref() const noexcept {
return value(); }
99 [[nodiscard]] inline
bool is_default() const noexcept;
108 void synchronize()
const { RMM_CUDA_TRY(cudaStreamSynchronize(stream_)); }
117 RMM_ASSERT_CUDA_SUCCESS(cudaStreamSynchronize(stream_));
121 cudaStream_t stream_{};
127 static constexpr cuda_stream_view cuda_stream_default{};
133 static const cuda_stream_view cuda_stream_legacy{
140 static const cuda_stream_view cuda_stream_per_thread{
149 #ifdef CUDA_API_PER_THREAD_DEFAULT_STREAM
150 return value() == cuda_stream_per_thread ||
value() ==
nullptr;
152 return value() == cuda_stream_per_thread;
158 #ifdef CUDA_API_PER_THREAD_DEFAULT_STREAM
159 return value() == cuda_stream_legacy;
161 return value() == cuda_stream_legacy ||
value() ==
nullptr;
200 os << stream.
value();
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
constexpr cudaStream_t value() const noexcept
Get the wrapped stream.
Definition: cuda_stream_view.hpp:75
void synchronize() const
Synchronize the viewed CUDA stream.
Definition: cuda_stream_view.hpp:108
constexpr cuda_stream_view & operator=(cuda_stream_view const &)=default
Default copy assignment operator.
constexpr cuda_stream_view & operator=(cuda_stream_view &&)=default
Default move assignment operator.
constexpr cuda_stream_view(cudaStream_t stream) noexcept
Constructor from a cudaStream_t.
Definition: cuda_stream_view.hpp:61
constexpr cuda_stream_view(cuda::stream_ref stream) noexcept
Implicit conversion from stream_ref.
Definition: cuda_stream_view.hpp:68
bool is_per_thread_default() const noexcept
true if the wrapped stream is the CUDA per-thread default stream
Definition: cuda_stream_view.hpp:147
constexpr cuda_stream_view(cuda_stream_view &&)=default
Default move constructor.
void synchronize_no_throw() const noexcept
Synchronize the viewed CUDA stream. Does not throw if there is an error.
Definition: cuda_stream_view.hpp:115
bool is_default() const noexcept
true if the wrapped stream is explicitly the CUDA legacy default stream
Definition: cuda_stream_view.hpp:156
constexpr cuda_stream_view(cuda_stream_view const &)=default
Default copy constructor.
bool operator==(cuda_stream_view lhs, cuda_stream_view rhs)
Equality comparison operator for streams.
Definition: cuda_stream_view.hpp:177
std::ostream & operator<<(std::ostream &os, cuda_stream_view stream)
Output stream operator for printing / logging streams.
Definition: cuda_stream_view.hpp:198
bool operator!=(cuda_stream_view lhs, cuda_stream_view rhs)
Inequality comparison operator for streams.
Definition: cuda_stream_view.hpp:189