Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
amrex::Gpu::TrackedVector< T > Struct Template Reference

#include <AMReX_TrackedVector.H>

Public Types

enum class  Status { up_to_date , device_dirty , host_dirty }
 
using value_type = T
 
using size_type = std::size_t
 
using device_vector_type = amrex::Gpu::NonManagedDeviceVector< T >
 

Public Member Functions

 TrackedVector ()=default
 
 TrackedVector (size_type a_size)
 
 TrackedVector (size_type a_size, value_type const &a_value)
 
 TrackedVector (std::initializer_list< T > a_initializer_list)
 
 TrackedVector (std::vector< T > a_vector)
 
 TrackedVector (TrackedVector const &a_vector)
 
 TrackedVector (TrackedVector &&a_vector) noexcept
 
TrackedVectoroperator= (TrackedVector const &a_vector)
 
TrackedVectoroperator= (TrackedVector &&a_vector) noexcept
 
 ~TrackedVector ()=default
 
Status status () const
 
std::vector< T > & host ()
 
std::vector< T > const & host_const () const
 
device_vector_typedevice ()
 
device_vector_type const & device_const () const
 
void release_gpu ()
 

Detailed Description

template<class T>
struct amrex::Gpu::TrackedVector< T >

Base for element data with dynamic host vectors mirrored lazily to GPU.

Provides lifetimes independent of AMReX initialize/finalize cycles, synchronization tracking, and data release APIs.

This object is primarily for input handling, allowing to initialize data even before AMReX was initialized and enabling workflows crossing AMReX init/finalize cycles. GPU memory will always be bound to an AMReX session, but CPU memory can be allocated and live arbitrarily long.

For AMReX CPU builds, the host and device members point to the same memory and the status will always be up to date.

Usage contract:

  • Device data can only be allocated after AMReX initialize and before finalize.
  • You can call release_gpu() anytime, but we will call it during AMReX finalize to invalidate device().
  • Always access data via host/device[_const](). Do not cache references/pointers to host/device memory managed by this object, or you run the risk of stale memory access.
  • Read-only accessors (host_const, device_const) may trigger a synchronous copy when the opposite side is dirty. They are logically const but not side-effect-free.
  • This class is not thread-safe. All accesses (including _const variants) must be externally synchronized if used from multiple threads.

Member Typedef Documentation

◆ device_vector_type

template<class T >
using amrex::Gpu::TrackedVector< T >::device_vector_type = amrex::Gpu::NonManagedDeviceVector<T>

◆ size_type

template<class T >
using amrex::Gpu::TrackedVector< T >::size_type = std::size_t

◆ value_type

template<class T >
using amrex::Gpu::TrackedVector< T >::value_type = T

Member Enumeration Documentation

◆ Status

template<class T >
enum class amrex::Gpu::TrackedVector::Status
strong
Enumerator
up_to_date 

host and device data are in sync

device_dirty 

host data needs an update

host_dirty 

device data needs an update

Constructor & Destructor Documentation

◆ TrackedVector() [1/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( )
default

◆ TrackedVector() [2/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( size_type  a_size)
inlineexplicit

◆ TrackedVector() [3/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( size_type  a_size,
value_type const &  a_value 
)
inline

◆ TrackedVector() [4/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( std::initializer_list< T >  a_initializer_list)
inline

◆ TrackedVector() [5/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( std::vector< T >  a_vector)
inline

◆ TrackedVector() [6/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( TrackedVector< T > const &  a_vector)
inline

◆ TrackedVector() [7/7]

template<class T >
amrex::Gpu::TrackedVector< T >::TrackedVector ( TrackedVector< T > &&  a_vector)
inlinenoexcept

Swap data of this and a_vector

◆ ~TrackedVector()

template<class T >
amrex::Gpu::TrackedVector< T >::~TrackedVector ( )
default

Member Function Documentation

◆ device()

template<class T >
device_vector_type & amrex::Gpu::TrackedVector< T >::device ( )
inline

Return writable device data

If host data is newer, syncs host-to-device first. Marks device as dirty so the next host access will sync back.

◆ device_const()

template<class T >
device_vector_type const & amrex::Gpu::TrackedVector< T >::device_const ( ) const
inline

Return read-only device data

If host data is newer, syncs host-to-device first.

◆ host()

template<class T >
std::vector< T > & amrex::Gpu::TrackedVector< T >::host ( )
inline

Return writable host data

If device data is newer, syncs device-to-host first (GPU builds). Marks host as dirty so the next device access will sync back.

◆ host_const()

template<class T >
std::vector< T > const & amrex::Gpu::TrackedVector< T >::host_const ( ) const
inline

Return read-only host data

If device data is newer, syncs device-to-host first (GPU builds).

◆ operator=() [1/2]

template<class T >
TrackedVector & amrex::Gpu::TrackedVector< T >::operator= ( TrackedVector< T > &&  a_vector)
inlinenoexcept

Swap the data of this and a_vector

◆ operator=() [2/2]

template<class T >
TrackedVector & amrex::Gpu::TrackedVector< T >::operator= ( TrackedVector< T > const &  a_vector)
inline

Copy data from a_vector

◆ release_gpu()

template<class T >
void amrex::Gpu::TrackedVector< T >::release_gpu ( )
inline

Release GPU memory

If the device side was modified (device_dirty), syncs device data back to the host first so no updates are lost. Host data preserved for reuse until destructor. This enables use outside of and across AMReX init/finalize cycles.

◆ status()

template<class T >
Status amrex::Gpu::TrackedVector< T >::status ( ) const
inline

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