Public Member Functions | Static Public Member Functions | List of all members
rapidsmpf::CudaEvent Class Reference

RAII wrapper for a CUDA event with convenience methods. More...

#include <cuda_event.hpp>

Public Member Functions

 CudaEvent (unsigned flags=cudaEventDisableTiming)
 Construct a CUDA event. More...
 
 ~CudaEvent () noexcept
 Destroy the CUDA event. More...
 
 CudaEvent (CudaEvent const &)=delete
 Non-copyable.
 
CudaEventoperator= (CudaEvent const &)=delete
 Non-copy-assignable.
 
 CudaEvent (CudaEvent &&other) noexcept
 Move constructor. More...
 
CudaEventoperator= (CudaEvent &&other)
 Move assignment operator. More...
 
void record (rmm::cuda_stream_view stream)
 Record the event on a CUDA stream. More...
 
bool is_ready () const
 Check if the CUDA event has been completed. More...
 
void host_wait () const
 Wait for the event to be completed (blocking). More...
 
void stream_wait (rmm::cuda_stream_view stream) const
 Make a CUDA stream wait on this event (non-blocking). More...
 
cudaEvent_t const & value () const noexcept
 Access the underlying CUDA event handle. More...
 
 operator cudaEvent_t const & () const noexcept
 Implicit conversion operator to the CUDA event handle. More...
 

Static Public Member Functions

static std::shared_ptr< CudaEventmake_shared_record (rmm::cuda_stream_view stream, unsigned flags=cudaEventDisableTiming)
 Create and record a CUDA event on a given stream. More...
 

Detailed Description

RAII wrapper for a CUDA event with convenience methods.

Creates a CUDA event on construction and destroys it on destruction.

Note
To prevent undefined behavior due to unfinished memory operations, events should be used in the following cases if any of the operations below were performed asynchronously with respect to the host:
  1. Before addressing a device buffer's allocation.
  2. Before accessing a device buffer's data that has been copied from any location, or processed by a CUDA kernel.
  3. Before accessing a host buffer's data that has been copied from device or processed by a CUDA kernel.
CudaEvent objects must not have static storage duration, since CUDA resources are not guaranteed to be valid during program initialization or shutdown.

Definition at line 35 of file cuda_event.hpp.

Constructor & Destructor Documentation

◆ CudaEvent() [1/2]

rapidsmpf::CudaEvent::CudaEvent ( unsigned  flags = cudaEventDisableTiming)

Construct a CUDA event.

Parameters
flagsCUDA event creation flags.
Exceptions
rapidsmpf::cuda_errorif cudaEventCreateWithFlags fails.

◆ ~CudaEvent()

rapidsmpf::CudaEvent::~CudaEvent ( )
noexcept

Destroy the CUDA event.

Automatically releases the underlying CUDA event resource.

◆ CudaEvent() [2/2]

rapidsmpf::CudaEvent::CudaEvent ( CudaEvent &&  other)
noexcept

Move constructor.

Parameters
otherSource CudaEvent to move from.

Member Function Documentation

◆ host_wait()

void rapidsmpf::CudaEvent::host_wait ( ) const

Wait for the event to be completed (blocking).

Exceptions
rapidsmpf::cuda_errorif cudaEventSynchronize fails.

◆ is_ready()

bool rapidsmpf::CudaEvent::is_ready ( ) const

Check if the CUDA event has been completed.

Returns
true if the event has been completed, false otherwise.
Exceptions
rapidsmpf::cuda_errorif cudaEventQuery fails.

◆ make_shared_record()

static std::shared_ptr<CudaEvent> rapidsmpf::CudaEvent::make_shared_record ( rmm::cuda_stream_view  stream,
unsigned  flags = cudaEventDisableTiming 
)
static

Create and record a CUDA event on a given stream.

Convenience factory that constructs a shared CudaEvent with the specified creation flags, immediately records it on the provided stream, and returns it as a std::shared_ptr.

Parameters
streamCUDA stream on which to record the event.
flagsCUDA event creation flags.
Returns
A shared pointer to the newly created and recorded CudaEvent.
Exceptions
rapidsmpf::cuda_errorif event creation or recording fails.

◆ operator cudaEvent_t const &()

rapidsmpf::CudaEvent::operator cudaEvent_t const & ( ) const
inlinenoexcept

Implicit conversion operator to the CUDA event handle.

Returns
Const reference to the underlying cudaEvent_t.

Definition at line 139 of file cuda_event.hpp.

◆ operator=()

CudaEvent& rapidsmpf::CudaEvent::operator= ( CudaEvent &&  other)

Move assignment operator.

Parameters
otherSource CudaEvent to move from.
Returns
Reference to this object.

◆ record()

void rapidsmpf::CudaEvent::record ( rmm::cuda_stream_view  stream)

Record the event on a CUDA stream.

Marks the event as occurring after all prior operations on the given stream.

Parameters
streamThe CUDA stream to record the event on.
Exceptions
rapidsmpf::cuda_errorif cudaEventRecord fails.

◆ stream_wait()

void rapidsmpf::CudaEvent::stream_wait ( rmm::cuda_stream_view  stream) const

Make a CUDA stream wait on this event (non-blocking).

Ensures that all operations submitted to the given stream after this call will not begin execution until this event has completed.

Parameters
streamCUDA stream that should wait for the event.
Exceptions
rapidsmpf::cuda_errorif cudaStreamWaitEvent fails.

◆ value()

cudaEvent_t const& rapidsmpf::CudaEvent::value ( ) const
noexcept

Access the underlying CUDA event handle.

Returns
Const reference to the underlying cudaEvent_t.

The documentation for this class was generated from the following file: