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>;
331 : Buffers(src.Buffers)
343 : Buffers(std::move(src.Buffers))
359 : Buffers(std::move(buffers))
388 this->Buffers = std::move(src.Buffers);
398 return this->Buffers == rhs.
Buffers;
404 return this->Buffers != rhs.
Buffers;
407 template <
typename VT,
typename ST>
413 template <
typename VT,
typename ST>
436 return this->ReadPortal(token);
441 return StorageType::CreateReadPortal(
457 return this->WritePortal(token);
462 return StorageType::CreateWritePortal(
470 return StorageType::GetNumberOfValues(this->GetBuffers());
476 return StorageType::GetNumberOfComponentsFlat(this->GetBuffers());
494 StorageType::ResizeBuffers(numberOfValues, this->GetBuffers(), preserve, token);
502 this->Allocate(numberOfValues, preserve, token);
530 this->Allocate(numberOfValues, preserve, token);
532 if (startIndex < numberOfValues)
534 this->Fill(fillValue, startIndex, numberOfValues, token);
544 this->AllocateAndFill(numberOfValues, fillValue, preserve, token);
559 StorageType::Fill(this->GetBuffers(), fillValue, startIndex, endIndex, token);
565 this->Fill(fillValue, startIndex, endIndex, token);
571 this->Fill(fillValue, startIndex, this->GetNumberOfValues(), token);
579 detail::ArrayHandleReleaseResourcesExecution(this->Buffers);
602 return StorageType::CreateReadPortal(this->GetBuffers(), device, token);
621 return StorageType::CreateWritePortal(this->GetBuffers(), device, token);
643 return StorageType::CreateWritePortal(this->GetBuffers(), device, token);
651 return detail::ArrayHandleIsOnDevice(this->Buffers, device);
697 for (
auto&& buffer : this->Buffers)
699 buffer.Enqueue(token);
711 for (std::size_t bufferIndex = 0; bufferIndex < this->Buffers.size(); ++bufferIndex)
713 this->Buffers[bufferIndex].DeepCopyFrom(source.
Buffers[bufferIndex]);
723 return this->Buffers;
728 mutable std::vector<vtkm::cont::internal::Buffer>
Buffers;
733 this->Buffers[
static_cast<std::size_t
>(index)] = buffer;
738 this->Buffers = buffers;
742 this->Buffers = std::move(buffers);
749 template <
typename T>
758 inline void printSummary_ArrayHandle_Value(
vtkm::UInt8 value,
762 out << static_cast<int>(value);
767 inline void printSummary_ArrayHandle_Value(
vtkm::Int8 value,
771 out << static_cast<int>(value);
774 template <
typename T>
781 using ComponentType =
typename Traits::ComponentType;
785 printSummary_ArrayHandle_Value(Traits::GetComponent(value, 0), out, IsVecOfVec());
789 printSummary_ArrayHandle_Value(Traits::GetComponent(value, index), out, IsVecOfVec());
794 template <
typename T1,
typename T2>
801 printSummary_ArrayHandle_Value(
804 printSummary_ArrayHandle_Value(
813 template <
typename T,
typename StorageT>
820 using PortalType =
typename ArrayType::ReadPortalType;
825 out <<
"valueType=" << vtkm::cont::TypeToString<T>()
826 <<
" storageType=" << vtkm::cont::TypeToString<StorageT>() <<
" " << sz
827 <<
" values occupying " << (
static_cast<size_t>(sz) *
sizeof(T)) <<
" bytes [";
834 detail::printSummary_ArrayHandle_Value(portal.Get(i), out, IsVec());
843 detail::printSummary_ArrayHandle_Value(portal.Get(0), out, IsVec());
845 detail::printSummary_ArrayHandle_Value(portal.Get(1), out, IsVec());
847 detail::printSummary_ArrayHandle_Value(portal.Get(2), out, IsVec());
849 detail::printSummary_ArrayHandle_Value(portal.Get(sz - 3), out, IsVec());
851 detail::printSummary_ArrayHandle_Value(portal.Get(sz - 2), out, IsVec());
853 detail::printSummary_ArrayHandle_Value(portal.Get(sz - 1), out, IsVec());
864 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>&);
865 template <
typename T,
typename S,
typename... Args>
866 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
868 const Args&... args);
869 template <
typename... Args>
870 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
871 const vtkm::cont::internal::Buffer& buffer,
872 const Args&... args);
874 template <
typename... Args>
875 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
876 const std::vector<vtkm::cont::internal::Buffer>& addbuffs,
877 const Args&... args);
878 template <
typename Arg0,
typename... Args>
879 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
881 const Args&... args);
883 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>&)
888 template <
typename T,
typename S,
typename... Args>
889 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
893 CreateBuffersImpl(buffers, array.
GetBuffers(), args...);
896 template <
typename... Args>
897 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
898 const vtkm::cont::internal::Buffer& buffer,
901 buffers.push_back(buffer);
902 CreateBuffersImpl(buffers, args...);
905 template <
typename... Args>
906 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
907 const std::vector<vtkm::cont::internal::Buffer>& addbuffs,
910 buffers.insert(buffers.end(), addbuffs.begin(), addbuffs.end());
911 CreateBuffersImpl(buffers, args...);
914 template <
typename T,
typename S,
typename... Args>
915 VTKM_CONT inline void CreateBuffersResolveArrays(std::vector<vtkm::cont::internal::Buffer>& buffers,
920 CreateBuffersImpl(buffers, array, args...);
923 template <
typename MetaData,
typename... Args>
924 VTKM_CONT inline void CreateBuffersResolveArrays(std::vector<vtkm::cont::internal::Buffer>& buffers,
926 const MetaData& metadata,
929 vtkm::cont::internal::Buffer buffer;
930 buffer.SetMetaData(metadata);
931 buffers.push_back(std::move(buffer));
932 CreateBuffersImpl(buffers, args...);
935 template <
typename Arg0,
typename... Args>
936 VTKM_CONT inline void CreateBuffersImpl(std::vector<vtkm::cont::internal::Buffer>& buffers,
944 using IsArray =
typename vtkm::cont::internal::ArrayHandleCheck<Arg0>::type::type;
945 CreateBuffersResolveArrays(buffers, IsArray{}, arg0, args...);
964 template <
typename... Args>
965 VTKM_CONT inline std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
const Args&... args)
967 std::vector<vtkm::cont::internal::Buffer> buffers;
968 buffers.reserve(
sizeof...(args));
969 detail::CreateBuffersImpl(buffers, args...);
978 #ifndef vtk_m_cont_ArrayHandleBasic_h
982 #endif //vtk_m_cont_ArrayHandle_h
void SyncControlArray() const
Synchronizes the control array with the execution array.
Definition: ArrayHandle.h:668
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:539
Manages an array-worth of data.
Definition: ArrayHandle.h:300
std::vector< vtkm::cont::internal::Buffer > Buffers
Definition: ArrayHandle.h:728
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:396
const std::vector< vtkm::cont::internal::Buffer > & GetBuffers() const
Returns the internal Buffer structures that hold the data.
Definition: ArrayHandle.h:721
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:421
void Enqueue(const vtkm::cont::Token &token) const
Enqueue a token for access to this ArrayHandle.
Definition: ArrayHandle.h:695
#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:814
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:554
void ReleaseResourcesExecution() const
Releases any resources being used in the execution environment (that are not being shared by the cont...
Definition: ArrayHandle.h:577
bool operator!=(const ArrayHandle< ValueType, StorageTag > &rhs) const
Definition: ArrayHandle.h:402
vtkm::cont::ArrayHandle< ValueType, StorageTag > & operator=(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &src)
Shallow copies an ArrayHandle.
Definition: ArrayHandle.h:375
void SetBuffer(vtkm::IdComponent index, const vtkm::cont::internal::Buffer &buffer)
Definition: ArrayHandle.h:731
std::vector< vtkm::cont::internal::Buffer > & GetBuffers()
Definition: ArrayHandle.h:725
vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:468
bool operator!=(const ArrayHandle< VT, ST > &) const
Definition: ArrayHandle.h:414
vtkm::Id ValueType
Definition: ArrayHandle.h:307
ArrayHandle(vtkm::cont::ArrayHandle< ValueType, StorageTag > &&src) noexcept
Move constructor.
Definition: ArrayHandle.h:342
typename StorageType::ReadPortalType ReadPortalType
The type of portal used when accessing data in a read-only mode.
Definition: ArrayHandle.h:312
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:618
void SetBuffers(const std::vector< vtkm::cont::internal::Buffer > &buffers)
Definition: ArrayHandle.h:736
~ArrayHandle()
Destructs an empty ArrayHandle.
Definition: ArrayHandle.h:370
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:638
ArrayHandle(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &src)
Copy constructor.
Definition: ArrayHandle.h:330
#define VTKM_CONT
Definition: ExportMacros.h:57
void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:584
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
typename StorageType::WritePortalType WritePortalType
The type of portal used when accessing data in a read-write mode.
Definition: ArrayHandle.h:314
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
ReadPortalType ReadPortal(vtkm::cont::Token &token) const
The type of portal used when accessing data in a read-only mode.
Definition: ArrayHandle.h:439
void DeepCopyFrom(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &source) const
Deep copies the data in the array.
Definition: ArrayHandle.h:707
ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:433
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:358
bool IsOnDevice(vtkm::cont::DeviceAdapterId device) const
Returns true if the ArrayHandle's data is on the given device.
Definition: ArrayHandle.h:649
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:568
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:599
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:562
#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:460
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:490
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:408
vtkm::IdComponent GetNumberOfComponentsFlat() const
Returns the total number of components for each value in the array.
Definition: ArrayHandle.h:474
WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:454
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:350
bool IsOnHost() const
Returns true if the ArrayHandle's data is on the host.
Definition: ArrayHandle.h:657
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:740
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:519
ArrayHandle()
Constructs an empty ArrayHandle.
Definition: ArrayHandle.h:318
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:498
vtkm::cont::ArrayHandle< ValueType, StorageTag > & operator=(vtkm::cont::ArrayHandle< ValueType, StorageTag > &&src) noexcept
Move and Assignment of an ArrayHandle.
Definition: ArrayHandle.h:385