cuda_stream_view.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <rmm/detail/export.hpp>
20 
21 #include <cuda/stream_ref>
22 #include <cuda_runtime_api.h>
23 
24 #include <cstddef>
25 #include <ostream>
26 
27 namespace RMM_EXPORT rmm {
40  public:
41  cuda_stream_view() = default;
42  ~cuda_stream_view() = default;
43  cuda_stream_view(cuda_stream_view const&) = default;
46  default;
48  default;
49 
50  // Disable construction from literal 0
51  cuda_stream_view(int) = delete; //< Prevent cast from 0
52  cuda_stream_view(std::nullptr_t) = delete; //< Prevent cast from nullptr
53 
59  cuda_stream_view(cudaStream_t stream) noexcept;
60 
66  cuda_stream_view(cuda::stream_ref stream) noexcept;
67 
73  [[nodiscard]] cudaStream_t value() const noexcept;
74 
80  operator cudaStream_t() const noexcept;
81 
87  operator cuda::stream_ref() const noexcept;
88 
92  [[nodiscard]] bool is_per_thread_default() const noexcept;
93 
97  [[nodiscard]] bool is_default() const noexcept;
98 
106  void synchronize() const;
107 
113  void synchronize_no_throw() const noexcept;
114 
115  private:
116  cudaStream_t stream_{};
117 };
118 
123 
128  cudaStreamLegacy // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
129 };
130 
135  cudaStreamPerThread // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
136 };
137 
146 
155 
163 std::ostream& operator<<(std::ostream& os, cuda_stream_view stream);
164  // end of group
166 } // namespace RMM_EXPORT rmm
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:39
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:122
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:134
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:127