SENSEI
A frame work for generic in situ analytics
svtkHAMRDataArray< T > Class Template Reference

An accelerator aware container for array based data. More...

#include <svtkHAMRDataArray.h>

Inheritance diagram for svtkHAMRDataArray< T >:
[legend]
Collaboration diagram for svtkHAMRDataArray< T >:
[legend]

Public Member Functions

 svtkTypeMacro (svtkHAMRDataArray, svtkDataArray)
 
void PrintSelf (ostream &os, svtkIndent indent) override
 
template<typename deleter_t >
svtkHAMRDataArray< T > * New (const std::string &name, T *data, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode, int owner, deleter_t deleter)
 
zero-copy data transfer
void SetData (T *data, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode, int owner)
 zero-copy the passed data. More...
 
void SetData (const std::shared_ptr< T > &data, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode, int owner)
 zero-copy the passed data. More...
 
template<typename deleter_t >
void SetData (T *dataPtr, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode, int owner, deleter_t deleter)
 zero-copy the passed data. More...
 
location agnostic access
std::shared_ptr< const T > GetHostAccessible () const
 
std::shared_ptr< const T > GetDeviceAccessible () const
 
std::shared_ptr< const T > GetCUDAAccessible () const
 
std::shared_ptr< const T > GetHIPAccessible () const
 
std::shared_ptr< const T > GetOpenMPAccessible () const
 
direct access
T * GetData ()
 fast access to the internally managed memory. More...
 
std::shared_ptr< T > GetDataPointer ()
 fast access to the internally managed memory. More...
 
device location
int GetOwner () const
 get the device where the memory was allocated. More...
 
void SetOwner ()
 Set the device id that owns the memory to the currently aactive device. More...
 
void SetAllocator (svtkAllocator alloc)
 Sets or changes the allocator used to manage the menory, this may move the data from one device to another. More...
 
svtkAllocator GetAllocator ()
 
bool HostAccessible ()
 return true if a pooniter to the data is safe to use on the Host More...
 
bool CUDAAccessible ()
 return true if a pooniter to the data is safe to use with CUDA More...
 
bool HIPAccessible ()
 returns a pointer to the data that is safe to use with HIP More...
 
bool OpenMPAccessible ()
 return true if a pooniter to the data is safe to use with OpenMP device off load More...
 
synchronization
void SetStream (const svtkStream &stream, svtkStreamMode &mode)
 sets the stream. mode indicate synchronous behavior or not. More...
 
svtkStream & GetStream ()
 
const svtkStream & GetStream () const
 
void Synchronize () const
 synchronizes on the internal stream More...
 
modify the size of the array
svtkIdType GetNumberOfValues () const override
 returns the number of values. this is the current size, not the capacity. More...
 
void SetNumberOfTuples (svtkIdType numTuples) override
 sets the current size and may change the capacity of the array More...
 
void SetNumberOfTuples (svtkIdType numTuples, svtkAllocator alloc)
 
svtkTypeBool Resize (svtkIdType numTuples) override
 resize the container using the current allocator More...
 
conversions
svtkAOSDataArrayTemplate< T > * AsSvtkAOSDataArray (int zeroCopy)
 Convert to an svtkAOSDataArrayTemplate instance. More...
 

Static Public Member Functions

construct uninitialized
static svtkHAMRDataArrayNew ()
 construct a new instance that is uninitiazed. More...
 
copy construct
static svtkHAMRDataArrayNew (svtkDataArray *da)
 copy construct from the passed instance. More...
 
static svtkHAMRDataArrayNew (svtkDataArray *da, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode)
 copy construct from the passed instance. More...
 
zero-copy construct
static svtkHAMRDataArrayNew (const std::string &name, T *data, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode, int owner, int take)
 zero-copy the passed data. More...
 
static svtkHAMRDataArrayNew (const std::string &name, const std::shared_ptr< T > &data, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode, int owner)
 zero-copy the passed data. More...
 
template<typename deleter_t >
static svtkHAMRDataArrayNew (const std::string &name, T *data, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode, int owner, deleter_t deleter)
 zero-copy the passed data. More...
 
construct and allocate
static svtkHAMRDataArrayNew (const std::string &name, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode)
 Allocate a new array of the specified size using the specified allocator. More...
 
static svtkHAMRDataArrayNew (const std::string &name, size_t numTuples, int numComps, svtkAllocator alloc, svtkStream stream, svtkStreamMode streamMode, const T &initVal)
 Allocate a new array of the specified size using the specified allocator initialized to the specified value. More...
 

Friends

template<typename U >
class svtkHAMRDataArray
 

Detailed Description

template<typename T>
class svtkHAMRDataArray< T >

An accelerator aware container for array based data.

The svtkHAMRDataArray can be used to allocate and manage data on the host and on accelerators. The purpose of the container is to pass data in between simulation and analysis codes in a platform portable, programming model portable, efficient manner.

Data can be allocated on the host or a specific accelerator. See ::New overloads in the "construct and allocate" group.

Data can be explicitly moved between devices and between the host and any device. See ::SetAllocator.

Zero-copy tansfer of device memory is supported, see ::New overloads in the "zero-copy construct" group for zero-copy construction and ::SetData overloads in the "zero-copy data transfer" group.

When consuming data passed from an unknown sorce, accessibility methods can be used to access the data on the host or desired device. These may move the data to the requested device or the host. Data movement is only done if the data is not in the reqeusted location. Smart pointers are used to automate and hide the details from the caller. See ::GetHostAccessible, ::GetDeviceAccessible and programming model specific overloads ::GetCUDAAccessible, ::GetHIPAccessible, and ::GetOpenMPAccessible.

When one knows where data resides direct access methods provide access to the raw pointers. See ::GetData and ::GetPointer.

By default all operations including allocations, and data movement, are asynchronous. Care must be taken before accessing the data to be sure outstanding operations have been completed. See ::Synchronize.

Member Function Documentation

◆ AsSvtkAOSDataArray()

template<typename T >
svtkAOSDataArrayTemplate< T > * svtkHAMRDataArray< T >::AsSvtkAOSDataArray ( int  zeroCopy)

Convert to an svtkAOSDataArrayTemplate instance.

Because SVTK only supports host based data, a deep-copy is made when this array is located on the GPU. Otherwise the data is passed via zero-copy

Parameters
[in]zeroCopyif true and the data resides on the host, the data is passed to the new svtkAOSDataArrayTemplate instance by zero-copy. Otehrwise a deep-copy is made.
Returns
a new instance that must be deleted by the caller

◆ CUDAAccessible()

template<typename T>
bool svtkHAMRDataArray< T >::CUDAAccessible ( )
inline

return true if a pooniter to the data is safe to use with CUDA

◆ GetAllocator()

template<typename T>
svtkAllocator svtkHAMRDataArray< T >::GetAllocator ( )
inline
Returns
the current allocator

◆ GetCUDAAccessible()

template<typename T>
std::shared_ptr<const T> svtkHAMRDataArray< T >::GetCUDAAccessible ( ) const
inline
Returns
a pointer to the data that is safe to use with CUDA

◆ GetData()

template<typename T>
void svtkHAMRDataArray< T >::GetData ( )
inline

fast access to the internally managed memory.

Use this only when you know where the data resides and will access it in that location. This method saves the cost of a smart_ptr copy construct and the cost of the logic that determines if a temporary is needed. For all other cases use GetXAccessible to access the data.

◆ GetDataPointer()

template<typename T>
std::shared_ptr<T> svtkHAMRDataArray< T >::GetDataPointer ( )
inline

fast access to the internally managed memory.

Use this only when you know where the data resides and will access it in that location. This method saves the cost of the logic determining if a temporary is needed. For all other cases use GetXAccessible to access the data.

◆ GetDeviceAccessible()

template<typename T>
std::shared_ptr<const T> svtkHAMRDataArray< T >::GetDeviceAccessible ( ) const
inline
Returns
a pointer to the data that is safe for the compiled device

◆ GetHIPAccessible()

template<typename T>
std::shared_ptr<const T> svtkHAMRDataArray< T >::GetHIPAccessible ( ) const
inline
Returns
a pointer to the data that is safe to use with HIP

◆ GetHostAccessible()

template<typename T>
std::shared_ptr<const T> svtkHAMRDataArray< T >::GetHostAccessible ( ) const
inline
Returns
a pointer to the data that is safe to use on the host

◆ GetNumberOfValues()

template<typename T>
svtkIdType svtkHAMRDataArray< T >::GetNumberOfValues ( ) const
inlineoverride

returns the number of values. this is the current size, not the capacity.

◆ GetOpenMPAccessible()

template<typename T>
std::shared_ptr<const T> svtkHAMRDataArray< T >::GetOpenMPAccessible ( ) const
inline
Returns
a pointer to the data that is safe to use with OpenMP device off load

◆ GetOwner()

template<typename T>
int svtkHAMRDataArray< T >::GetOwner ( ) const
inline

get the device where the memory was allocated.

◆ GetStream()

template<typename T>
svtkStream& svtkHAMRDataArray< T >::GetStream ( )
inline
Returns
the stream

◆ HIPAccessible()

template<typename T>
bool svtkHAMRDataArray< T >::HIPAccessible ( )
inline

returns a pointer to the data that is safe to use with HIP

◆ HostAccessible()

template<typename T>
bool svtkHAMRDataArray< T >::HostAccessible ( )
inline

return true if a pooniter to the data is safe to use on the Host

◆ New() [1/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( )
static

construct a new instance that is uninitiazed.

Before use call ::SetAllocator (and optionally ::SetStream), and either ::SetData or some combination of ::SetNumberOfTuples, ::SetNumberOfComponents, and/or ::Resize.

Returns
an empty instance.

◆ New() [2/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( svtkDataArray da)
static

copy construct from the passed instance.

this is a deep copy.

Note
the allocator is determined by the passed instance, while the default svtkStream and svtkStreamMode will be used. Use the overload that accepts an allocator when you want control over the location of the copy.
Parameters
[in]dathe array to deep copy.

◆ New() [3/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( svtkDataArray da,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode 
)
static

copy construct from the passed instance.

this is a deep copy. if the allocator is a device allocator the memory is allocated on the active device.

Parameters
[in]dathe array to deep copy.
[in]allocthe allocator to use to allocate memory for the copy
[in]streamthe stream to make the allocation and copy on
[in]streamModethe sychnronization behavior of the container.
Returns
a new instance with the data copied.

◆ New() [4/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( const std::string &  name,
T *  data,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
int  owner,
int  take 
)
static

zero-copy the passed data.

Parameters
[in]namethe name of the array
[in]dataa pointer to the data
[in]numTuplesthe number of data tuples
[in]numCompsthe numper of components per tuple
[in]allocan ::svtkAllocator instance declaring where the data resides
[in]streaman ::svtkStream instance providing an ordering on operations
[in]streamModean ::svtkStreamMode instance declaring synchronous behavior or not
[in]ownerthe device id where the data resides, or -1 for the host
[in]takeif true the pointed to data will be released using the deleter associated with the declared ::svtkAllocator alloc
Returns
a new instance that must be deleted by the caller

◆ New() [5/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( const std::string &  name,
const std::shared_ptr< T > &  data,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
int  owner 
)
static

zero-copy the passed data.

This override gives one direct control over the management and reference counting of the pointed to data.

Parameters
[in]namethe name of the array
[in]dataa smart pointer that manages the pointed to data
[in]numTuplesthe number of data tuples
[in]numCompsthe numper of components per tuple
[in]allocan ::svtkAllocator instance declaring where the data resides
[in]streaman ::svtkStream instance providing an ordering on operations
[in]streamModean ::svtkStreamMode instance declaring synchronous behavior or not
[in]ownerthe device id where the data resides, or -1 for the host
Returns
a new instance that must be deleted by the caller

◆ New() [6/8]

template<typename T>
template<typename deleter_t >
static svtkHAMRDataArray* svtkHAMRDataArray< T >::New ( const std::string &  name,
T *  data,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
int  owner,
deleter_t  deleter 
)
static

zero-copy the passed data.

This override gives one direct control over the method that is used to release the pointed to array.

Parameters
[in]namethe name of the array
[in]dataa smart pointer that manages the pointed to data
[in]numTuplesthe number of data tuples
[in]numCompsthe numper of components per tuple
[in]allocan ::svtkAllocator instance declaring where the data resides
[in]streaman ::svtkStream instance providing an ordering on operations
[in]streamModean ::svtkStreamMode instance declaring synchronous behavior or not
[in]ownerthe device id where the data resides, or -1 for the host
Returns
a new instance that must be deleted by the caller

◆ New() [7/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( const std::string &  name,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode 
)
static

Allocate a new array of the specified size using the specified allocator.

Parameters
[in]namethe name of the array
[in]numTuplesthe number of data tuples
[in]numCompsthe numper of components per tuple
[in]allocan ::svtkAllocator instance declaring where the data resides
[in]streaman ::svtkStream instance providing an ordering on operations
[in]streamModean ::svtkStreamMode instance declaring synchronous behavior or not
Returns
a new instance that must be deleted by the caller

◆ New() [8/8]

template<typename T >
svtkHAMRDataArray< T > * svtkHAMRDataArray< T >::New ( const std::string &  name,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
const T &  initVal 
)
static

Allocate a new array of the specified size using the specified allocator initialized to the specified value.

Parameters
[in]namethe name of the array
[in]numTuplesthe number of data tuples
[in]numCompsthe numper of components per tuple
[in]allocan ::svtkAllocator instance declaring where the data resides
[in]streaman ::svtkStream instance providing an ordering on operations
[in]streamModean ::svtkStreamMode instance declaring synchronous behavior or not
[in]initValthe value to initialize the contents to
Returns
a new instance that must be deleted by the caller

◆ OpenMPAccessible()

template<typename T>
bool svtkHAMRDataArray< T >::OpenMPAccessible ( )
inline

return true if a pooniter to the data is safe to use with OpenMP device off load

◆ Resize()

template<typename T >
svtkTypeBool svtkHAMRDataArray< T >::Resize ( svtkIdType  numTuples)
override

resize the container using the current allocator

◆ SetAllocator()

template<typename T>
void svtkHAMRDataArray< T >::SetAllocator ( svtkAllocator  alloc)
inline

Sets or changes the allocator used to manage the menory, this may move the data from one device to another.

◆ SetData() [1/3]

template<typename T >
void svtkHAMRDataArray< T >::SetData ( T *  data,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
int  owner 
)

zero-copy the passed data.

the allocator is used to tell where the data resides. the callee (array instance) takes ownership of the pointer.

◆ SetData() [2/3]

template<typename T >
void svtkHAMRDataArray< T >::SetData ( const std::shared_ptr< T > &  data,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
int  owner 
)

zero-copy the passed data.

the allocator is used to tell where the data resides.

◆ SetData() [3/3]

template<typename T >
template<typename deleter_t >
void svtkHAMRDataArray< T >::SetData ( T *  dataPtr,
size_t  numTuples,
int  numComps,
svtkAllocator  alloc,
svtkStream  stream,
svtkStreamMode  streamMode,
int  owner,
deleter_t  deleter 
)

zero-copy the passed data.

the allocator is used to tell where the data resides the deleter will be called as void deleter(void *dataPtr) when the data is no longer needed

◆ SetNumberOfTuples()

template<typename T >
void svtkHAMRDataArray< T >::SetNumberOfTuples ( svtkIdType  numTuples)
override

sets the current size and may change the capacity of the array

◆ SetOwner()

template<typename T>
void svtkHAMRDataArray< T >::SetOwner ( )
inline

Set the device id that owns the memory to the currently aactive device.

this may be used to move the data from one device to another.

◆ SetStream()

template<typename T>
void svtkHAMRDataArray< T >::SetStream ( const svtkStream &  stream,
svtkStreamMode &  mode 
)
inline

sets the stream. mode indicate synchronous behavior or not.

◆ Synchronize()

template<typename T>
void svtkHAMRDataArray< T >::Synchronize ( ) const
inline

synchronizes on the internal stream


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