Statevector Lifecycle (Wavefront Backend)
Scope
This page describes the current wavefront state/observable lifecycle implemented in:
native/wavefront/context/wavefront_context.f90native/wavefront/sparse/wavefront_sparse.f90native/wavefront/circulant/wavefront_circulant.f90
Key Arrays and Ownership
Array |
Location |
Owner |
Notes |
|---|---|---|---|
|
Device |
|
Main device state buffer, size |
|
Device |
|
Optional scratch buffer; allocated only if
|
|
Device |
|
Device observable slice, size |
|
Device |
|
Persistent reduction output buffer ( |
|
Host |
|
Host staging array for reduction buffer copies. |
|
Host |
|
Per-NODECOMM-rank host partition metadata. |
|
Host |
|
Per-NODECOMM-rank device partition metadata. |
Sparse CSR device data |
Device |
|
Managed by sparse graph communication setup/cleanup. |
|
Device |
|
Reallocated on each |
Setup and Transfer Metadata
During context%setup(ci, error_code):
cipointer is borrowed and cached.has_deviceis set fromci%get_DEVCOMM()membership.Transfer metadata arrays are allocated and filled with
MPI_AllgatheroverNODECOMMusing: - host partition:local_i,local_i_offset- device partition:device_local_i,device_local_i_offsetDevice allocations occur only on
has_deviceranks.state,work(if allocated), andobservablesare zeroed withhipMemset.Reduction buffers are allocated once and reused by
get_expectation_valueandget_state_norm.
State/Observable I/O
The context exposes four collective transfer operations:
set_state: host -> device viagpu_allscatterv_htodget_state: device -> host viagpu_allgatherv_dtohset_observables: host -> device viagpu_allscatterv_htodget_observables: device -> host viagpu_allgatherv_dtoh
Current behavior:
Collective error checks are synchronized on
SUBCOMM.Each routine brackets transfer calls with
MPI_Barrier(SUBCOMM).Non-GPU ranks pass
C_NULL_PTRfor device pointers.
Propagation Paths
Sparse path
wavefront_sparse%propagatecallsChebyshev_MultiplyonDEVCOMM.Output is written to
context%work.context%stateandcontext%workare pointer-swapped after each call.A
MPI_Barrier(SUBCOMM)follows the sparse propagate call.
Circulant path
wavefront_circulant%propagateuses SHAFFT overDEVCOMM.The code calls
shafftSetBuffersbefore forward FFT.After forward FFT and normalization,
shafftGetBuffersrefreshescontext%state/context%workpointers.Phase shift kernel runs on
context%state.shafftSetBuffersis called again before backward FFT to ensure SHAFFT uses the updated pointers.Final
shafftGetBuffersrefreshes pointers again.
Reductions (No Full State Transfer)
get_expectation_valuelaunches a GPU reduction kernel, copiesreduction_doutto host, sums locally, thenMPI_AllreduceonSUBCOMM.get_state_normfollows the same pattern with a norm kernel.Ranks without devices contribute
0to theSUBCOMMallreduce.
Pointer Stability Rules
Treat
context%stateas a logical handle, not a stable address.Sparse propagation explicitly swaps
stateandworkpointers.Circulant propagation may reorder buffers through SHAFFT and then rebinds pointers via
shafftGetBuffers.Do not cache
c_loc(context%state)across propagate calls.
Destruction
context%destroy() currently:
Re-selects
device_IDon GPU ranks.Synchronizes device.
Frees
work,state,observables, and reduction buffers if allocated.Deallocates transfer metadata arrays.
Nullifies borrowed
cipointer.
Important current behavior:
No
MPI_Barrieris executed incontext_destroy.This avoids destructor deadlocks when called through Python GC timing.
Collective Participation Summary
Operation |
Required participants |
|---|---|
|
All active |
|
All active |
|
All active |
Sparse propagate |
Device-owning ranks compute on |
Circulant propagate |
Device-owning ranks in |
Error Handling Notes
Most context/circulant API-level failures are surfaced via
error_code.Circulant SHAFFT calls return non-zero
error_codeon failure.Some lower-level checks still abort collectively (for example invalid GPU topology/binding configuration), and HIP utility behavior depends on the linked
hipfort_checkimplementation.