Celeritas 0.7.0-22+develop.9704a67c5
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
celeritas::AsyncSnapshot< T > Class Template Reference

Host copy of a single value that is updated asynchronously from a stream. More...

#include <AsyncSnapshot.hh>

Public Member Functions

 AsyncSnapshot (T const &value={})
 Construct with an initial host value.
 
void load_async (ObserverPtr< T const, MemSpace::host > src, StreamId)
 Load a single value from host memory.
 
void load_async (ObserverPtr< T const, MemSpace::device > src, StreamId stream)
 Enqueue a load of a single value from device memory.
 
bool ready () const
 Whether the most recent load has completed.
 
void sync () const
 Block the host until the most recent load has completed.
 
void assign (T const &value)
 Overwrite the host value.
 
T const & value () const
 Access the most recently loaded value.
 
T const & wait () const
 Wait for the most recent load and access its value.
 

Detailed Description

template<class T>
class celeritas::AsyncSnapshot< T >

Host copy of a single value that is updated asynchronously from a stream.

The value is stored in pinned host memory so that a device-to-host copy enqueued with load_async does not block the host. Each device load records an event on its stream after the copy: ready queries it without blocking and sync waits for it. Because the copy is ordered after the work previously enqueued on that stream, completion of the load also implies completion of that work. A load from host memory completes immediately.

The loaded value must not be read or overwritten until the load has completed, which is checked when CELERITAS_DEBUG is enabled.

snapshot.load_async(device_counters, stream_id);
// ... enqueue more work or do host work ...
use(snapshot.wait());
Host copy of a single value that is updated asynchronously from a stream.
Definition AsyncSnapshot.hh:50
void load_async(ObserverPtr< T const, MemSpace::host > src, StreamId)
Load a single value from host memory.
Definition AsyncSnapshot.hh:119
T const & wait() const
Wait for the most recent load and access its value.
Definition AsyncSnapshot.hh:179

Constructor & Destructor Documentation

◆ AsyncSnapshot()

template<class T >
celeritas::AsyncSnapshot< T >::AsyncSnapshot ( T const &  value = {})
inlineexplicit

Construct with an initial host value.

If a device is active, the storage is pinned and the completion event is created. A snapshot that loads from device memory must therefore be constructed after the device is activated.

Member Function Documentation

◆ assign()

template<class T >
void celeritas::AsyncSnapshot< T >::assign ( T const &  value)
inline

Overwrite the host value.

The most recent load must have completed.

◆ load_async() [1/2]

template<class T >
void celeritas::AsyncSnapshot< T >::load_async ( ObserverPtr< T const, MemSpace::device >  src,
StreamId  stream 
)
inline

Enqueue a load of a single value from device memory.

The copy is enqueued on the given stream, followed by the completion event.

◆ load_async() [2/2]

template<class T >
void celeritas::AsyncSnapshot< T >::load_async ( ObserverPtr< T const, MemSpace::host >  src,
StreamId   
)
inline

Load a single value from host memory.

The load completes immediately. The stream is accepted so that code templated on the memory space can call either overload.

◆ value()

template<class T >
T const & celeritas::AsyncSnapshot< T >::value ( ) const
inline

Access the most recently loaded value.

The most recent load must have completed: call sync or check ready first, or use wait instead.

◆ wait()

template<class T >
T const & celeritas::AsyncSnapshot< T >::wait ( ) const
inline

Wait for the most recent load and access its value.

This blocks the host until the load completes.


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