cuda_event.hpp
1 
5 #pragma once
6 
7 #include <mutex>
8 
9 #include <cuda_runtime.h>
10 
11 #include <rmm/cuda_stream_view.hpp>
12 
13 #include <rapidsmpf/error.hpp>
14 
15 namespace rapidsmpf {
16 
17 
35 class CudaEvent {
36  public:
44  CudaEvent(unsigned flags = cudaEventDisableTiming);
45 
59  static std::shared_ptr<CudaEvent> make_shared_record(
60  rmm::cuda_stream_view stream, unsigned flags = cudaEventDisableTiming
61  );
62 
68  ~CudaEvent() noexcept;
69 
70  CudaEvent(CudaEvent const&) = delete;
71  CudaEvent& operator=(CudaEvent const&) = delete;
72 
78  CudaEvent(CudaEvent&& other) noexcept;
79 
92  CudaEvent& operator=(CudaEvent&& other);
93 
103  void record(rmm::cuda_stream_view stream);
104 
112  [[nodiscard]] bool is_ready() const;
113 
119  void host_wait() const;
120 
131  void stream_wait(rmm::cuda_stream_view stream) const;
132 
138  [[nodiscard]] cudaEvent_t const& value() const noexcept;
139 
145  operator cudaEvent_t const&() const noexcept {
146  return value();
147  }
148 
149  private:
150  cudaEvent_t event_{};
151 };
152 
153 
154 } // namespace rapidsmpf
RAII wrapper for a CUDA event with convenience methods.
Definition: cuda_event.hpp:35
bool is_ready() const
Check if the CUDA event has been completed.
static std::shared_ptr< CudaEvent > make_shared_record(rmm::cuda_stream_view stream, unsigned flags=cudaEventDisableTiming)
Create and record a CUDA event on a given stream.
void record(rmm::cuda_stream_view stream)
Record the event on a CUDA stream.
~CudaEvent() noexcept
Destroy the CUDA event.
CudaEvent(unsigned flags=cudaEventDisableTiming)
Construct a CUDA event.
void stream_wait(rmm::cuda_stream_view stream) const
Make a CUDA stream wait on this event (non-blocking).
cudaEvent_t const & value() const noexcept
Access the underlying CUDA event handle.
void host_wait() const
Wait for the event to be completed (blocking).
RAPIDS Multi-Processor interfaces.
Definition: backend.hpp:14