cuda_stream.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 
9 #include <rmm/detail/export.hpp>
10 
11 #include <cuda/stream>
12 #include <cuda_runtime_api.h>
13 
14 #include <functional>
15 #include <memory>
16 
17 RMM_NAMESPACE_BEGIN
29 class cuda_stream {
30  public:
34  enum class flags : unsigned int {
35  sync_default = cudaStreamDefault,
36  non_blocking =
37  cudaStreamNonBlocking,
38  };
45  cuda_stream(cuda_stream&&) = default;
55  ~cuda_stream() = default;
56  cuda_stream(cuda_stream const&) = delete; // Copying disallowed: one stream one owner
57  cuda_stream& operator=(cuda_stream&) = delete;
58 
66  cuda_stream(cuda_stream::flags flags = cuda_stream::flags::sync_default);
67 
74  [[nodiscard]] bool is_valid() const;
75 
81  [[nodiscard]] cudaStream_t value() const;
82 
86  explicit operator cudaStream_t() const noexcept;
87 
88 #if defined(__GNUC__) || defined(__clang__)
89 #pragma GCC diagnostic push
90 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
91 #endif
92 
100  [[nodiscard, deprecated("Use conversion to cuda::stream_ref instead.")]] cuda_stream_view view()
101  const;
102 
110  [[deprecated("Use conversion to cuda::stream_ref instead.")]] operator cuda_stream_view() const;
111 
112 #if defined(__GNUC__) || defined(__clang__)
113 #pragma GCC diagnostic pop
114 #endif
115 
121  operator cuda::stream_ref() const noexcept;
122 
130  void synchronize() const;
131 
137  void synchronize_no_throw() const noexcept;
138 
139  private:
140  std::unique_ptr<cudaStream_t, std::function<void(cudaStream_t*)>> stream_;
141 };
142  // end of group
144 RMM_NAMESPACE_END
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:31
Owning wrapper for a CUDA stream.
Definition: cuda_stream.hpp:29
bool is_valid() const
Returns true if the owned stream is non-null.
cuda_stream & operator=(cuda_stream &&)=default
Move copy assignment operator (default)
cudaStream_t value() const
Get the value of the wrapped CUDA stream.
flags
stream creation flags.
Definition: cuda_stream.hpp:34
cuda_stream_view view() const
Creates an immutable, non-owning view of the wrapped CUDA stream.
cuda_stream(cuda_stream &&)=default
Move constructor (default)
cuda_stream(cuda_stream::flags flags=cuda_stream::flags::sync_default)
Construct a new CUDA stream object.