cuda_stream_view.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <rmm/detail/export.hpp>
9 
10 #include <cuda/stream>
11 #include <cuda_runtime_api.h>
12 
13 #include <cstddef>
14 #include <ostream>
15 
16 RMM_NAMESPACE_BEGIN
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  [[nodiscard]] cudaStream_t get() const noexcept;
70 
76  operator cudaStream_t() const noexcept;
77 
83  operator cuda::stream_ref() const noexcept;
84 
88  [[nodiscard]] bool is_per_thread_default() const noexcept;
89 
93  [[nodiscard]] bool is_default() const noexcept;
94 
102  void synchronize() const;
103 
111  void sync() const;
112 
118  void synchronize_no_throw() const noexcept;
119 
120  private:
121  cudaStream_t stream_{};
122 };
123 
128 
133  cudaStreamLegacy // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
134 };
135 
140  cudaStreamPerThread // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
141 };
142 
151 
160 
168 std::ostream& operator<<(std::ostream& os, cuda_stream_view stream);
169  // end of group
171 RMM_NAMESPACE_END
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:127
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:139
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:132