VTK-m
2.0
|
Manages an array-worth of data. More...
#include <ArrayHandle.h>
Public Types | |
using | ValueType = T |
using | StorageTag = StorageTag_ |
using | StorageType = vtkm::cont::internal::Storage< ValueType, StorageTag > |
using | ReadPortalType = typename StorageType::ReadPortalType |
using | WritePortalType = typename StorageType::WritePortalType |
Public Member Functions | |
VTKM_CONT | ArrayHandle () |
Constructs an empty ArrayHandle. More... | |
VTKM_CONT | ArrayHandle (const vtkm::cont::ArrayHandle< ValueType, StorageTag > &src) |
Copy constructor. More... | |
VTKM_CONT | ArrayHandle (vtkm::cont::ArrayHandle< ValueType, StorageTag > &&src) noexcept |
Move constructor. More... | |
VTKM_CONT | ~ArrayHandle () |
Destructs an empty ArrayHandle. More... | |
VTKM_CONT vtkm::cont::ArrayHandle< ValueType, StorageTag > & | operator= (const vtkm::cont::ArrayHandle< ValueType, StorageTag > &src) |
Copies an ArrayHandle. More... | |
VTKM_CONT vtkm::cont::ArrayHandle< ValueType, StorageTag > & | operator= (vtkm::cont::ArrayHandle< ValueType, StorageTag > &&src) noexcept |
Move and Assignment of an ArrayHandle. More... | |
VTKM_CONT bool | operator== (const ArrayHandle< ValueType, StorageTag > &rhs) const |
Like a pointer, two ArrayHandles are considered equal if they point to the same location in memory. More... | |
VTKM_CONT bool | operator!= (const ArrayHandle< ValueType, StorageTag > &rhs) const |
template<typename VT , typename ST > | |
VTKM_CONT bool | operator== (const ArrayHandle< VT, ST > &) const |
template<typename VT , typename ST > | |
VTKM_CONT bool | operator!= (const ArrayHandle< VT, ST > &) const |
VTKM_CONT StorageType | GetStorage () const |
Get the storage. More... | |
VTKM_CONT WritePortalType | WritePortal () const |
Get an array portal that can be used in the control environment. More... | |
VTKM_CONT WritePortalType | WritePortal (vtkm::cont::Token &token) const |
VTKM_CONT vtkm::Id | GetNumberOfValues () const |
Returns the number of entries in the array. More... | |
VTKM_CONT void | ReleaseResourcesExecution () const |
Releases any resources being used in the execution environment (that are not being shared by the control environment). More... | |
VTKM_CONT void | ReleaseResources () const |
Releases all resources in both the control and execution environments. More... | |
VTKM_CONT ReadPortalType | PrepareForInput (vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const |
Prepares this array to be used as an input to an operation in the execution environment. More... | |
VTKM_CONT WritePortalType | PrepareForInPlace (vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const |
Prepares this array to be used in an in-place operation (both as input and output) in the execution environment. More... | |
VTKM_CONT WritePortalType | PrepareForOutput (vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const |
Prepares (allocates) this array to be used as an output from an operation in the execution environment. More... | |
VTKM_CONT bool | IsOnDevice (vtkm::cont::DeviceAdapterId device) const |
Returns true if the ArrayHandle's data is on the given device. More... | |
VTKM_CONT bool | IsOnHost () const |
Returns true if the ArrayHandle's data is on the host. More... | |
VTKM_CONT void | SyncControlArray () const |
Synchronizes the control array with the execution array. More... | |
VTKM_CONT void | Enqueue (const vtkm::cont::Token &token) const |
Enqueue a token for access to this ArrayHandle. More... | |
VTKM_CONT void | DeepCopyFrom (const vtkm::cont::ArrayHandle< ValueType, StorageTag > &source) const |
Deep copies the data in the array. More... | |
const VTKM_CONT std::vector< vtkm::cont::internal::Buffer > & | GetBuffers () const |
Returns the internal Buffer structures that hold the data. More... | |
VTKM_CONT std::vector< vtkm::cont::internal::Buffer > & | GetBuffers () |
VTKM_CONT | ArrayHandle (const std::vector< vtkm::cont::internal::Buffer > &buffers) |
VTKM_CONT | ArrayHandle (std::vector< vtkm::cont::internal::Buffer > &&buffers) noexcept |
VTKM_CONT ReadPortalType | ReadPortal () const |
Get an array portal that can be used in the control environment. More... | |
VTKM_CONT ReadPortalType | ReadPortal (vtkm::cont::Token &token) const |
Get an array portal that can be used in the control environment. More... | |
VTKM_CONT void | Allocate (vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const |
Allocates an array large enough to hold the given number of values. More... | |
VTKM_CONT void | Allocate (vtkm::Id numberOfValues, vtkm::CopyFlag preserve=vtkm::CopyFlag::Off) const |
Allocates an array large enough to hold the given number of values. More... | |
VTKM_CONT void | AllocateAndFill (vtkm::Id numberOfValues, const ValueType &fillValue, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const |
Allocates an array and fills it with an initial value. More... | |
VTKM_CONT void | AllocateAndFill (vtkm::Id numberOfValues, const ValueType &fillValue, vtkm::CopyFlag preserve=vtkm::CopyFlag::Off) const |
Allocates an array and fills it with an initial value. More... | |
VTKM_CONT void | Fill (const ValueType &fillValue, vtkm::Id startIndex, vtkm::Id endIndex, vtkm::cont::Token &token) const |
Fills the array with a given value. More... | |
VTKM_CONT void | Fill (const ValueType &fillValue, vtkm::Id startIndex, vtkm::Id endIndex) const |
Fills the array with a given value. More... | |
VTKM_CONT void | Fill (const ValueType &fillValue, vtkm::Id startIndex=0) const |
Fills the array with a given value. More... | |
Protected Member Functions | |
VTKM_CONT void | SetBuffer (vtkm::IdComponent index, const vtkm::cont::internal::Buffer &buffer) |
VTKM_CONT void | SetBuffers (const std::vector< vtkm::cont::internal::Buffer > &buffers) |
VTKM_CONT void | SetBuffers (std::vector< vtkm::cont::internal::Buffer > &&buffers) |
Private Member Functions | |
VTKM_STATIC_ASSERT_MSG ((internal::IsValidArrayHandle< T, StorageTag_ >::value), "Attempted to create an ArrayHandle with an invalid type/storage combination.") | |
Private Attributes | |
std::vector< vtkm::cont::internal::Buffer > | Buffers |
Manages an array-worth of data.
ArrayHandle
manages as array of data that can be manipulated by VTKm algorithms. The ArrayHandle
may have up to two copies of the array, one for the control environment and one for the execution environment, although depending on the device and how the array is being used, the ArrayHandle
will only have one copy when possible.
An ArrayHandle
is often constructed by instantiating one of the ArrayHandle
subclasses. Several basic ArrayHandle
types can also be constructed directly and then allocated. The ArrayHandleBasic
subclass provides mechanisms for importing user arrays into an ArrayHandle
.
ArrayHandle
behaves like a shared smart pointer in that when it is copied each copy holds a reference to the same array. These copies are reference counted so that when all copies of the ArrayHandle
are destroyed, any allocated memory is released.
using vtkm::cont::ArrayHandle< T, StorageTag_ >::ReadPortalType = typename StorageType::ReadPortalType |
using vtkm::cont::ArrayHandle< T, StorageTag_ >::StorageTag = StorageTag_ |
using vtkm::cont::ArrayHandle< T, StorageTag_ >::StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag> |
using vtkm::cont::ArrayHandle< T, StorageTag_ >::ValueType = T |
using vtkm::cont::ArrayHandle< T, StorageTag_ >::WritePortalType = typename StorageType::WritePortalType |
|
inline |
Constructs an empty ArrayHandle.
|
inline |
Copy constructor.
Implemented so that it is defined exclusively in the control environment. If there is a separate device for the execution environment (for example, with CUDA), then the automatically generated copy constructor could be created for all devices, and it would not be valid for all devices.
|
inlinenoexcept |
Move constructor.
Implemented so that it is defined exclusively in the control environment. If there is a separate device for the execution environment (for example, with CUDA), then the automatically generated move constructor could be created for all devices, and it would not be valid for all devices.
|
inline |
Special constructor for subclass specializations that need to set the initial state array. Used when pulling data from other sources.
|
inlinenoexcept |
Special constructor for subclass specializations that need to set the initial state array. Used when pulling data from other sources.
|
inline |
Destructs an empty ArrayHandle.
Implemented so that it is defined exclusively in the control environment. If there is a separate device for the execution environment (for example, with CUDA), then the automatically generated destructor could be created for all devices, and it would not be valid for all devices.
|
inline |
Allocates an array large enough to hold the given number of values.
The allocation may be done on an already existing array. If so, then the data are preserved as best as possible if the preserve flag is set to vtkm::CopyFlag::On
. If the preserve flag is set to vtkm::CopyFlag::Off
(the default), any existing data could be wiped out.
This method can throw ErrorBadAllocation
if the array cannot be allocated or ErrorBadValue
if the allocation is not feasible (for example, the array storage is read-only).
|
inline |
Allocates an array large enough to hold the given number of values.
The allocation may be done on an already existing array. If so, then the data are preserved as best as possible if the preserve flag is set to vtkm::CopyFlag::On
. If the preserve flag is set to vtkm::CopyFlag::Off
(the default), any existing data could be wiped out.
This method can throw ErrorBadAllocation
if the array cannot be allocated or ErrorBadValue
if the allocation is not feasible (for example, the array storage is read-only).
|
inline |
Allocates an array and fills it with an initial value.
AllocateAndFill
behaves similar to Allocate
except that after allocation it fills the array with a given fillValue
. This method is convenient when you wish to initialize the array.
If the preserve
flag is vtkm::CopyFlag::On
, then any data that existed before the call to AllocateAndFill
will remain after the call (assuming the new array size is large enough). If the array size is expanded, then the new values at the end will be filled.
If the preserve
flag is vtkm::CopyFlag::Off
(the default), the entire array is filled with the given fillValue
.
|
inline |
Allocates an array and fills it with an initial value.
AllocateAndFill
behaves similar to Allocate
except that after allocation it fills the array with a given fillValue
. This method is convenient when you wish to initialize the array.
If the preserve
flag is vtkm::CopyFlag::On
, then any data that existed before the call to AllocateAndFill
will remain after the call (assuming the new array size is large enough). If the array size is expanded, then the new values at the end will be filled.
If the preserve
flag is vtkm::CopyFlag::Off
(the default), the entire array is filled with the given fillValue
.
|
inline |
Deep copies the data in the array.
Takes the data that is in source and copies that data into this array.
|
inline |
Enqueue a token for access to this ArrayHandle.
This method places the given Token
into the queue of Token
s waiting for access to this ArrayHandle
and then returns immediately. When this token is later used to get data from this ArrayHandle
(for example, in a call to PrepareForInput
), it will use this place in the queue while waiting for access.
This method is to be used to ensure that a set of accesses to an ArrayHandle
that happen on multiple threads occur in a specified order. For example, if you spawn of a job to modify data in an ArrayHandle
and then spawn off a job that reads that same data, you need to make sure that the first job gets access to the ArrayHandle
before the second. If they both just attempt to call their respective Prepare
methods, there is no guarantee which order they will occur. Having the spawning thread first call this method will ensure the order.
Prepare
methods that attaches the token to this ArrayHandle
. Otherwise, the enqueued token will block any subsequent access to the ArrayHandle
, even if the Token
is destroyed.
|
inline |
Fills the array with a given value.
After calling this method, every entry in the array from startIndex
to endIndex
. of the array is set to fillValue
. If startIndex
or endIndex
is not specified, then the fill happens from the begining or end, respectively.
|
inline |
Fills the array with a given value.
After calling this method, every entry in the array from startIndex
to endIndex
. of the array is set to fillValue
. If startIndex
or endIndex
is not specified, then the fill happens from the begining or end, respectively.
|
inline |
Fills the array with a given value.
After calling this method, every entry in the array from startIndex
to endIndex
. of the array is set to fillValue
. If startIndex
or endIndex
is not specified, then the fill happens from the begining or end, respectively.
|
inline |
|
inline |
Returns the internal Buffer
structures that hold the data.
Note that great care should be taken when modifying buffers outside of the ArrayHandle.
|
inline |
Returns the number of entries in the array.
|
inline |
Get the storage.
|
inline |
Returns true if the ArrayHandle's data is on the given device.
If the data are on the given device, then preparing for that device should not require any data movement.
|
inline |
Returns true if the ArrayHandle's data is on the host.
If the data are on the given device, then calling ReadPortal
or WritePortal
should not require any data movement.
|
inline |
|
inline |
|
inline |
Copies an ArrayHandle.
|
inlinenoexcept |
Move and Assignment of an ArrayHandle.
|
inline |
Like a pointer, two ArrayHandles
are considered equal if they point to the same location in memory.
|
inline |
|
inline |
Prepares this array to be used in an in-place operation (both as input and output) in the execution environment.
If necessary, copies data to the execution environment. Can throw an exception if this array does not yet contain any data. Returns a portal that can be used in code running in the execution environment.
The Token
object provided will be attached to this ArrayHandle
. The returned portal is guaranteed to be valid while the Token
is still attached and in scope. Other operations on this ArrayHandle
that would invalidate the returned portal will block until the Token
is released. Likewise, this method will block if another Token
is already attached. This can potentially lead to deadlocks.
|
inline |
Prepares this array to be used as an input to an operation in the execution environment.
If necessary, copies data to the execution environment. Can throw an exception if this array does not yet contain any data. Returns a portal that can be used in code running in the execution environment.
The Token
object provided will be attached to this ArrayHandle
. The returned portal is guaranteed to be valid while the Token
is still attached and in scope. Other operations on this ArrayHandle
that would invalidate the returned portal will block until the Token
is released. Likewise, this method will block if another Token
is already attached. This can potentially lead to deadlocks.
|
inline |
Prepares (allocates) this array to be used as an output from an operation in the execution environment.
The internal state of this class is set to have valid data in the execution array with the assumption that the array will be filled soon (i.e. before any other methods of this object are called). Returns a portal that can be used in code running in the execution environment.
The Token
object provided will be attached to this ArrayHandle
. The returned portal is guaranteed to be valid while the Token
is still attached and in scope. Other operations on this ArrayHandle
that would invalidate the returned portal will block until the Token
is released. Likewise, this method will block if another Token
is already attached. This can potentially lead to deadlocks.
|
inline |
Get an array portal that can be used in the control environment.
The returned array can be used in the control environment to read values from the array. (It is not possible to write to the returned portal. That is Get
will work on the portal, but Set
will not.)
Note: The returned portal cannot be used in the execution environment. This is because the portal will not work on some devices like GPUs. To get a portal that will work in the execution environment, use PrepareForInput
.
|
inline |
Get an array portal that can be used in the control environment.
The returned array can be used in the control environment to read values from the array. (It is not possible to write to the returned portal. That is Get
will work on the portal, but Set
will not.)
Note: The returned portal cannot be used in the execution environment. This is because the portal will not work on some devices like GPUs. To get a portal that will work in the execution environment, use PrepareForInput
.
|
inline |
Releases all resources in both the control and execution environments.
|
inline |
Releases any resources being used in the execution environment (that are not being shared by the control environment).
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
Synchronizes the control array with the execution array.
If either the user array or control array is already valid, this method does nothing (because the data is already available in the control environment). Although the internal state of this class can change, the method is declared const because logically the data does not.
|
private |
|
inline |
Get an array portal that can be used in the control environment.
The returned array can be used in the control environment to reand and write values to the array.
Note: The returned portal cannot be used in the execution environment. This is because the portal will not work on some devices like GPUs. To get a portal that will work in the execution environment, use PrepareForInput
.
|
inline |
|
mutableprivate |