Celeritas 0.7+be44d7947
Loading...
Searching...
No Matches
Public Member Functions | List of all members
celeritas::Stepper< M > Class Template Referencefinal

Manage a state vector and execute a single step on all of them. More...

#include <Stepper.hh>

Inheritance diagram for celeritas::Stepper< M >:
Inheritance graph
[legend]

Public Types

Type aliases
using StateRef = CoreStateData< Ownership::reference, M >
 
- Public Types inherited from celeritas::StepperInterface
using Input = StepperInput
 
using SpanConstPrimary = Span< Primary const >
 
using result_type = StepperResult
 
using SPState = std::shared_ptr< CoreStateInterface >
 

Public Member Functions

 Stepper (Input input)
 Construct with problem parameters and setup options.
 
 ~Stepper () final
 Default destructor.
 
void warm_up () final
 Run all step actions with no active particles.
 
void async () final
 Start a step with existing states and any staged primary batch.
 
void async (SpanConstPrimary primaries) final
 Copy new primaries into owned storage and start a step with them.
 
bool valid () const noexcept final
 Whether an asynchronous step result can be retrieved.
 
bool ready () const final
 Whether the asynchronous step has completed.
 
void wait () const final
 Wait for the asynchronous step to complete without consuming its result.
 
StepperResult get () final
 Wait for and return the asynchronous step result.
 
size_type primary_capacity () const noexcept final
 Fixed capacity of each stepper-owned primary buffer.
 
size_type initializer_capacity () const noexcept final
 Return the fixed capacity of the track initializer queue.
 
size_type secondary_capacity () const noexcept final
 Fixed capacity of the per-step secondary stack.
 
size_type num_buffered_primaries () const noexcept final
 Number of primaries accumulated in the producer buffer.
 
void push_primary (Primary const &primary) final
 Add a primary to the producer buffer.
 
void stage_primaries () final
 Stage the producer buffer for transport.
 
SpanConstPrimary staged_primaries () const noexcept final
 Access the unsubmitted primary batch staged for the next step.
 
StepperResult operator() () final
 Transport already-initialized states.
 
void stage_primaries (SpanConstPrimary primaries) final
 Copy user-provided primaries into owned storage and stage them.
 
StepperResult operator() (SpanConstPrimary primaries) final
 
void kill_active () final
 Kill all tracks in flight to debug "stuck" tracks.
 
void reseed (UniqueEventId event_id) final
 Reseed RNGs and counters at the start of an event for reproducibility.
 
ActionSequence constactions () const final
 Get action sequence for timing diagnostics.
 
StateRef conststate_ref () const
 Access core data, primarily for debugging.
 
CoreStateInterface conststate () const final
 Get the core state interface for diagnostic output.
 
void reset_state ()
 Reset the core state counters and data so it can be reused.
 
SPState sp_state () final
 Get a shared pointer to the state (TEMPORARY, DO NOT USE)
 

Additional Inherited Members

- Protected Member Functions inherited from celeritas::StepperInterface
 StepperInterface (StepperInterface const &)=default
 
StepperInterfaceoperator= (StepperInterface const &)=default
 
 StepperInterface (StepperInterface &&)=default
 
StepperInterfaceoperator= (StepperInterface &&)=default
 

Detailed Description

template<MemSpace M>
class celeritas::Stepper< M >

Manage a state vector and execute a single step on all of them.

Note
This is likely to be removed and refactored since we're changing how primaries are created and how multithread state ownership is managed.

Device steps have separate start and result phases. Calling async enqueues the action sequence, a counter snapshot, and a completion event on the state stream. Diagnostic action or step timing can still synchronize the stream. Other synchronization within the action sequence is being removed separately.

The two primary buffers are reserved to primary_capacity at construction, so accumulating and staging primaries within capacity does not reallocate. Device buffers use pinned host memory so inserting a staged batch can enqueue its host-to-device copy. The submitted source storage is retained until that copy completes; same-stream ordering ensures the step actions see the copied input. Reusing a submitted source may wait for its copy event, but does not wait for the full step to complete.

The following sequence overlaps production of a later primary batch with an outstanding result:

step.async(make_span(first_primaries));
for (Primary primary : second_primaries)
{
step.push_primary(std::move(primary));
}
step.stage_primaries();
StepperResult result = step.get();
do
{
// Submit the staged batch while continuing any active tracks
step.async();
result = step.get();
} while (result);
constexpr Span< T, N > make_span(Array< T, N > &x)
Get a mutable fixed-size view to an array.
Definition Span.hh:337
Manage a state vector and execute a single step on all of them.
Definition Stepper.hh:313
Starting "source" particle.
Definition Primary.hh:22
Track counters for a step.
Definition Stepper.hh:67
Asynchronous state

The valid_ flag tracks whether a result can be consumed, whereas step_done_ tracks completion of device work. Their states after successful calls are:

Lifecycle point valid_ CPU step_done_ GPU step_done_
Construction or after get false Null Allocated and ready
After async true Null and ready Recorded; pending or ready
After ready returns false true Not possible Recorded and pending
After ready is true or wait true Null/ready Recorded/ready

A host step executes synchronously, so its null event is always ready. A device event is allocated once and re-recorded after each counter snapshot. Calling get first waits for completion and then clears valid_; it does not reset or replace the event. Primary buffering has an independent state, tracked by primary_phase_ and primary_copy_done_. The staged storage remains internal while a copy source is submitted, but the public staged_primaries accessor returns only an unsubmitted batch:

Primary phase Producer Staged storage Accessor Copy event
empty May fill Empty Empty Null/ready or allocated/ready
staged May fill Next input Next input Recorded after H2D copy
submitted May fill Prior copy source Empty Pending or ready

Calling stage_primaries changes empty to staged. Calling async changes staged to submitted after the actions have been enqueued. A later stage_primaries call may reclaim a submitted source after waiting only for its copy event, then stage the producer buffer. Calling get also reclaims a submitted source, but leaves a next staged batch unchanged. Host copies complete synchronously, so primary_copy_done_ is null and reclaiming the source does not wait.

The expected state transitions are

no result + producer -- async() --> valid result + same producer
no result + no queued input -- async(primaries) --> valid result
valid result -- ready() or wait() --> valid result
valid result -- get() --> no result
producer -- stage_primaries() --> staged
valid result + producer -- stage_primaries() --> valid result + staged
staged + no result -- async() --> submitted + valid result
submitted + producer -- stage_primaries() --> staged
bool valid() const noexcept final
Whether an asynchronous step result can be retrieved.
Definition Stepper.hh:337
bool ready() const final
Whether the asynchronous step has completed.
Definition Stepper.cc:384
void stage_primaries() final
Stage the producer buffer for transport.
Definition Stepper.cc:275
void wait() const final
Wait for the asynchronous step to complete without consuming its result.
Definition Stepper.cc:395
void async() final
Start a step with existing states and any staged primary batch.
Definition Stepper.cc:179
StepperResult get() final
Wait for and return the asynchronous step result.
Definition Stepper.cc:409

Calling ready or wait repeatedly with a valid result is allowed. The next async call is allowed only after get consumes the previous result. Primaries may be pushed and staged while a result is valid, and the producer may begin filling again while that next batch is staged. The staged batch cannot be submitted until the prior result is consumed. Calls to warm_up, reset_state, and reseed are rejected while a result or queued primary batch exists. Calling kill_active permits buffered primaries but rejects a pending result or staged batch. The synchronous call operators perform async followed immediately by get.

Member Function Documentation

◆ actions()

template<MemSpace M>
ActionSequence const & celeritas::Stepper< M >::actions ( ) const
inlinefinalvirtual

Get action sequence for timing diagnostics.

Implements celeritas::StepperInterface.

◆ async() [1/2]

template<MemSpace M>
void celeritas::Stepper< M >::async ( )
finalvirtual

Start a step with existing states and any staged primary batch.

A single transport step is simply a loop over a topologically sorted DAG of kernels. The step result must be retrieved with get before another step can be started. In device mode the result counters are copied asynchronously to pinned host memory, followed by a completion event. Primaries in the producer buffer remain there unless they have first been staged.

Existing synchronization within the action sequence can still block this call. Removing those counter-dependent synchronization points is handled separately.

Implements celeritas::StepperInterface.

◆ async() [2/2]

template<MemSpace M>
void celeritas::Stepper< M >::async ( SpanConstPrimary  primaries)
finalvirtual

Copy new primaries into owned storage and start a step with them.

The input is copied into the producer buffer before its host-to-device copy is enqueued, so it can be released when this function returns.

Implements celeritas::StepperInterface.

◆ get()

template<MemSpace M>
auto celeritas::Stepper< M >::get ( )
finalvirtual

Wait for and return the asynchronous step result.

Calling this consumes the pending result and allows another step to be started.

Implements celeritas::StepperInterface.

◆ initializer_capacity()

template<MemSpace M>
size_type celeritas::Stepper< M >::initializer_capacity ( ) const
finalvirtualnoexcept

Return the fixed capacity of the track initializer queue.

After consuming a step result, callers can compare this with the result's queued initializers and the producer buffer size before staging primaries.

Implements celeritas::StepperInterface.

◆ kill_active()

template<MemSpace M>
void celeritas::Stepper< M >::kill_active ( )
finalvirtual

Kill all tracks in flight to debug "stuck" tracks.

The next "step" will apply the tracking cut and (if CPU) print diagnostic output about the failed tracks. Primaries in the producer buffer are not yet part of the core state and remain unchanged, but staged primaries prevent this operation.

Implements celeritas::StepperInterface.

◆ num_buffered_primaries()

template<MemSpace M>
size_type celeritas::Stepper< M >::num_buffered_primaries ( ) const
inlinefinalvirtualnoexcept

Number of primaries accumulated in the producer buffer.

Implements celeritas::StepperInterface.

◆ operator()() [1/2]

template<MemSpace M>
auto celeritas::Stepper< M >::operator() ( )
finalvirtual

Transport already-initialized states.

Deprecated:
This is the deprecated synchronous compatibility wrapper for async and get.

Implements celeritas::StepperInterface.

◆ operator()() [2/2]

template<MemSpace M>
auto celeritas::Stepper< M >::operator() ( SpanConstPrimary  primaries)
finalvirtual
Deprecated:
Initialize new primaries and transport them for a single step.

Implements celeritas::StepperInterface.

◆ primary_capacity()

template<MemSpace M>
size_type celeritas::Stepper< M >::primary_capacity ( ) const
inlinefinalvirtualnoexcept

Fixed capacity of each stepper-owned primary buffer.

Implements celeritas::StepperInterface.

◆ push_primary()

template<MemSpace M>
void celeritas::Stepper< M >::push_primary ( Primary const primary)
finalvirtual

Add a primary to the producer buffer.

The producer buffer can be filled while a step result is valid or another primary batch is staged. Its fixed capacity is reserved at construction.

Implements celeritas::StepperInterface.

◆ ready()

template<MemSpace M>
bool celeritas::Stepper< M >::ready ( ) const
finalvirtual

Whether the asynchronous step has completed.

Implements celeritas::StepperInterface.

◆ reseed()

template<MemSpace M>
void celeritas::Stepper< M >::reseed ( UniqueEventId  event_id)
finalvirtual

Reseed RNGs and counters at the start of an event for reproducibility.

This reinitializes the RNG states using a single seed and unique subsequence for each thread. It ensures that given an event identification, the random number sequence for the event (and thus the event's behavior) can be reproduced.

Implements celeritas::StepperInterface.

◆ secondary_capacity()

template<MemSpace M>
size_type celeritas::Stepper< M >::secondary_capacity ( ) const
inlinefinalvirtualnoexcept

Fixed capacity of the per-step secondary stack.

Implements celeritas::StepperInterface.

◆ sp_state()

template<MemSpace M>
SPState celeritas::Stepper< M >::sp_state ( )
inlinefinalvirtual

Get a shared pointer to the state (TEMPORARY, DO NOT USE)

Implements celeritas::StepperInterface.

◆ stage_primaries() [1/2]

template<MemSpace M>
void celeritas::Stepper< M >::stage_primaries ( )
finalvirtual

Stage the producer buffer for transport.

This validates and inserts primaries into the stepper state but does not execute transport actions. This separation does not by itself make staging nonblocking: in device mode the current counter updates may still synchronize internally. Reusing the source of a previously submitted batch waits only for its copy event, not for completion of the previous step.

Precondition
No primaries are currently staged.

Implements celeritas::StepperInterface.

◆ stage_primaries() [2/2]

template<MemSpace M>
void celeritas::Stepper< M >::stage_primaries ( SpanConstPrimary  primaries)
finalvirtual

Copy user-provided primaries into owned storage and stage them.

The caller's span can be released when this function returns. If staging fails, the copied input is discarded so the caller can correct it and retry.

Implements celeritas::StepperInterface.

◆ staged_primaries()

template<MemSpace M>
auto celeritas::Stepper< M >::staged_primaries ( ) const
finalvirtualnoexcept

Access the unsubmitted primary batch staged for the next step.

Access the unsubmitted primaries staged for the next step.

Submitted source storage is retained internally until its copy completes, but is not exposed by this accessor.

Implements celeritas::StepperInterface.

◆ state()

template<MemSpace M>
CoreStateInterface const & celeritas::Stepper< M >::state ( ) const
inlinefinalvirtual

Get the core state interface for diagnostic output.

Implements celeritas::StepperInterface.

◆ valid()

template<MemSpace M>
bool celeritas::Stepper< M >::valid ( ) const
inlinefinalvirtualnoexcept

Whether an asynchronous step result can be retrieved.

Implements celeritas::StepperInterface.

◆ wait()

template<MemSpace M>
void celeritas::Stepper< M >::wait ( ) const
finalvirtual

Wait for the asynchronous step to complete without consuming its result.

Implements celeritas::StepperInterface.

◆ warm_up()

template<MemSpace M>
void celeritas::Stepper< M >::warm_up ( )
finalvirtual

Run all step actions with no active particles.

The warmup stage is useful for profiling and debugging since the first step iteration can do the following:

  • Initialize asynchronous memory pools
  • Interrogate kernel functions for properties to be output later
  • Allocate "lazy" auxiliary data (e.g. action diagnostics)

Implements celeritas::StepperInterface.


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