10 #ifndef vtk_m_cont_ArrayHandleStride_h
11 #define vtk_m_cont_ArrayHandleStride_h
23 struct ArrayStrideInfo
31 ArrayStrideInfo() =
default;
38 : NumberOfValues(numValues)
49 if (this->Divisor > 1)
51 arrayIndex = arrayIndex / this->Divisor;
55 arrayIndex = arrayIndex % this->Modulo;
57 arrayIndex = (arrayIndex * this->Stride) + this->Offset;
63 class ArrayPortalStrideRead
65 const T* Array =
nullptr;
69 ArrayPortalStrideRead() =
default;
70 ArrayPortalStrideRead(ArrayPortalStrideRead&&) =
default;
71 ArrayPortalStrideRead(
const ArrayPortalStrideRead&) =
default;
72 ArrayPortalStrideRead& operator=(ArrayPortalStrideRead&&) =
default;
73 ArrayPortalStrideRead& operator=(
const ArrayPortalStrideRead&) =
default;
75 ArrayPortalStrideRead(
const T* array,
const ArrayStrideInfo& info)
90 return detail::ArrayPortalBasicReadGet(this->Array + this->Info.ArrayIndex(index));
93 VTKM_EXEC_CONT const ValueType* GetArray()
const {
return this->Array; }
94 VTKM_EXEC_CONT const ArrayStrideInfo& GetInfo()
const {
return this->Info; }
98 class ArrayPortalStrideWrite
101 ArrayStrideInfo
Info;
104 ArrayPortalStrideWrite() =
default;
105 ArrayPortalStrideWrite(ArrayPortalStrideWrite&&) =
default;
106 ArrayPortalStrideWrite(
const ArrayPortalStrideWrite&) =
default;
107 ArrayPortalStrideWrite& operator=(ArrayPortalStrideWrite&&) =
default;
108 ArrayPortalStrideWrite& operator=(
const ArrayPortalStrideWrite&) =
default;
110 ArrayPortalStrideWrite(T* array,
const ArrayStrideInfo& info)
125 return detail::ArrayPortalBasicWriteGet(this->Array + this->Info.ArrayIndex(index));
133 detail::ArrayPortalBasicWriteSet(this->Array + this->Info.ArrayIndex(index), value);
136 VTKM_EXEC_CONT ValueType* GetArray()
const {
return this->Array; }
137 VTKM_EXEC_CONT const ArrayStrideInfo& GetInfo()
const {
return this->Info; }
155 template <
typename T>
158 using StrideInfo = vtkm::internal::ArrayStrideInfo;
163 using ReadPortalType = vtkm::internal::ArrayPortalStrideRead<T>;
164 using WritePortalType = vtkm::internal::ArrayPortalStrideWrite<T>;
166 VTKM_CONT static StrideInfo& GetInfo(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
168 return buffers[0].GetMetaData<StrideInfo>();
172 const std::vector<vtkm::cont::internal::Buffer>& buffers)
174 return GetInfo(buffers).NumberOfValues;
177 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
186 VTKM_CONT static ReadPortalType CreateReadPortal(
187 const std::vector<vtkm::cont::internal::Buffer>& buffers,
191 return ReadPortalType(
reinterpret_cast<const T*
>(buffers[1].ReadPointerDevice(device, token)),
195 VTKM_CONT static WritePortalType CreateWritePortal(
196 const std::vector<vtkm::cont::internal::Buffer>& buffers,
200 return WritePortalType(
reinterpret_cast<T*
>(buffers[1].WritePointerDevice(device, token)),
204 static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
205 const vtkm::cont::internal::Buffer& sourceBuffer = vtkm::cont::internal::Buffer{},
206 vtkm::internal::ArrayStrideInfo&& info = vtkm::internal::ArrayStrideInfo{})
208 return vtkm::cont::internal::CreateBuffers(info, sourceBuffer);
212 const std::vector<vtkm::cont::internal::Buffer>& buffers)
250 template <
typename T>
260 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
265 vtkm::cont::internal::Buffer{},
266 vtkm::internal::ArrayStrideInfo(0, stride, offset, modulo, divisor)))
277 array.GetBuffers()[0],
278 vtkm::internal::ArrayStrideInfo(numValues, stride, offset, modulo, divisor)))
290 vtkm::internal::ArrayStrideInfo(numValues, stride, offset, modulo, divisor)))
301 return StorageType::GetBasicArray(this->GetBuffers());
316 template <
typename T>
317 struct SerializableTypeString<
vtkm::cont::ArrayHandleStride<T>>
326 template <
typename T>
327 struct SerializableTypeString<
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagStride>>
328 : SerializableTypeString<vtkm::cont::ArrayHandleStride<T>>
338 template <
typename T>
339 struct Serialization<
vtkm::cont::ArrayHandleStride<T>>
345 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj_)
363 vtkm::cont::internal::Buffer buffer;
381 #ifndef vtk_m_cont_ArrayHandleStride_cxx
391 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<char, StorageTagStride>;
392 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::Int8, StorageTagStride>;
393 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::UInt8, StorageTagStride>;
394 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::Int16, StorageTagStride>;
395 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::UInt16, StorageTagStride>;
396 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::Int32, StorageTagStride>;
397 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::UInt32, StorageTagStride>;
398 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::Int64, StorageTagStride>;
399 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::UInt64, StorageTagStride>;
400 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::Float32, StorageTagStride>;
401 extern template class VTKM_CONT_TEMPLATE_EXPORT Storage<vtkm::Float64, StorageTagStride>;
405 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<char, StorageTagStride>;
406 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Int8, StorageTagStride>;
407 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::UInt8, StorageTagStride>;
408 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Int16, StorageTagStride>;
409 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::UInt16, StorageTagStride>;
410 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Int32, StorageTagStride>;
411 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::UInt32, StorageTagStride>;
412 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Int64, StorageTagStride>;
413 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::UInt64, StorageTagStride>;
414 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Float32, StorageTagStride>;
415 extern template class VTKM_CONT_TEMPLATE_EXPORT ArrayHandle<vtkm::Float64, StorageTagStride>;
420 #endif //vtk_m_cont_ArrayHandleStride_cxx
423 #endif //vtk_m_cont_ArrayHandleStride_h