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 
86  CudaEvent& operator=(CudaEvent&& other);
87 
97  void record(rmm::cuda_stream_view stream);
98 
106  [[nodiscard]] bool is_ready() const;
107 
113  void host_wait() const;
114 
125  void stream_wait(rmm::cuda_stream_view stream) const;
126 
132  [[nodiscard]] cudaEvent_t const& value() const noexcept;
133 
139  operator cudaEvent_t const&() const noexcept {
140  return value();
141  }
142 
143  private:
144  cudaEvent_t event_{};
145 };
146 
147 
148 } // 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).