Celeritas 0.7.0-dev.328+develop.a407567
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
celeritas::DeviceEvent Class Reference

Minimal wrapper around a CUDA/HIP event for synchronization. More...

#include <DeviceEvent.hh>

Classes

struct  Impl
 Internal implementation holding the native CUDA/HIP event handle. More...
 

Public Types

using EventT = std::nullptr_t
 Event implementation is unavailable.
 

Public Member Functions

 DeviceEvent (Device const &d)
 Construct a device event.
 
 DeviceEvent (std::nullptr_t)
 Construct a null device event.
 
 DeviceEvent (DeviceEvent const &)=delete
 
DeviceEventoperator= (DeviceEvent const &)=delete
 
 DeviceEvent (DeviceEvent &&)=default
 
DeviceEventoperator= (DeviceEvent &&)=default
 
 operator bool () const
 Whether the event is valid (not null or moved-from).
 
EventT get () const
 Get the native CUDA/HIP event handle.
 
void record (Stream const &s)
 Record this event on the stream.
 
bool ready () const
 Query event status without blocking.
 
void sync () const
 Wait for the event to complete.
 

Detailed Description

Minimal wrapper around a CUDA/HIP event for synchronization.

Events provide a mechanism for querying the status of asynchronous operations on GPU streams and synchronizing between host and device, and synchronizing between streams.

States
  • Constructed: when built with an active device, the instance evaluates to true and manages an event object.
  • Null: when constructed with a nullptr, or when moved from, the class instance is false. It does not manage an event. The sync function is a null-op (the event is always ready ), and record cannot be called.

If no device is enabled (or Celeritas is compiled without CUDA/HIP support), only the null state is available.

Example
// Setup:
DeviceEvent my_kernel(celeritas::device());
assert(my_kernel.ready());
// Later...
launch_kernel_async(state.stream());
my_kernel.record(state.stream());
// Then do CPU work until the kernel or CPU is done
while (!cpu_work_done() && !my_kernel.ready())
{
cpu_work();
}
Minimal wrapper around a CUDA/HIP event for synchronization.
Definition DeviceEvent.hh:62
Use my_kernel.sync() before the kernel launch to wait on the previous kernel launch before going again.

Member Function Documentation

◆ get()

auto celeritas::DeviceEvent::get ( ) const

Get the native CUDA/HIP event handle.

This provides direct access to the underlying event for advanced use cases.

◆ ready()

bool celeritas::DeviceEvent::ready ( ) const

Query event status without blocking.

Returns
true if all operations recorded before this event have completed, false if the event is still pending

This is a non-blocking query that returns immediately. If an error occurs during the query, the function will throw an exception.

◆ record()

void celeritas::DeviceEvent::record ( Stream const s)

Record this event on the stream.

This captures the state of the stream at the point the event is recorded. All operations enqueued on the stream before this call must complete before the event is considered complete.

◆ sync()

void celeritas::DeviceEvent::sync ( ) const

Wait for the event to complete.

This blocks the calling thread until all operations recorded before this event have finished executing on the device. Use this to synchronize the host with device operations.

If the event is null, this is a no-op.


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