Go to the documentation of this file.
10 #ifndef vtk_m_cont_ArrayHandle_h
11 #define vtk_m_cont_ArrayHandle_h
51 #if VTKM_STORAGE == VTKM_STORAGE_BASIC
53 #define VTKM_DEFAULT_STORAGE_TAG ::vtkm::cont::StorageTagBasic
55 #elif VTKM_STORAGE == VTKM_STORAGE_ERROR
58 #define VTKM_DEFAULT_STORAGE_TAG ::vtkm::cont::internal::StorageTagError
60 #elif (VTKM_STORAGE == VTKM_STORAGE_UNDEFINED) || !defined(VTKM_STORAGE)
62 #ifndef VTKM_DEFAULT_STORAGE_TAG
63 #warning If array storage is undefined, VTKM_DEFAULT_STORAGE_TAG must be defined.
90 template <
typename T,
typename StorageTag>
91 using IsValidArrayHandle =
92 std::integral_constant<bool,
93 !(std::is_base_of<vtkm::cont::internal::UndefinedStorage,
94 vtkm::cont::internal::Storage<T, StorageTag>>::value)>;
100 template <
typename T,
typename StorageTag>
101 using IsInvalidArrayHandle =
102 std::integral_constant<bool, !IsValidArrayHandle<T, StorageTag>::value>;
110 template <
typename ArrayHandle>
111 using IsWritableArrayHandle =
112 vtkm::internal::PortalSupportsSets<typename std::decay<ArrayHandle>::type::WritePortalType>;
126 template <
typename T>
127 struct ArrayHandleCheck
128 : std::is_base_of<vtkm::cont::internal::ArrayHandleBase, std::decay_t<T>>::type
137 #define VTKM_IS_ARRAY_HANDLE(T) VTKM_STATIC_ASSERT(::vtkm::cont::internal::ArrayHandleCheck<T>{})
144 template <
typename T>
145 struct GetTypeInParentheses;
146 template <
typename T>
147 struct GetTypeInParentheses<void(T)>
155 #define VTK_M_ARRAY_HANDLE_SUBCLASS_IMPL(classname, fullclasstype, superclass, typename__) \
156 using Thisclass = typename__ vtkm::cont::detail::GetTypeInParentheses<void fullclasstype>::type; \
157 using Superclass = typename__ vtkm::cont::detail::GetTypeInParentheses<void superclass>::type; \
159 VTKM_IS_ARRAY_HANDLE(Superclass); \
165 classname(const Thisclass& src) \
171 classname(Thisclass&& src) noexcept \
172 : Superclass(std::move(src)) \
177 classname(const vtkm::cont::ArrayHandle<typename__ Superclass::ValueType, \
178 typename__ Superclass::StorageTag>& src) \
184 classname(vtkm::cont::ArrayHandle<typename__ Superclass::ValueType, \
185 typename__ Superclass::StorageTag>&& src) noexcept \
186 : Superclass(std::move(src)) \
191 explicit classname(const std::vector<vtkm::cont::internal::Buffer>& buffers) \
192 : Superclass(buffers) \
197 explicit classname(std::vector<vtkm::cont::internal::Buffer>&& buffers) noexcept \
198 : Superclass(std::move(buffers)) \
203 Thisclass& operator=(const Thisclass& src) \
205 this->Superclass::operator=(src); \
210 Thisclass& operator=(Thisclass&& src) noexcept \
212 this->Superclass::operator=(std::move(src)); \
216 using ValueType = typename__ Superclass::ValueType; \
217 using StorageTag = typename__ Superclass::StorageTag; \
218 using StorageType = typename__ Superclass::StorageType; \
219 using ReadPortalType = typename__ Superclass::ReadPortalType; \
220 using WritePortalType = typename__ Superclass::WritePortalType
243 #define VTKM_ARRAY_HANDLE_SUBCLASS(classname, fullclasstype, superclass) \
244 VTK_M_ARRAY_HANDLE_SUBCLASS_IMPL(classname, fullclasstype, superclass, typename)
266 #define VTKM_ARRAY_HANDLE_SUBCLASS_NT(classname, superclass) \
267 VTK_M_ARRAY_HANDLE_SUBCLASS_IMPL(classname, (classname), superclass, )
273 const std::vector<vtkm::cont::internal::Buffer>& buffers);
276 const std::vector<vtkm::cont::internal::Buffer>& buffers,
299 template <
typename T,
typename StorageTag_ = VTKM_DEFAULT_STORAGE_TAG>
303 (internal::IsValidArrayHandle<T, StorageTag_>::value),
304 "Attempted to create an ArrayHandle with an invalid type/storage combination.");
309 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
329 : Buffers(src.Buffers)
341 : Buffers(std::move(src.Buffers))
357 : Buffers(std::move(buffers))
386 this->Buffers = std::move(src.Buffers);
396 return this->Buffers == rhs.
Buffers;
402 return this->Buffers != rhs.
Buffers;
405 template <
typename VT,
typename ST>
411 template <
typename VT,
typename ST>
434 return this->ReadPortal(token);
439 return StorageType::CreateReadPortal(
455 return this->WritePortal(token);
460 return StorageType::CreateWritePortal(
468 return StorageType::GetNumberOfValues(this->GetBuffers());
474 return StorageType::GetNumberOfComponentsFlat(this->GetBuffers());
492 StorageType::ResizeBuffers(numberOfValues, this->GetBuffers(), preserve, token);
500 this->Allocate(numberOfValues, preserve, token);
528 this->Allocate(numberOfValues, preserve, token);
530 if (startIndex < numberOfValues)
532 this->Fill(fillValue, startIndex, numberOfValues, token);
542 this->AllocateAndFill(numberOfValues, fillValue, preserve, token);
557 StorageType::Fill(this->GetBuffers(), fillValue, startIndex, endIndex, token);
563 this->Fill(fillValue, startIndex, endIndex, token);
569 this->Fill(fillValue, startIndex, this->GetNumberOfValues(), token);
577 detail::ArrayHandleReleaseResourcesExecution(this->Buffers);
600 return StorageType::CreateReadPortal(this->GetBuffers(), device, token);
619 return StorageType::CreateWritePortal(this->GetBuffers(), device, token);
641 return StorageType::CreateWritePortal(this->GetBuffers(), device, token);
649 return detail::ArrayHandleIsOnDevice(this->Buffers, device);
695 for (
auto&& buffer : this->Buffers)
697 buffer.Enqueue(token);
709 for (std::size_t bufferIndex = 0; bufferIndex < this->Buffers.size(); ++bufferIndex)
711 this->Buffers[bufferIndex].DeepCopyFrom(source.
Buffers[bufferIndex]);
721 return this->Buffers;
726 mutable std::vector<vtkm::cont::internal::Buffer>
Buffers;
731 this->Buffers[
static_cast<std::size_t
>(index)] = buffer;
736 this->Buffers = buffers;
740 this->Buffers = std::move(buffers);
747 template <
typename T>
756 inline void printSummary_ArrayHandle_Value(
vtkm::UInt8 value,
760 out << static_cast<int>(value);
765 inline void printSummary_ArrayHandle_Value(
vtkm::Int8 value,
769 out << static_cast<int>(value);
772 template <
typename T>
779 using ComponentType =
typename Traits::ComponentType;
783 printSummary_ArrayHandle_Value(Traits::GetComponent(value, 0), out, IsVecOfVec());
787 printSummary_ArrayHandle_Value(Traits::GetComponent(value, index), out, IsVecOfVec());
792 template <
typename T1,
typename T2>
799 printSummary_ArrayHandle_Value(
802 printSummary_ArrayHandle_Value(
811 template <
typename T,
typename StorageT>
818 using PortalType =
typename ArrayType::ReadPortalType;
823 out <<
"valueType=" << vtkm::cont::TypeToString<T>()
824 <<
" storageType=" << vtkm::cont::TypeToString<StorageT>() <<
" " << sz
825 <<
" values occupying " << (
static_cast<size_t>(sz) *
sizeof(T)) <<
" bytes [";
832 detail::printSummary_ArrayHandle_Value(portal.Get(i), out, IsVec());
841 detail::printSummary_ArrayHandle_Value(portal.Get(0), out, IsVec());
843 detail::printSummary_ArrayHandle_Value(portal.Get(1), out, IsVec());
845 detail::printSummary_ArrayHandle_Value(portal.Get(2), out, IsVec());
847 detail::printSummary_ArrayHandle_Value(portal.Get(sz - 3), out, IsVec());
849 detail::printSummary_ArrayHandle_Value(portal.Get(sz - 2), out, IsVec());
851 detail::printSummary_ArrayHandle_Value(portal.Get(sz - 1), out, IsVec());
862 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>&);
863 template <
typename T,
typename S,
typename... Args>
864 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
866 const Args&... args);
867 template <
typename... Args>
868 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
869 const vtkm::cont::internal::Buffer& buffer,
870 const Args&... args);
872 template <
typename... Args>
873 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
874 const std::vector<vtkm::cont::internal::Buffer>& addbuffs,
875 const Args&... args);
876 template <
typename Arg0,
typename... Args>
877 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
879 const Args&... args);
881 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>&)
886 template <
typename T,
typename S,
typename... Args>
887 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
891 CreateBuffersImpl(buffers, array.
GetBuffers(), args...);
894 template <
typename... Args>
895 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
896 const vtkm::cont::internal::Buffer& buffer,
899 buffers.push_back(buffer);
900 CreateBuffersImpl(buffers, args...);
903 template <
typename... Args>
904 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
905 const std::vector<vtkm::cont::internal::Buffer>& addbuffs,
908 buffers.insert(buffers.end(), addbuffs.begin(), addbuffs.end());
909 CreateBuffersImpl(buffers, args...);
912 template <
typename T,
typename S,
typename... Args>
913 VTKM_CONT inline void CreateBuffersResolveArrays(std::vector<vtkm::cont::internal::Buffer>& buffers,
918 CreateBuffersImpl(buffers, array, args...);
921 template <
typename MetaData,
typename... Args>
922 VTKM_CONT inline void CreateBuffersResolveArrays(std::vector<vtkm::cont::internal::Buffer>& buffers,
924 const MetaData& metadata,
927 vtkm::cont::internal::Buffer buffer;
928 buffer.SetMetaData(metadata);
929 buffers.push_back(std::move(buffer));
930 CreateBuffersImpl(buffers, args...);
933 template <
typename Arg0,
typename... Args>
934 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
942 using IsArray =
typename vtkm::cont::internal::ArrayHandleCheck<Arg0>::type::type;
943 CreateBuffersResolveArrays(buffers, IsArray{}, arg0, args...);
962 template <
typename... Args>
963 VTKM_CONT inline std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
const Args&... args)
965 std::vector<vtkm::cont::internal::Buffer> buffers;
966 buffers.reserve(
sizeof...(args));
967 detail::CreateBuffersImpl(buffers, args...);
976 #ifndef vtk_m_cont_ArrayHandleBasic_h
980 #endif //vtk_m_cont_ArrayHandle_h
void SyncControlArray() const
Synchronizes the control array with the execution array.
Definition: ArrayHandle.h:666
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.
Definition: ArrayHandle.h:537
Manages an array-worth of data.
Definition: ArrayHandle.h:300
std::vector< vtkm::cont::internal::Buffer > Buffers
Definition: ArrayHandle.h:726
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.
Definition: ArrayHandle.h:394
const std::vector< vtkm::cont::internal::Buffer > & GetBuffers() const
Returns the internal Buffer structures that hold the data.
Definition: ArrayHandle.h:719
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:23
Groups connected points that have the same field value.
Definition: Atomic.h:19
StorageType GetStorage() const
Get the storage.
Definition: ArrayHandle.h:419
void Enqueue(const vtkm::cont::Token &token) const
Enqueue a token for access to this ArrayHandle.
Definition: ArrayHandle.h:693
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
void printSummary_ArrayHandle(const vtkm::cont::ArrayHandle< T, StorageT > &array, std::ostream &out, bool full=false)
Definition: ArrayHandle.h:812
void Fill(const ValueType &fillValue, vtkm::Id startIndex, vtkm::Id endIndex, vtkm::cont::Token &token) const
Fills the array with a given value.
Definition: ArrayHandle.h:552
void ReleaseResourcesExecution() const
Releases any resources being used in the execution environment (that are not being shared by the cont...
Definition: ArrayHandle.h:575
bool operator!=(const ArrayHandle< ValueType, StorageTag > &rhs) const
Definition: ArrayHandle.h:400
vtkm::cont::ArrayHandle< ValueType, StorageTag > & operator=(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &src)
Shallow copies an ArrayHandle.
Definition: ArrayHandle.h:373
void SetBuffer(vtkm::IdComponent index, const vtkm::cont::internal::Buffer &buffer)
Definition: ArrayHandle.h:729
std::vector< vtkm::cont::internal::Buffer > & GetBuffers()
Definition: ArrayHandle.h:723
vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:466
bool operator!=(const ArrayHandle< VT, ST > &) const
Definition: ArrayHandle.h:412
vtkm::Id ValueType
Definition: ArrayHandle.h:307
ArrayHandle(vtkm::cont::ArrayHandle< ValueType, StorageTag > &&src) noexcept
Move constructor.
Definition: ArrayHandle.h:340
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:311
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
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 e...
Definition: ArrayHandle.h:616
void SetBuffers(const std::vector< vtkm::cont::internal::Buffer > &buffers)
Definition: ArrayHandle.h:734
~ArrayHandle()
Destructs an empty ArrayHandle.
Definition: ArrayHandle.h:368
int8_t Int8
Base type to use for 8-bit signed integer numbers.
Definition: Types.h:165
FirstType first
The pair's first object.
Definition: Pair.h:50
#define VTKM_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:18
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
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 environmen...
Definition: ArrayHandle.h:636
ArrayHandle(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &src)
Copy constructor.
Definition: ArrayHandle.h:328
#define VTKM_CONT
Definition: ExportMacros.h:57
void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:582
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
typename StorageType::WritePortalType WritePortalType
Definition: ArrayHandle.h:312
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
ReadPortalType ReadPortal(vtkm::cont::Token &token) const
Definition: ArrayHandle.h:437
void DeepCopyFrom(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &source) const
Deep copies the data in the array.
Definition: ArrayHandle.h:705
ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:431
ArrayHandle(std::vector< vtkm::cont::internal::Buffer > &&buffers) noexcept
Special constructor for subclass specializations that need to set the initial state array.
Definition: ArrayHandle.h:356
bool IsOnDevice(vtkm::cont::DeviceAdapterId device) const
Returns true if the ArrayHandle's data is on the given device.
Definition: ArrayHandle.h:647
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
void Fill(const ValueType &fillValue, vtkm::Id startIndex=0) const
Fills the array with a given value.
Definition: ArrayHandle.h:566
Tag for a device adapter used to avoid specifying a device.
Definition: DeviceAdapterTag.h:187
VTKM_DEFAULT_STORAGE_TAG StorageTag
Definition: ArrayHandle.h:308
vtkm::cont::internal::Storage< ValueType, StorageTag > StorageType
Definition: ArrayHandle.h:309
A tag for the basic implementation of a Storage object.
Definition: ArrayHandle.h:45
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.
Definition: ArrayHandle.h:597
CopyFlag
Identifier used to specify whether a function should deep copy data.
Definition: Flags.h:17
void Fill(const ValueType &fillValue, vtkm::Id startIndex, vtkm::Id endIndex) const
Fills the array with a given value.
Definition: ArrayHandle.h:560
#define VTKM_NEVER_EXPORT
Definition: ExportMacros.h:90
WritePortalType WritePortal(vtkm::cont::Token &token) const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:458
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.
Definition: ArrayHandle.h:488
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:61
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
bool operator==(const ArrayHandle< VT, ST > &) const
Definition: ArrayHandle.h:406
vtkm::IdComponent GetNumberOfComponentsFlat() const
Returns the total number of components for each value in the array.
Definition: ArrayHandle.h:472
WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:452
ArrayHandle(const std::vector< vtkm::cont::internal::Buffer > &buffers)
Special constructor for subclass specializations that need to set the initial state array.
Definition: ArrayHandle.h:348
bool IsOnHost() const
Returns true if the ArrayHandle's data is on the host.
Definition: ArrayHandle.h:655
A vtkm::Pair is essentially the same as an STL pair object except that the methods (constructors and ...
Definition: Pair.h:29
SecondType second
The pair's second object.
Definition: Pair.h:55
void SetBuffers(std::vector< vtkm::cont::internal::Buffer > &&buffers)
Definition: ArrayHandle.h:738
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.
Definition: ArrayHandle.h:517
ArrayHandle()
Constructs an empty ArrayHandle.
Definition: ArrayHandle.h:316
void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve=vtkm::CopyFlag::Off) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:496
vtkm::cont::ArrayHandle< ValueType, StorageTag > & operator=(vtkm::cont::ArrayHandle< ValueType, StorageTag > &&src) noexcept
Move and Assignment of an ArrayHandle.
Definition: ArrayHandle.h:383