18 #ifndef viskores_cont_ArrayHandleSOA_h
19 #define viskores_cont_ArrayHandleSOA_h
30 #include <viskoresstd/integer_sequence.h>
34 #include <type_traits>
46 template <
typename ValueType_,
typename ComponentPortalType>
50 using ValueType = ValueType_;
53 using ComponentType =
typename ComponentPortalType::ValueType;
59 ComponentPortalType Portals[NUM_COMPONENTS];
65 : NumberOfValues(numValues)
72 this->Portals[index] = portal;
77 template <
typename SPT = ComponentPortalType,
78 typename Supported =
typename viskores::internal::PortalSupportsGets<SPT>::type,
79 typename =
typename std::enable_if<Supported::value>::type>
82 return this->
Get(valueIndex, viskoresstd::make_index_sequence<NUM_COMPONENTS>());
85 template <
typename SPT = ComponentPortalType,
86 typename Supported =
typename viskores::internal::PortalSupportsSets<SPT>::type,
87 typename =
typename std::enable_if<Supported::value>::type>
90 this->Set(valueIndex, value, viskoresstd::make_index_sequence<NUM_COMPONENTS>());
95 template <std::
size_t I>
98 return this->Portals[I].Get(valueIndex);
101 template <std::size_t... I>
104 return ValueType{ this->GetComponent<I>(valueIndex)... };
108 template <std::
size_t I>
111 this->Portals[I].Set(valueIndex,
116 template <std::size_t... I>
118 const ValueType& value,
119 viskoresstd::index_sequence<I...>)
const
122 (void)std::initializer_list<bool>{ this->SetComponent<I>(valueIndex, value)... };
138 template <
typename ComponentType, viskores::IdComponent NUM_COMPONENTS>
139 class VISKORES_ALWAYS_EXPORT
145 using ReadPortalType =
146 viskores::internal::ArrayPortalSOA<ValueType,
147 viskores::internal::ArrayPortalBasicRead<ComponentType>>;
148 using WritePortalType =
149 viskores::internal::ArrayPortalSOA<ValueType,
150 viskores::internal::ArrayPortalBasicWrite<ComponentType>>;
152 VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> CreateBuffers()
154 return std::vector<viskores::cont::internal::Buffer>(
static_cast<std::size_t
>(NUM_COMPONENTS));
158 const std::vector<viskores::cont::internal::Buffer>&)
165 const std::vector<viskores::cont::internal::Buffer>& buffers,
170 viskores::internal::NumberOfValuesToNumberOfBytes<ComponentType>(numValues);
174 buffers[componentIndex].SetNumberOfBytes(numBytes, preserve, token);
179 const std::vector<viskores::cont::internal::Buffer>& buffers)
182 return static_cast<viskores::Id>(buffers[0].GetNumberOfBytes()) /
186 VISKORES_CONT static void Fill(
const std::vector<viskores::cont::internal::Buffer>& buffers,
187 const ValueType& fillValue,
199 ComponentType source = fillValue[componentIndex];
200 buffers[componentIndex].Fill(&source, sourceSize, startByte, endByte, token);
205 const std::vector<viskores::cont::internal::Buffer>& buffers,
210 ReadPortalType portal(numValues);
214 VISKORES_ASSERT(buffers[0].GetNumberOfBytes() == buffers[componentIndex].GetNumberOfBytes());
215 portal.SetPortal(componentIndex,
216 viskores::internal::ArrayPortalBasicRead<ComponentType>(
217 reinterpret_cast<const ComponentType*
>(
218 buffers[componentIndex].ReadPointerDevice(device, token)),
225 const std::vector<viskores::cont::internal::Buffer>& buffers,
230 WritePortalType portal(numValues);
234 VISKORES_ASSERT(buffers[0].GetNumberOfBytes() == buffers[componentIndex].GetNumberOfBytes());
235 portal.SetPortal(componentIndex,
236 viskores::internal::ArrayPortalBasicWrite<ComponentType>(
237 reinterpret_cast<ComponentType*
>(
238 buffers[componentIndex].WritePointerDevice(device, token)),
264 template <
typename T>
278 ArrayHandleSOA(std::initializer_list<viskores::cont::internal::Buffer>&& componentBuffers)
294 ArrayHandleSOA(
const std::array<ComponentArrayType, NUM_COMPONENTS>& componentArrays)
299 this->
SetArray(componentIndex, componentArrays[componentIndex]);
320 this->
SetArray(componentIndex, componentArrays[componentIndex]);
339 for (
auto&& array : componentArrays)
341 this->
SetArray(componentIndex, array);
359 ArrayHandleSOA(std::initializer_list<std::vector<ComponentType>>&& componentVectors)
363 for (
auto&& vector : componentVectors)
389 template <
typename Allocator,
typename... RemainingVectors>
391 const std::vector<ComponentType, Allocator>& vector0,
392 RemainingVectors&&... componentVectors)
396 .GetBuffers()[0]... })
420 template <
typename... RemainingVectors>
422 std::vector<ComponentType>&& vector0,
423 RemainingVectors&&... componentVectors)
427 .GetBuffers()[0]... })
449 for (
auto&& vectorIter = componentArrays.begin(); vectorIter != componentArrays.end();
471 template <
typename... RemainingArrays>
475 const RemainingArrays&... componentArrays)
500 template <
typename... Remaining>
501 using VecSizeFromRemaining =
517 template <
typename ValueType>
519 std::initializer_list<
540 template <
typename ComponentType,
typename... RemainingArrays>
542 viskores::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingArrays...>::value>>
546 const RemainingArrays&... componentArrays)
548 return { componentArray0, componentArrays... };
564 template <
typename ValueType>
588 template <
typename ComponentType,
typename... RemainingVectors>
590 viskores::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>
592 const std::vector<ComponentType>& vector0,
593 RemainingVectors&&... componentVectors)
620 template <
typename ComponentType,
typename... RemainingVectors>
622 viskores::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>
624 std::vector<ComponentType>&& vector0,
625 RemainingVectors&&... componentVectors)
629 viskores::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>(
648 template <
typename ComponentType,
typename... RemainingVectors>
650 viskores::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingVectors...>::value>>
652 RemainingVectors&&... componentVectors)
656 std::forward<RemainingVectors>(componentVectors))... };
670 template <
typename ValueType>
693 template <
typename ComponentType,
typename... RemainingArrays>
695 viskores::Vec<ComponentType, internal::VecSizeFromRemaining<RemainingArrays...>::value>>
698 const ComponentType* array0,
699 const RemainingArrays*... componentArrays)
703 length, copy, array0, componentArrays...);
714 template <
typename T>
718 -> decltype(ArrayExtractComponentImpl<viskores::cont::StorageTagBasic>{}(
727 return ArrayExtractComponentImpl<viskores::cont::StorageTagBasic>{}(
728 array.GetArray(componentIndex / NUM_SUB_COMPONENTS),
729 componentIndex % NUM_SUB_COMPONENTS,
750 template <
typename ValueType>
751 struct SerializableTypeString<
viskores::cont::ArrayHandleSOA<ValueType>>
760 template <
typename ValueType>
761 struct SerializableTypeString<
viskores::cont::ArrayHandle<ValueType, viskores::cont::StorageTagSOA>>
762 : SerializableTypeString<viskores::cont::ArrayHandleSOA<ValueType>>
771 template <
typename ValueType>
772 struct Serialization<
viskores::cont::ArrayHandleSOA<ValueType>>
778 static VISKORES_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
783 viskoresdiy::save(bb, obj.GetBuffers()[componentIndex]);
789 std::vector<viskores::cont::internal::Buffer> buffers(NUM_COMPONENTS);
790 for (std::size_t componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex)
794 obj = BaseType(buffers);
798 template <
typename ValueType>
799 struct Serialization<
viskores::cont::ArrayHandle<ValueType, viskores::cont::StorageTagSOA>>
800 : Serialization<viskores::cont::ArrayHandleSOA<ValueType>>
810 #ifndef viskores_cont_ArrayHandleSOA_cxx
819 #define VISKORES_ARRAYHANDLE_SOA_EXPORT(Type) \
820 extern template class VISKORES_CONT_TEMPLATE_EXPORT \
821 ArrayHandle<viskores::Vec<Type, 2>, StorageTagSOA>; \
822 extern template class VISKORES_CONT_TEMPLATE_EXPORT \
823 ArrayHandle<viskores::Vec<Type, 3>, StorageTagSOA>; \
824 extern template class VISKORES_CONT_TEMPLATE_EXPORT \
825 ArrayHandle<viskores::Vec<Type, 4>, StorageTagSOA>;
827 VISKORES_ARRAYHANDLE_SOA_EXPORT(
char)
839 #undef VISKORES_ARRAYHANDLE_SOA_EXPORT
845 #endif // !viskores_cont_ArrayHandleSOA_cxx
847 #endif //viskores_cont_ArrayHandleSOA_h