|
Celeritas 0.7+be44d7947
|
Manage a state vector and execute a single step on all of them. More...
#include <Stepper.hh>

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 const & | actions () const final |
| Get action sequence for timing diagnostics. | |
| StateRef const & | state_ref () const |
| Access core data, primarily for debugging. | |
| CoreStateInterface const & | state () 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 | |
| StepperInterface & | operator= (StepperInterface const &)=default |
| StepperInterface (StepperInterface &&)=default | |
| StepperInterface & | operator= (StepperInterface &&)=default |
Manage a state vector and execute a single step on all of them.
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:
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
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.
|
inlinefinalvirtual |
Get action sequence for timing diagnostics.
Implements celeritas::StepperInterface.
|
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.
|
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.
|
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.
|
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.
|
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.
|
inlinefinalvirtualnoexcept |
Number of primaries accumulated in the producer buffer.
Implements celeritas::StepperInterface.
|
finalvirtual |
Transport already-initialized states.
async and get. Implements celeritas::StepperInterface.
|
finalvirtual |
Implements celeritas::StepperInterface.
|
inlinefinalvirtualnoexcept |
Fixed capacity of each stepper-owned primary buffer.
Implements celeritas::StepperInterface.
|
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.
|
finalvirtual |
Whether the asynchronous step has completed.
Implements celeritas::StepperInterface.
|
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.
|
inlinefinalvirtualnoexcept |
Fixed capacity of the per-step secondary stack.
Implements celeritas::StepperInterface.
|
inlinefinalvirtual |
Get a shared pointer to the state (TEMPORARY, DO NOT USE)
Implements celeritas::StepperInterface.
|
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.
Implements celeritas::StepperInterface.
|
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.
|
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.
|
inlinefinalvirtual |
Get the core state interface for diagnostic output.
Implements celeritas::StepperInterface.
|
inlinefinalvirtualnoexcept |
Whether an asynchronous step result can be retrieved.
Implements celeritas::StepperInterface.
|
finalvirtual |
Wait for the asynchronous step to complete without consuming its result.
Implements celeritas::StepperInterface.
|
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:
Implements celeritas::StepperInterface.