class
SushiRuntime::API::State
template <typename T>Owns two equally sized buffers whose roles the runtime swaps after each step.
- Declared in
include/SushiRuntime/api/data/state.hpp
Template parameters
TElement type; must be trivially copyable for device use.
See also
include/SushiRuntime/api/data/README.md
Public types
using SushiRuntime::API::State< T >::value_type = TElement type, exposed so generic code can recover it.
Public member functions
State()=defaultConstructs an empty state that owns no memory.
State(std::shared_ptr< Execution::RuntimeContext > ctx, std::size_t count, DeviceIndex device_index=DeviceIndex{0}, Residency residency=Residency::Shared)Allocates both buffers of count elements on one device.
See also
include/SushiRuntime/api/data/README.md
T * current() const noexceptExposes the field a step kernel reads from.
Returns
Pointer to the first element of the current field.
T * next() const noexceptExposes the field a step kernel writes into.
Returns
Pointer to the first element of the next field.
std::size_t size() const noexceptReports the capacity of the pair.
Returns
Number of elements in each field; both are the same size.
bool empty() const noexceptTells whether this State still owns memory.
Returns
True if it owns no allocation, e.g. after being moved from.
void * read_key() const noexceptIdentifies the region a task reading this State depends on.
Returns
The current field's base address, as used by the tracker.
void * write_key() const noexceptIdentifies the region a task writing this State depends on.
Returns
The next field's base address, as used by the tracker.
Core::LivenessObserver liveness() const noexceptReturns a weak observer of the current field's allocation, which stands for the State.
See also
include/SushiRuntime/api/data/README.md
T & operator[](std::size_t i) constReturns element i of the current field for host code.
Exceptions
SushiExceptionIf the State is device-resident.
span< T > host() constReturns a host-addressable span over the current field after one residency check.
Exceptions
SushiExceptionIf the State is device-resident.
Residency residency() const noexceptReports where both fields live.
Returns
Residency::Shared for managed USM, Residency::Device for device-resident memory, Residency::Host for pinned host USM.
bool host_accessible() const noexceptTells whether the host may index the current field directly.
Returns
True for shared or host USM; false for device-resident memory, which must go through read_range()/write_range().
std::vector< T > read_range(ElementRange range) constCopies a sub-range of the current field out to a host vector.
Parameters
rangeElement window to read; count is clamped to the field size.
void write_range(ElementRange range, const T *src)Copies a host range into a sub-range of the current field.
Parameters
rangeElement window to write; count is clamped to the field size.
srcHost source of at least range.count elements.
void advance() noexceptSwaps current and next so the just-written state becomes current.
The runtime calls this once per step.

