cuda_stream_view.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <rmm/detail/export.hpp>
9 
10 #include <cuda/stream_ref>
11 #include <cuda_runtime_api.h>
12 
13 #include <cstddef>
14 #include <ostream>
15 
16 namespace RMM_EXPORT rmm {
29  public:
30  cuda_stream_view() = default;
31  ~cuda_stream_view() = default;
32  cuda_stream_view(cuda_stream_view const&) = default;
35  default;
37  default;
38 
39  // Disable construction from literal 0
40  cuda_stream_view(int) = delete; //< Prevent cast from 0
41  cuda_stream_view(std::nullptr_t) = delete; //< Prevent cast from nullptr
42 
48  cuda_stream_view(cudaStream_t stream) noexcept;
49 
55  cuda_stream_view(cuda::stream_ref stream) noexcept;
56 
62  [[nodiscard]] cudaStream_t value() const noexcept;
63 
69  operator cudaStream_t() const noexcept;
70 
76  operator cuda::stream_ref() const noexcept;
77 
81  [[nodiscard]] bool is_per_thread_default() const noexcept;
82 
86  [[nodiscard]] bool is_default() const noexcept;
87 
95  void synchronize() const;
96 
102  void synchronize_no_throw() const noexcept;
103 
104  private:
105  cudaStream_t stream_{};
106 };
107 
112 
117  cudaStreamLegacy // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
118 };
119 
124  cudaStreamPerThread // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
125 };
126 
135 
144 
152 std::ostream& operator<<(std::ostream& os, cuda_stream_view stream);
153  // end of group
155 } // namespace RMM_EXPORT rmm
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:28
cuda_stream_view(cuda_stream_view &&)=default
Default move constructor.
cuda_stream_view & operator=(cuda_stream_view &&)=default
Default move assignment operator.
cuda_stream_view & operator=(cuda_stream_view const &)=default
Default copy assignment operator.
cuda_stream_view(cuda_stream_view const &)=default
Default copy constructor.
cuda_stream_view(cudaStream_t stream) noexcept
Constructor from a cudaStream_t.
cudaStream_t value() const noexcept
Get the wrapped stream.
cuda_stream_view(cuda::stream_ref stream) noexcept
Implicit conversion from stream_ref.
bool operator==(cuda_stream_view lhs, cuda_stream_view rhs)
Equality comparison operator for streams.
static constexpr cuda_stream_view cuda_stream_default
Static cuda_stream_view of the default stream (stream 0), for convenience.
Definition: cuda_stream_view.hpp:111
std::ostream & operator<<(std::ostream &os, cuda_stream_view stream)
Output stream operator for printing / logging streams.
static const cuda_stream_view cuda_stream_per_thread
Static cuda_stream_view of cudaStreamPerThread, for convenience.
Definition: cuda_stream_view.hpp:123
bool operator!=(cuda_stream_view lhs, cuda_stream_view rhs)
Inequality comparison operator for streams.
static const cuda_stream_view cuda_stream_legacy
Static cuda_stream_view of cudaStreamLegacy, for convenience.
Definition: cuda_stream_view.hpp:116