Move from tao::tuple to vtkm::Tuple

The new version of vtkm::Tuple should be faster. It also gives us more
control over the implementation and can provide some VTK-m specific
things.
This commit is contained in:
Kenneth Moreland 2020-02-25 15:11:10 -07:00
parent dca8144345
commit 6f0edbec24
4 changed files with 299 additions and 597 deletions

@ -14,12 +14,13 @@
#include <vtkm/Deprecated.h> #include <vtkm/Deprecated.h>
#include <vtkm/StaticAssert.h> #include <vtkm/StaticAssert.h>
#include <vtkm/Tuple.h>
#include <vtkm/VecTraits.h> #include <vtkm/VecTraits.h>
#include <vtkmtaotuple/include/Tuple.h>
#include <vtkm/internal/brigand.hpp> #include <vtkm/internal/brigand.hpp>
#include <vtkmstd/integer_sequence.h>
#include <type_traits> #include <type_traits>
namespace vtkm namespace vtkm
@ -61,278 +62,162 @@ struct AllAreArrayHandles
}; };
// GetValueType: --------------------------------------------------------------- // GetValueType: ---------------------------------------------------------------
// Determines the output ValueType of the objects in TupleType, a vtkmstd::tuple // Determines the output `ValueType` of the set of `ArrayHandle` objects. For example, if the input
// which can contain ArrayHandles, ArrayPortals...anything with a ValueType // set contains 3 types with `vtkm::Float32` ValueTypes, then the ValueType defined here will be
// defined, really. For example, if the input TupleType contains 3 types with // `vtkm::Vec<Float32, 3>`. This also validates that all members have the same `ValueType`.
// Float32 ValueTypes, then the ValueType defined here will be Vec<Float32, 3>.
// This also validates that all members have the same ValueType.
template <typename TupleType>
struct GetValueTypeImpl;
template <typename Head, typename... Tail> template <typename ExpectedValueType, typename ArrayType>
struct GetValueTypeImpl<vtkmstd::tuple<Head, Tail...>> constexpr bool CheckValueType()
{ {
using Type = typename Head::ValueType; VTKM_STATIC_ASSERT_MSG((std::is_same<ExpectedValueType, typename ArrayType::ValueType>::value),
private:
using Next = GetValueTypeImpl<vtkmstd::tuple<Tail...>>;
VTKM_STATIC_ASSERT_MSG(VTKM_PASS_COMMAS(std::is_same<Type, typename Next::Type>::value),
"ArrayHandleCompositeVector must be built from " "ArrayHandleCompositeVector must be built from "
"ArrayHandles with the same ValueTypes."); "ArrayHandles with the same ValueTypes.");
}; return std::is_same<ExpectedValueType, typename ArrayType::ValueType>::value;
}
template <typename Head> template <typename ArrayType0, typename... ArrayTypes>
struct GetValueTypeImpl<vtkmstd::tuple<Head>>
{
using Type = typename Head::ValueType;
};
template <typename TupleType>
struct GetValueType struct GetValueType
{ {
VTKM_STATIC_ASSERT(vtkmstd::tuple_size<TupleType>::value >= 1); static constexpr vtkm::IdComponent COUNT =
static_cast<vtkm::IdComponent>(sizeof...(ArrayTypes)) + 1;
static const vtkm::IdComponent COUNT = using ComponentType = typename ArrayType0::ValueType;
static_cast<vtkm::IdComponent>(vtkmstd::tuple_size<TupleType>::value); static constexpr std::array<bool, sizeof...(ArrayTypes) + 1> ValueCheck{
using ComponentType = typename GetValueTypeImpl<TupleType>::Type; { true, CheckValueType<ComponentType, ArrayTypes>()... }
};
using ValueType = vtkm::Vec<ComponentType, COUNT>; using ValueType = vtkm::Vec<ComponentType, COUNT>;
}; };
// TupleTypePrepend: ----------------------------------------------------------- // Special case for only one component
// Prepend a type to a tuple, defining the new tuple in Type. template <typename ArrayType>
template <typename PrependType, typename TupleType> struct GetValueType<ArrayType>
struct TupleTypePrepend;
template <typename PrependType, typename... TupleTypes>
struct TupleTypePrepend<PrependType, vtkmstd::tuple<TupleTypes...>>
{ {
using Type = vtkmstd::tuple<PrependType, TupleTypes...>; static constexpr vtkm::IdComponent COUNT = 1;
using ComponentType = typename ArrayType::ValueType;
using ValueType = typename ArrayType::ValueType;
}; };
// ArrayTupleForEach: ---------------------------------------------------------- // -----------------------------------------------------------------------------
// Collection of methods that iterate through the arrays in ArrayTuple to // Functors to access Storage methods. This is used with vtkm::Tuple's
// implement the ArrayHandle API. // ForEach and Transform methods.
template <std::size_t Index, std::size_t Count, typename ArrayTuple>
struct ArrayTupleForEach struct WritePortal
{ {
using Next = ArrayTupleForEach<Index + 1, Count, ArrayTuple>; template <typename ArrayHandle>
typename ArrayHandle::WritePortalType operator()(const ArrayHandle& array) const
template <typename PortalTuple>
VTKM_CONT static void GetPortalTupleControl(ArrayTuple& arrays, PortalTuple& portals)
{ {
vtkmstd::get<Index>(portals) = vtkmstd::get<Index>(arrays).WritePortal(); return array.WritePortal();
Next::GetPortalTupleControl(arrays, portals);
}
template <typename PortalTuple>
VTKM_CONT static void GetPortalConstTupleControl(const ArrayTuple& arrays, PortalTuple& portals)
{
vtkmstd::get<Index>(portals) = vtkmstd::get<Index>(arrays).ReadPortal();
Next::GetPortalConstTupleControl(arrays, portals);
}
template <typename DeviceTag, typename PortalTuple>
VTKM_CONT static void PrepareForInput(const ArrayTuple& arrays,
PortalTuple& portals,
vtkm::cont::Token& token)
{
vtkmstd::get<Index>(portals) = vtkmstd::get<Index>(arrays).PrepareForInput(DeviceTag(), token);
Next::template PrepareForInput<DeviceTag>(arrays, portals, token);
}
template <typename DeviceTag, typename PortalTuple>
VTKM_CONT static void PrepareForInPlace(ArrayTuple& arrays,
PortalTuple& portals,
vtkm::cont::Token& token)
{
vtkmstd::get<Index>(portals) =
vtkmstd::get<Index>(arrays).PrepareForInPlace(DeviceTag(), token);
Next::template PrepareForInPlace<DeviceTag>(arrays, portals, token);
}
template <typename DeviceTag, typename PortalTuple>
VTKM_CONT static void PrepareForOutput(ArrayTuple& arrays,
PortalTuple& portals,
vtkm::Id numValues,
vtkm::cont::Token& token)
{
vtkmstd::get<Index>(portals) =
vtkmstd::get<Index>(arrays).PrepareForOutput(numValues, DeviceTag(), token);
Next::template PrepareForOutput<DeviceTag>(arrays, portals, numValues, token);
}
VTKM_CONT
static void Allocate(ArrayTuple& arrays, vtkm::Id numValues)
{
vtkmstd::get<Index>(arrays).Allocate(numValues);
Next::Allocate(arrays, numValues);
}
VTKM_CONT
static void Shrink(ArrayTuple& arrays, vtkm::Id numValues)
{
vtkmstd::get<Index>(arrays).Shrink(numValues);
Next::Shrink(arrays, numValues);
}
VTKM_CONT
static void ReleaseResources(ArrayTuple& arrays)
{
vtkmstd::get<Index>(arrays).ReleaseResources();
Next::ReleaseResources(arrays);
} }
}; };
template <std::size_t Index, typename ArrayTuple> struct ReadPortal
struct ArrayTupleForEach<Index, Index, ArrayTuple>
{ {
template <typename PortalTuple> template <typename ArrayHandle>
VTKM_CONT static void GetPortalTupleControl(ArrayTuple&, PortalTuple&) typename ArrayHandle::ReadPortalType operator()(const ArrayHandle& array) const
{ {
return array.ReadPortal();
} }
template <typename PortalTuple>
VTKM_CONT static void GetPortalConstTupleControl(const ArrayTuple&, PortalTuple&)
{
}
template <typename DeviceTag, typename PortalTuple>
VTKM_CONT static void PrepareForInput(const ArrayTuple&, PortalTuple&, vtkm::cont::Token&)
{
}
template <typename DeviceTag, typename PortalTuple>
VTKM_CONT static void PrepareForInPlace(ArrayTuple&, PortalTuple&, vtkm::cont::Token&)
{
}
template <typename DeviceTag, typename PortalTuple>
VTKM_CONT static void PrepareForOutput(ArrayTuple&, PortalTuple&, vtkm::Id, vtkm::cont::Token&)
{
}
VTKM_CONT static void Allocate(ArrayTuple&, vtkm::Id) {}
VTKM_CONT static void Shrink(ArrayTuple&, vtkm::Id) {}
VTKM_CONT static void ReleaseResources(ArrayTuple&) {}
}; };
// PortalTupleTraits: ---------------------------------------------------------- struct Allocate
// Determine types of ArrayHandleCompositeVector portals and construct the
// portals from the input arrays.
template <typename ArrayTuple>
struct PortalTupleTypeGeneratorImpl;
template <typename Head, typename... Tail>
struct PortalTupleTypeGeneratorImpl<vtkmstd::tuple<Head, Tail...>>
{ {
using Next = PortalTupleTypeGeneratorImpl<vtkmstd::tuple<Tail...>>; vtkm::Id NumValues;
using PortalControlTuple = typename TupleTypePrepend<typename Head::WritePortalType, VTKM_CONT Allocate(vtkm::Id numValues)
typename Next::PortalControlTuple>::Type; : NumValues(numValues)
using PortalConstControlTuple =
typename TupleTypePrepend<typename Head::ReadPortalType,
typename Next::PortalConstControlTuple>::Type;
template <typename DeviceTag>
struct ExecutionTypes
{ {
using PortalTuple = typename TupleTypePrepend< }
typename Head::template ExecutionTypes<DeviceTag>::Portal,
typename Next::template ExecutionTypes<DeviceTag>::PortalTuple>::Type; template <typename Array>
using PortalConstTuple = typename TupleTypePrepend< VTKM_CONT void operator()(Array& array)
typename Head::template ExecutionTypes<DeviceTag>::PortalConst, {
typename Next::template ExecutionTypes<DeviceTag>::PortalConstTuple>::Type; array.Allocate(this->NumValues);
}; }
}; };
template <typename Head> struct Shrink
struct PortalTupleTypeGeneratorImpl<vtkmstd::tuple<Head>>
{ {
using PortalControlTuple = vtkmstd::tuple<typename Head::WritePortalType>; vtkm::Id NumValues;
using PortalConstControlTuple = vtkmstd::tuple<typename Head::ReadPortalType>; VTKM_CONT Shrink(vtkm::Id numValues)
: NumValues(numValues)
template <typename DeviceTag>
struct ExecutionTypes
{ {
using PortalTuple = vtkmstd::tuple<typename Head::template ExecutionTypes<DeviceTag>::Portal>; }
using PortalConstTuple =
vtkmstd::tuple<typename Head::template ExecutionTypes<DeviceTag>::PortalConst>; template <typename Array>
}; VTKM_CONT void operator()(Array& array)
{
array.Shrink(this->NumValues);
}
}; };
template <typename ArrayTuple> struct ReleaseResources
struct PortalTupleTraits
{ {
private: template <typename Array>
using TypeGenerator = PortalTupleTypeGeneratorImpl<ArrayTuple>; VTKM_CONT void operator()(Array& array)
using ForEachArray = ArrayTupleForEach<0, vtkmstd::tuple_size<ArrayTuple>::value, ArrayTuple>;
public:
using PortalTuple = typename TypeGenerator::PortalControlTuple;
using PortalConstTuple = typename TypeGenerator::PortalConstControlTuple;
VTKM_STATIC_ASSERT(vtkmstd::tuple_size<ArrayTuple>::value ==
vtkmstd::tuple_size<PortalTuple>::value);
VTKM_STATIC_ASSERT(vtkmstd::tuple_size<ArrayTuple>::value ==
vtkmstd::tuple_size<PortalConstTuple>::value);
template <typename DeviceTag>
struct ExecutionTypes
{ {
using PortalTuple = typename TypeGenerator::template ExecutionTypes<DeviceTag>::PortalTuple; array.ReleaseResources();
using PortalConstTuple = }
typename TypeGenerator::template ExecutionTypes<DeviceTag>::PortalConstTuple; };
VTKM_STATIC_ASSERT(vtkmstd::tuple_size<ArrayTuple>::value == // -----------------------------------------------------------------------------
vtkmstd::tuple_size<PortalTuple>::value); // Functors to access ArrayTransfer methods. This is used with vtkm::Tuple's
VTKM_STATIC_ASSERT(vtkmstd::tuple_size<ArrayTuple>::value == // ForEach and Transform methods.
vtkmstd::tuple_size<PortalConstTuple>::value);
};
VTKM_CONT template <typename Device>
static const PortalTuple GetPortalTupleControl(ArrayTuple& arrays) struct PrepareForInput
{
vtkm::cont::Token& Token;
VTKM_CONT PrepareForInput(vtkm::cont::Token& token)
: Token(token)
{ {
PortalTuple portals;
ForEachArray::GetPortalTupleControl(arrays, portals);
return portals;
} }
VTKM_CONT template <typename Array>
static const PortalConstTuple GetPortalConstTupleControl(const ArrayTuple& arrays) VTKM_CONT typename Array::template ExecutionTypes<Device>::PortalConst operator()(
const Array& array)
{
return array.PrepareForInput(Device{}, this->Token);
}
};
template <typename Device>
struct PrepareForInPlace
{
vtkm::cont::Token& Token;
VTKM_CONT PrepareForInPlace(vtkm::cont::Token& token)
: Token(token)
{ {
PortalConstTuple portals;
ForEachArray::GetPortalConstTupleControl(arrays, portals);
return portals;
} }
template <typename DeviceTag> template <typename Array>
VTKM_CONT static const typename ExecutionTypes<DeviceTag>::PortalConstTuple PrepareForInput( VTKM_CONT typename Array::template ExecutionTypes<Device>::Portal operator()(Array& array)
const ArrayTuple& arrays, {
vtkm::cont::Token& token) return array.PrepareForInPlace(Device{}, this->Token);
}
};
template <typename Device>
struct PrepareForOutput
{
vtkm::Id NumValues;
vtkm::cont::Token& Token;
VTKM_CONT PrepareForOutput(vtkm::Id numValues, vtkm::cont::Token& token)
: NumValues(numValues)
, Token(token)
{ {
typename ExecutionTypes<DeviceTag>::PortalConstTuple portals;
ForEachArray::template PrepareForInput<DeviceTag>(arrays, portals, token);
return portals;
} }
template <typename DeviceTag> template <typename Array>
VTKM_CONT static const typename ExecutionTypes<DeviceTag>::PortalTuple PrepareForInPlace( VTKM_CONT typename Array::template ExecutionTypes<Device>::Portal operator()(Array& array)
ArrayTuple& arrays,
vtkm::cont::Token& token)
{ {
typename ExecutionTypes<DeviceTag>::PortalTuple portals; return array.PrepareForOutput(this->NumValues, Device{}, this->Token);
ForEachArray::template PrepareForInPlace<DeviceTag>(arrays, portals, token);
return portals;
} }
};
template <typename DeviceTag> struct ReleaseResourcesExecution
VTKM_CONT static const typename ExecutionTypes<DeviceTag>::PortalTuple {
PrepareForOutput(ArrayTuple& arrays, vtkm::Id numValues, vtkm::cont::Token& token) template <typename Array>
VTKM_CONT void operator()(Array& array)
{ {
typename ExecutionTypes<DeviceTag>::PortalTuple portals; array.ReleaseResourcesExecution();
ForEachArray::template PrepareForOutput<DeviceTag>(arrays, portals, numValues, token);
return portals;
} }
}; };
@ -347,7 +232,7 @@ struct ArraySizeValidatorImpl
VTKM_CONT VTKM_CONT
static bool Exec(const TupleType& tuple, vtkm::Id numVals) static bool Exec(const TupleType& tuple, vtkm::Id numVals)
{ {
return vtkmstd::get<Index>(tuple).GetNumberOfValues() == numVals && Next::Exec(tuple, numVals); return vtkm::Get<Index>(tuple).GetNumberOfValues() == numVals && Next::Exec(tuple, numVals);
} }
}; };
@ -364,113 +249,96 @@ struct ArraySizeValidator
VTKM_CONT VTKM_CONT
static bool Exec(const TupleType& tuple, vtkm::Id numVals) static bool Exec(const TupleType& tuple, vtkm::Id numVals)
{ {
return ArraySizeValidatorImpl<0, vtkmstd::tuple_size<TupleType>::value, TupleType>::Exec( return ArraySizeValidatorImpl<0, vtkm::TupleSize<TupleType>::value, TupleType>::Exec(tuple,
tuple, numVals); numVals);
} }
}; };
template <typename PortalList> template <typename... PortalList>
using AllPortalsAreWritable = using AllPortalsAreWritable =
typename brigand::all<PortalList, typename brigand::all<brigand::list<PortalList...>,
brigand::bind<vtkm::internal::PortalSupportsSets, brigand::_1>>::type; brigand::bind<vtkm::internal::PortalSupportsSets, brigand::_1>>::type;
// GetFromPortals: -------------------------------------------------------------
// Given a set of array portals as arguments, returns a Vec comprising the values
// at the provided index.
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename... Portals>
VTKM_EXEC_CONT typename GetValueType<Portals...>::ValueType GetFromPortals(
vtkm::Id index,
const Portals&... portals)
{
return { portals.Get(index)... };
}
// SetToPortals: ---------------------------------------------------------------
// Given a Vec-like object, and index, and a set of array portals, sets each of
// the portals to the respective component of the Vec.
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ValueType, vtkm::IdComponent... I, typename... Portals>
VTKM_EXEC_CONT void SetToPortalsImpl(vtkm::Id index,
const ValueType& value,
vtkmstd::integer_sequence<vtkm::IdComponent, I...>,
const Portals&... portals)
{
using Traits = vtkm::VecTraits<ValueType>;
(void)std::initializer_list<bool>{ (portals.Set(index, Traits::GetComponent(value, I)),
false)... };
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ValueType, typename... Portals>
VTKM_EXEC_CONT void SetToPortals(vtkm::Id index, const ValueType& value, const Portals&... portals)
{
SetToPortalsImpl(
index,
value,
vtkmstd::make_integer_sequence<vtkm::IdComponent, vtkm::IdComponent(sizeof...(Portals))>{},
portals...);
}
} // end namespace compvec } // end namespace compvec
template <typename PortalTuple> template <typename... PortalTypes>
class VTKM_ALWAYS_EXPORT ArrayPortalCompositeVector class VTKM_ALWAYS_EXPORT ArrayPortalCompositeVector
{ {
using Writable = compvec::AllPortalsAreWritable<PortalTuple>; using Writable = compvec::AllPortalsAreWritable<PortalTypes...>;
using TupleType = vtkm::Tuple<PortalTypes...>;
TupleType Portals;
public: public:
using ValueType = typename compvec::GetValueType<PortalTuple>::ValueType; using ValueType = typename compvec::GetValueType<PortalTypes...>::ValueType;
private:
using Traits = vtkm::VecTraits<ValueType>;
// Get: ----------------------------------------------------------------------
template <vtkm::IdComponent VectorIndex, typename PortalTupleT>
struct GetImpl;
template <vtkm::IdComponent VectorIndex, typename Head, typename... Tail>
struct GetImpl<VectorIndex, vtkmstd::tuple<Head, Tail...>>
{
using Next = GetImpl<VectorIndex + 1, vtkmstd::tuple<Tail...>>;
VTKM_EXEC_CONT
static void Exec(const PortalTuple& portals, ValueType& vec, vtkm::Id arrayIndex)
{
Traits::SetComponent(vec, VectorIndex, vtkmstd::get<VectorIndex>(portals).Get(arrayIndex));
Next::Exec(portals, vec, arrayIndex);
}
};
template <vtkm::IdComponent VectorIndex, typename Head>
struct GetImpl<VectorIndex, vtkmstd::tuple<Head>>
{
VTKM_EXEC_CONT
static void Exec(const PortalTuple& portals, ValueType& vec, vtkm::Id arrayIndex)
{
Traits::SetComponent(vec, VectorIndex, vtkmstd::get<VectorIndex>(portals).Get(arrayIndex));
}
};
// Set: ----------------------------------------------------------------------
template <vtkm::IdComponent VectorIndex, typename PortalTupleT>
struct SetImpl;
template <vtkm::IdComponent VectorIndex, typename Head, typename... Tail>
struct SetImpl<VectorIndex, vtkmstd::tuple<Head, Tail...>>
{
using Next = SetImpl<VectorIndex + 1, vtkmstd::tuple<Tail...>>;
VTKM_EXEC_CONT
static void Exec(const PortalTuple& portals, const ValueType& vec, vtkm::Id arrayIndex)
{
vtkmstd::get<VectorIndex>(portals).Set(arrayIndex, Traits::GetComponent(vec, VectorIndex));
Next::Exec(portals, vec, arrayIndex);
}
};
template <vtkm::IdComponent VectorIndex, typename Head>
struct SetImpl<VectorIndex, vtkmstd::tuple<Head>>
{
VTKM_EXEC_CONT
static void Exec(const PortalTuple& portals, const ValueType& vec, vtkm::Id arrayIndex)
{
vtkmstd::get<VectorIndex>(portals).Set(arrayIndex, Traits::GetComponent(vec, VectorIndex));
}
};
public:
VTKM_EXEC_CONT VTKM_EXEC_CONT
ArrayPortalCompositeVector() {} ArrayPortalCompositeVector() {}
VTKM_CONT VTKM_CONT
ArrayPortalCompositeVector(const PortalTuple& portals) ArrayPortalCompositeVector(const PortalTypes&... portals)
: Portals(portals...)
{
}
VTKM_CONT
ArrayPortalCompositeVector(const TupleType& portals)
: Portals(portals) : Portals(portals)
{ {
} }
VTKM_EXEC_CONT VTKM_EXEC_CONT
vtkm::Id GetNumberOfValues() const { return vtkmstd::get<0>(this->Portals).GetNumberOfValues(); } vtkm::Id GetNumberOfValues() const { return vtkm::Get<0>(this->Portals).GetNumberOfValues(); }
VTKM_EXEC_CONT VTKM_EXEC_CONT
ValueType Get(vtkm::Id index) const ValueType Get(vtkm::Id index) const
{ {
ValueType result; return this->Portals.Apply(compvec::GetFromPortals<PortalTypes...>, index);
GetImpl<0, PortalTuple>::Exec(this->Portals, result, index);
return result;
} }
template <typename Writable_ = Writable, template <typename Writable_ = Writable,
typename = typename std::enable_if<Writable_::value>::type> typename = typename std::enable_if<Writable_::value>::type>
VTKM_EXEC_CONT void Set(vtkm::Id index, const ValueType& value) const VTKM_EXEC_CONT void Set(vtkm::Id index, const ValueType& value) const
{ {
SetImpl<0, PortalTuple>::Exec(this->Portals, value, index); this->Portals.Apply(compvec::SetToPortals<ValueType, PortalTypes...>, index, value);
} }
private:
PortalTuple Portals;
}; };
} // namespace internal } // namespace internal
@ -483,12 +351,6 @@ struct VTKM_ALWAYS_EXPORT StorageTagCompositeVec
namespace internal namespace internal
{ {
template <typename ArrayTuple>
struct VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6, "Use StorageTagCompositeVec instead.")
StorageTagCompositeVector
{
};
template <typename... ArrayTs> template <typename... ArrayTs>
struct CompositeVectorTraits struct CompositeVectorTraits
{ {
@ -499,38 +361,27 @@ struct CompositeVectorTraits
"Template parameters for ArrayHandleCompositeVector " "Template parameters for ArrayHandleCompositeVector "
"must be a list of ArrayHandle types."); "must be a list of ArrayHandle types.");
using ValueType = typename compvec::GetValueType<vtkmstd::tuple<ArrayTs...>>::ValueType; using ValueType = typename compvec::GetValueType<ArrayTs...>::ValueType;
using StorageTag = vtkm::cont::StorageTagCompositeVec<typename ArrayTs::StorageTag...>; using StorageTag = vtkm::cont::StorageTagCompositeVec<typename ArrayTs::StorageTag...>;
using StorageType = Storage<ValueType, StorageTag>; using StorageType = Storage<ValueType, StorageTag>;
using Superclass = ArrayHandle<ValueType, StorageTag>; using Superclass = ArrayHandle<ValueType, StorageTag>;
}; };
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <typename... Arrays>
class Storage<typename compvec::GetValueType<vtkmstd::tuple<Arrays...>>::ValueType,
StorageTagCompositeVector<vtkmstd::tuple<Arrays...>>>
: CompositeVectorTraits<Arrays...>::StorageType
{
using Superclass = typename CompositeVectorTraits<Arrays...>::StorageType;
using Superclass::Superclass;
};
VTKM_DEPRECATED_SUPPRESS_END
template <typename T, typename... StorageTags> template <typename T, typename... StorageTags>
class Storage<vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(StorageTags))>, class Storage<vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(StorageTags))>,
vtkm::cont::StorageTagCompositeVec<StorageTags...>> vtkm::cont::StorageTagCompositeVec<StorageTags...>>
{ {
using ArrayTuple = vtkmstd::tuple<vtkm::cont::ArrayHandle<T, StorageTags>...>; using ArrayTuple = vtkm::Tuple<vtkm::cont::ArrayHandle<T, StorageTags>...>;
using ForEachArray =
compvec::ArrayTupleForEach<0, vtkmstd::tuple_size<ArrayTuple>::value, ArrayTuple>; ArrayTuple Arrays;
using PortalTypes = compvec::PortalTupleTraits<ArrayTuple>; bool Valid;
using PortalTupleType = typename PortalTypes::PortalTuple;
using PortalConstTupleType = typename PortalTypes::PortalConstTuple;
public: public:
using ValueType = typename compvec::GetValueType<ArrayTuple>::ValueType; using ValueType = vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(StorageTags))>;
using PortalType = ArrayPortalCompositeVector<PortalTupleType>; using PortalType = ArrayPortalCompositeVector<
using PortalConstType = ArrayPortalCompositeVector<PortalConstTupleType>; typename vtkm::cont::ArrayHandle<T, StorageTags>::WritePortalType...>;
using PortalConstType =
ArrayPortalCompositeVector<typename vtkm::cont::ArrayHandle<T, StorageTags>::ReadPortalType...>;
VTKM_CONT VTKM_CONT
Storage() Storage()
@ -538,18 +389,6 @@ public:
{ {
} }
VTKM_CONT
Storage(const ArrayTuple& arrays)
: Arrays(arrays)
, Valid(true)
{
using SizeValidator = compvec::ArraySizeValidator<ArrayTuple>;
if (!SizeValidator::Exec(this->Arrays, this->GetNumberOfValues()))
{
throw ErrorBadValue("All arrays must have the same number of values.");
}
}
template <typename... ArrayTypes> template <typename... ArrayTypes>
VTKM_CONT Storage(const ArrayTypes&... arrays) VTKM_CONT Storage(const ArrayTypes&... arrays)
: Arrays(arrays...) : Arrays(arrays...)
@ -566,42 +405,44 @@ public:
PortalType GetPortal() PortalType GetPortal()
{ {
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
return PortalType(PortalTypes::GetPortalTupleControl(this->Arrays)); return this->Arrays.Transform(compvec::WritePortal{});
} }
void TypeCheck(int) const;
VTKM_CONT VTKM_CONT
PortalConstType GetPortalConst() const PortalConstType GetPortalConst() const
{ {
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
return PortalConstType(PortalTypes::GetPortalConstTupleControl(this->Arrays)); this->Arrays.Transform(compvec::ReadPortal{});
return this->Arrays.Transform(compvec::ReadPortal{});
} }
VTKM_CONT VTKM_CONT
vtkm::Id GetNumberOfValues() const vtkm::Id GetNumberOfValues() const
{ {
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
return vtkmstd::get<0>(this->Arrays).GetNumberOfValues(); return vtkm::Get<0>(this->Arrays).GetNumberOfValues();
} }
VTKM_CONT VTKM_CONT
void Allocate(vtkm::Id numValues) void Allocate(vtkm::Id numValues)
{ {
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
ForEachArray::Allocate(this->Arrays, numValues); this->Arrays.ForEach(compvec::Allocate{ numValues });
} }
VTKM_CONT VTKM_CONT
void Shrink(vtkm::Id numValues) void Shrink(vtkm::Id numValues)
{ {
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
ForEachArray::Shrink(this->Arrays, numValues); this->Arrays.ForEach(compvec::Shrink{ numValues });
} }
VTKM_CONT VTKM_CONT
void ReleaseResources() void ReleaseResources()
{ {
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
ForEachArray::ReleaseResources(this->Arrays); this->Arrays.ForEach(compvec::ReleaseResources{});
} }
VTKM_CONT VTKM_CONT
@ -617,28 +458,25 @@ public:
VTKM_ASSERT(this->Valid); VTKM_ASSERT(this->Valid);
return this->Arrays; return this->Arrays;
} }
private:
ArrayTuple Arrays;
bool Valid;
}; };
VTKM_DEPRECATED_SUPPRESS_BEGIN // Special case for single component. Just defer to the original storage.
template <typename... Arrays, typename DeviceTag> template <typename T, typename StorageTag>
struct ArrayTransfer<typename compvec::GetValueType<vtkmstd::tuple<Arrays...>>::ValueType, class Storage<T, vtkm::cont::StorageTagCompositeVec<StorageTag>> : public Storage<T, StorageTag>
StorageTagCompositeVector<vtkmstd::tuple<Arrays...>>,
DeviceTag>
: ArrayTransfer<typename compvec::GetValueType<vtkmstd::tuple<Arrays...>>::ValueType,
typename CompositeVectorTraits<Arrays...>::StorageType,
DeviceTag>
{ {
using Superclass = using ArrayType = vtkm::cont::ArrayHandle<T, StorageTag>;
ArrayTransfer<typename compvec::GetValueType<vtkmstd::tuple<Arrays...>>::ValueType, using TupleType = vtkm::Tuple<ArrayType>;
typename CompositeVectorTraits<Arrays...>::StorageType,
DeviceTag>; public:
using Superclass::Superclass; Storage() = default;
Storage(const ArrayType& array)
: Storage<T, StorageTag>(array.GetStorage())
{
}
VTKM_CONT
const TupleType GetArrayTuple() const { return TupleType(ArrayType(this->GetStoragea())); }
}; };
VTKM_DEPRECATED_SUPPRESS_END
template <typename T, typename... StorageTags, typename DeviceTag> template <typename T, typename... StorageTags, typename DeviceTag>
class ArrayTransfer<vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(StorageTags))>, class ArrayTransfer<vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(StorageTags))>,
@ -647,26 +485,27 @@ class ArrayTransfer<vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(Storag
{ {
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceTag); VTKM_IS_DEVICE_ADAPTER_TAG(DeviceTag);
using ArrayTuple = vtkmstd::tuple<vtkm::cont::ArrayHandle<T, StorageTags>...>; using ArrayTuple = vtkm::Tuple<vtkm::cont::ArrayHandle<T, StorageTags>...>;
public: public:
using ValueType = typename compvec::GetValueType<ArrayTuple>::ValueType; using ValueType = vtkm::Vec<T, static_cast<vtkm::IdComponent>(sizeof...(StorageTags))>;
private: private:
using ForEachArray =
compvec::ArrayTupleForEach<0, vtkmstd::tuple_size<ArrayTuple>::value, ArrayTuple>;
using StorageTag = vtkm::cont::StorageTagCompositeVec<StorageTags...>; using StorageTag = vtkm::cont::StorageTagCompositeVec<StorageTags...>;
using StorageType = internal::Storage<ValueType, StorageTag>; using StorageType = internal::Storage<ValueType, StorageTag>;
using ControlTraits = compvec::PortalTupleTraits<ArrayTuple>;
using ExecutionTraits = typename ControlTraits::template ExecutionTypes<DeviceTag>; StorageType* Storage;
public: public:
using PortalControl = ArrayPortalCompositeVector<typename ControlTraits::PortalTuple>; using PortalControl = typename StorageType::PortalType;
using PortalConstControl = ArrayPortalCompositeVector<typename ControlTraits::PortalConstTuple>; using PortalConstControl = typename StorageType::PortalConstType;
using PortalExecution = ArrayPortalCompositeVector<typename ExecutionTraits::PortalTuple>; using PortalExecution = ArrayPortalCompositeVector<
typename vtkm::cont::ArrayHandle<T,
StorageTags>::template ExecutionTypes<DeviceTag>::Portal...>;
using PortalConstExecution = using PortalConstExecution =
ArrayPortalCompositeVector<typename ExecutionTraits::PortalConstTuple>; ArrayPortalCompositeVector<typename vtkm::cont::ArrayHandle<T, StorageTags>::
template ExecutionTypes<DeviceTag>::PortalConst...>;
VTKM_CONT VTKM_CONT
ArrayTransfer(StorageType* storage) ArrayTransfer(StorageType* storage)
@ -680,22 +519,20 @@ public:
VTKM_CONT VTKM_CONT
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData), vtkm::cont::Token& token) const PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData), vtkm::cont::Token& token) const
{ {
return PortalConstExecution( return this->GetArrayTuple().Transform(compvec::PrepareForInput<DeviceTag>{ token });
ControlTraits::template PrepareForInput<DeviceTag>(this->GetArrayTuple(), token));
} }
VTKM_CONT VTKM_CONT
PortalExecution PrepareForInPlace(bool vtkmNotUsed(updateData), vtkm::cont::Token& token) PortalExecution PrepareForInPlace(bool vtkmNotUsed(updateData), vtkm::cont::Token& token)
{ {
return PortalExecution( return this->GetArrayTuple().Transform(compvec::PrepareForInPlace<DeviceTag>{ token });
ControlTraits::template PrepareForInPlace<DeviceTag>(this->GetArrayTuple(), token));
} }
VTKM_CONT VTKM_CONT
PortalExecution PrepareForOutput(vtkm::Id numValues, vtkm::cont::Token& token) PortalExecution PrepareForOutput(vtkm::Id numValues, vtkm::cont::Token& token)
{ {
return PortalExecution( return this->GetArrayTuple().Transform(
ControlTraits::template PrepareForOutput<DeviceTag>(this->GetArrayTuple(), numValues, token)); compvec::PrepareForOutput<DeviceTag>{ numValues, token });
} }
VTKM_CONT VTKM_CONT
@ -707,17 +544,14 @@ public:
} }
VTKM_CONT VTKM_CONT
void Shrink(vtkm::Id numValues) { ForEachArray::Shrink(this->GetArrayTuple(), numValues); } void Shrink(vtkm::Id numValues) { this->GetArrayTuple().ForEach(compvec::Shrink{ numValues }); }
VTKM_CONT VTKM_CONT
void ReleaseResources() { ForEachArray::ReleaseResources(this->GetArrayTuple()); } void ReleaseResources() { this->GetArrayTuple().ForEach(compvec::ReleaseResourcesExecution{}); }
VTKM_CONT VTKM_CONT
const ArrayTuple& GetArrayTuple() const { return this->Storage->GetArrayTuple(); } const ArrayTuple& GetArrayTuple() const { return this->Storage->GetArrayTuple(); }
ArrayTuple& GetArrayTuple() { return this->Storage->GetArrayTuple(); } ArrayTuple& GetArrayTuple() { return this->Storage->GetArrayTuple(); }
private:
StorageType* Storage;
}; };
} // namespace internal } // namespace internal
@ -742,7 +576,7 @@ class ArrayHandleCompositeVector
{ {
private: private:
using Traits = internal::CompositeVectorTraits<ArrayTs...>; using Traits = internal::CompositeVectorTraits<ArrayTs...>;
using TupleType = vtkmstd::tuple<ArrayTs...>; using TupleType = vtkm::Tuple<ArrayTs...>;
using StorageType = typename Traits::StorageType; using StorageType = typename Traits::StorageType;
public: public:
@ -798,59 +632,12 @@ struct SerializableTypeString<
vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<T, STs>...>> vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<T, STs>...>>
{ {
}; };
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <typename... AHs>
struct SerializableTypeString<vtkm::cont::ArrayHandle<
typename vtkm::cont::internal::compvec::GetValueType<vtkmstd::tuple<AHs...>>::ValueType,
vtkm::cont::internal::StorageTagCompositeVector<vtkmstd::tuple<AHs...>>>>
: SerializableTypeString<vtkm::cont::ArrayHandleCompositeVector<AHs...>>
{
};
VTKM_DEPRECATED_SUPPRESS_END
} }
} // vtkm::cont } // vtkm::cont
namespace mangled_diy_namespace namespace mangled_diy_namespace
{ {
namespace internal
{
template <typename Functor, typename TupleType, typename... Args>
inline void TupleForEachImpl(TupleType&& t,
std::integral_constant<size_t, 0>,
Functor&& f,
Args&&... args)
{
f(vtkmstd::get<0>(t), std::forward<Args>(args)...);
}
template <typename Functor, typename TupleType, size_t Index, typename... Args>
inline void TupleForEachImpl(TupleType&& t,
std::integral_constant<size_t, Index>,
Functor&& f,
Args&&... args)
{
TupleForEachImpl(std::forward<TupleType>(t),
std::integral_constant<size_t, Index - 1>{},
std::forward<Functor>(f),
std::forward<Args>(args)...);
f(vtkmstd::get<Index>(t), std::forward<Args>(args)...);
}
template <typename Functor, typename TupleType, typename... Args>
inline void TupleForEach(TupleType&& t, Functor&& f, Args&&... args)
{
constexpr auto size = vtkmstd::tuple_size<typename std::decay<TupleType>::type>::value;
TupleForEachImpl(std::forward<TupleType>(t),
std::integral_constant<size_t, size - 1>{},
std::forward<Functor>(f),
std::forward<Args>(args)...);
}
} // internal
template <typename... AHs> template <typename... AHs>
struct Serialization<vtkm::cont::ArrayHandleCompositeVector<AHs...>> struct Serialization<vtkm::cont::ArrayHandleCompositeVector<AHs...>>
{ {
@ -860,33 +647,47 @@ private:
struct SaveFunctor struct SaveFunctor
{ {
template <typename AH> BinaryBuffer& Buffer;
void operator()(const AH& ah, BinaryBuffer& bb) const SaveFunctor(BinaryBuffer& bb)
: Buffer(bb)
{ {
vtkmdiy::save(bb, ah); }
template <typename AH>
void operator()(const AH& ah) const
{
vtkmdiy::save(this->Buffer, ah);
} }
}; };
struct LoadFunctor struct LoadFunctor
{ {
template <typename AH> BinaryBuffer& Buffer;
void operator()(AH& ah, BinaryBuffer& bb) const LoadFunctor(BinaryBuffer& bb)
: Buffer(bb)
{ {
vtkmdiy::load(bb, ah); }
template <typename AH>
void operator()(AH& ah) const
{
vtkmdiy::load(this->Buffer, ah);
} }
}; };
static BaseType Create(const AHs&... arrays) { return Type(arrays...); }
public: public:
static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj) static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
{ {
internal::TupleForEach(obj.GetStorage().GetArrayTuple(), SaveFunctor{}, bb); obj.GetStorage().GetArrayTuple().ForEach(SaveFunctor{ bb });
} }
static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj) static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
{ {
vtkmstd::tuple<AHs...> arrayTuple; vtkm::Tuple<AHs...> tuple;
internal::TupleForEach(arrayTuple, LoadFunctor{}, bb); tuple.ForEach(LoadFunctor{ bb });
obj = BaseType(typename BaseType::StorageType(arrayTuple)); obj = tuple.Apply(Create);
} }
}; };
@ -897,16 +698,6 @@ struct Serialization<
: Serialization<vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<T, STs>...>> : Serialization<vtkm::cont::ArrayHandleCompositeVector<vtkm::cont::ArrayHandle<T, STs>...>>
{ {
}; };
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <typename... AHs>
struct Serialization<vtkm::cont::ArrayHandle<
typename vtkm::cont::internal::compvec::GetValueType<vtkmstd::tuple<AHs...>>::ValueType,
vtkm::cont::internal::StorageTagCompositeVector<vtkmstd::tuple<AHs...>>>>
: Serialization<vtkm::cont::ArrayHandleCompositeVector<AHs...>>
{
};
VTKM_DEPRECATED_SUPPRESS_END
} // diy } // diy
/// @endcond SERIALIZATION /// @endcond SERIALIZATION

@ -15,29 +15,18 @@
#include <vtkm/cont/Storage.h> #include <vtkm/cont/Storage.h>
#include <vtkm/StaticAssert.h> #include <vtkm/StaticAssert.h>
#include <vtkm/Tuple.h>
#include <vtkm/VecTraits.h> #include <vtkm/VecTraits.h>
#include <vtkm/internal/ArrayPortalHelpers.h> #include <vtkm/internal/ArrayPortalHelpers.h>
#include <vtkm/internal/brigand.hpp> #include <vtkm/internal/brigand.hpp>
#include <vtkmtaotuple/include/Tuple.h> #include <vtkmstd/integer_sequence.h>
#include <vtkmtaotuple/include/tao/seq/make_integer_sequence.hpp>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
// Some compilers like brigand's integer sequences.
// Some compilers prefer tao's.
// Brigand seems to have more support, so we'll use that as default and fallback
// to tao when brigand fails. With C++14, we'll be able to just use the STL.
#if !defined(VTKM_CUDA_DEVICE_PASS) && \
(defined(VTKM_GCC) || \
(defined(__apple_build_version__) && (__apple_build_version__ >= 10000000)) || \
(defined(VTKM_CLANG) && (__clang_major__ >= 5)))
#define VTKM_USE_TAO_SEQ
#endif
namespace vtkm namespace vtkm
{ {
namespace cont namespace cont
@ -407,14 +396,10 @@ struct DecoratorStorageTraits
"ArrayHandleDecorator must be a list of ArrayHandle " "ArrayHandleDecorator must be a list of ArrayHandle "
"types."); "types.");
using ArrayTupleType = vtkmstd::tuple<ArrayTs...>; using ArrayTupleType = vtkm::Tuple<ArrayTs...>;
// size_t integral constants that index ArrayTs: // size_t integral constants that index ArrayTs:
#ifndef VTKM_USE_TAO_SEQ using IndexList = vtkmstd::make_index_sequence<sizeof...(ArrayTs)>;
using IndexList = brigand::make_sequence<brigand::size_t<0>, sizeof...(ArrayTs)>;
#else // VTKM_USE_TAO_SEQ
using IndexList = tao::seq::make_index_sequence<sizeof...(ArrayTs)>;
#endif // VTKM_USE_TAO_SEQ
// true_type/false_type depending on whether the decorator supports Allocate/Shrink: // true_type/false_type depending on whether the decorator supports Allocate/Shrink:
using IsAllocatable = IsDecoratorAllocatable<DecoratorImplT, ArrayList>; using IsAllocatable = IsDecoratorAllocatable<DecoratorImplT, ArrayList>;
@ -532,13 +517,12 @@ struct DecoratorStorageTraits
} }
#ifndef VTKM_USE_TAO_SEQ
// Portal construction methods. These actually create portals. // Portal construction methods. These actually create portals.
template <template <typename...> class List, typename... Indices> template <template <typename, std::size_t...> class List, std::size_t... Indices>
VTKM_CONT static PortalControlType MakePortalControl(const DecoratorImplT& impl, VTKM_CONT static PortalControlType MakePortalControl(const DecoratorImplT& impl,
ArrayTupleType& arrays, ArrayTupleType& arrays,
vtkm::Id numValues, vtkm::Id numValues,
List<Indices...>) List<std::size_t, Indices...>)
{ {
return CreatePortalDecorator<PortalControlType>( return CreatePortalDecorator<PortalControlType>(
numValues, numValues,
@ -551,100 +535,7 @@ struct DecoratorStorageTraits
// Indices{}.value : Works on both MSVC2015 and MSVC2017. // Indices{}.value : Works on both MSVC2015 and MSVC2017.
// //
// Don't touch the following line unless you really, really have to. // Don't touch the following line unless you really, really have to.
WritePortal(vtkmstd::get<Indices{}.value>(arrays))...); WritePortal(vtkm::Get<Indices>(arrays))...);
}
template <template <typename...> class List, typename... Indices>
VTKM_CONT static PortalConstControlType MakePortalConstControl(const DecoratorImplT& impl,
const ArrayTupleType& arrays,
vtkm::Id numValues,
List<Indices...>)
{
return CreatePortalDecorator<PortalConstControlType>(
numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
ReadPortal(vtkmstd::get<Indices{}.value>(arrays))...);
}
template <template <typename...> class List, typename... Indices, typename Device>
VTKM_CONT static PortalConstExecutionType<Device> MakePortalInput(const DecoratorImplT& impl,
const ArrayTupleType& arrays,
vtkm::Id numValues,
List<Indices...>,
Device dev,
vtkm::cont::Token& token)
{
return CreatePortalDecorator<PortalConstExecutionType<Device>>(
numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
GetPortalInput(vtkmstd::get<Indices{}.value>(arrays), dev, token)...);
}
template <template <typename...> class List, typename... Indices, typename Device>
VTKM_CONT static PortalExecutionType<Device> MakePortalInPlace(const DecoratorImplT& impl,
ArrayTupleType& arrays,
vtkm::Id numValues,
List<Indices...>,
Device dev,
vtkm::cont::Token& token)
{
return CreatePortalDecorator<PortalExecutionType<Device>>(
numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
GetPortalInPlace(vtkmstd::get<Indices{}.value>(arrays), dev, token)...);
}
template <template <typename...> class List, typename... Indices, typename Device>
VTKM_CONT static PortalExecutionType<Device> MakePortalOutput(const DecoratorImplT& impl,
ArrayTupleType& arrays,
vtkm::Id numValues,
List<Indices...>,
Device dev,
vtkm::cont::Token& token)
{
return CreatePortalDecorator<PortalExecutionType<Device>>(
numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
GetPortalOutput(vtkmstd::get<Indices{}.value>(arrays), dev, token)...);
}
template <template <typename...> class List, typename... Indices>
VTKM_CONT static void AllocateSourceArrays(const DecoratorImplT& impl,
ArrayTupleType& arrays,
vtkm::Id numValues,
List<Indices...>)
{
CallAllocate(IsAllocatable{}, impl, numValues, vtkmstd::get<Indices{}.value>(arrays)...);
}
template <template <typename...> class List, typename... Indices>
VTKM_CONT static void ShrinkSourceArrays(const DecoratorImplT& impl,
ArrayTupleType& arrays,
vtkm::Id numValues,
List<Indices...>)
{
CallShrink(IsShrinkable{}, impl, numValues, vtkmstd::get<Indices{}.value>(arrays)...);
}
#else // VTKM_USE_TAO_SEQ
// Portal construction methods. These actually create portals.
template <template <typename, std::size_t...> class List, std::size_t... Indices>
VTKM_CONT static PortalControlType MakePortalControl(const DecoratorImplT& impl,
ArrayTupleType& arrays,
vtkm::Id numValues,
List<std::size_t, Indices...>)
{
return CreatePortalDecorator<PortalControlType>(
numValues, impl, WritePortal(vtkmstd::get<Indices>(arrays))...);
} }
template <template <typename, std::size_t...> class List, std::size_t... Indices> template <template <typename, std::size_t...> class List, std::size_t... Indices>
@ -654,7 +545,11 @@ struct DecoratorStorageTraits
List<std::size_t, Indices...>) List<std::size_t, Indices...>)
{ {
return CreatePortalDecorator<PortalConstControlType>( return CreatePortalDecorator<PortalConstControlType>(
numValues, impl, ReadPortal(vtkmstd::get<Indices>(arrays))...); numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
ReadPortal(vtkm::Get<Indices>(arrays))...);
} }
template <template <typename, std::size_t...> class List, std::size_t... Indices, typename Device> template <template <typename, std::size_t...> class List, std::size_t... Indices, typename Device>
@ -666,7 +561,11 @@ struct DecoratorStorageTraits
vtkm::cont::Token& token) vtkm::cont::Token& token)
{ {
return CreatePortalDecorator<PortalConstExecutionType<Device>>( return CreatePortalDecorator<PortalConstExecutionType<Device>>(
numValues, impl, GetPortalInput(vtkmstd::get<Indices>(arrays), dev, token)...); numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
GetPortalInput(vtkm::Get<Indices>(arrays), dev, token)...);
} }
template <template <typename, std::size_t...> class List, std::size_t... Indices, typename Device> template <template <typename, std::size_t...> class List, std::size_t... Indices, typename Device>
@ -678,7 +577,11 @@ struct DecoratorStorageTraits
vtkm::cont::Token& token) vtkm::cont::Token& token)
{ {
return CreatePortalDecorator<PortalExecutionType<Device>>( return CreatePortalDecorator<PortalExecutionType<Device>>(
numValues, impl, GetPortalInPlace(vtkmstd::get<Indices>(arrays), dev, token)...); numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
GetPortalInPlace(vtkm::Get<Indices>(arrays), dev, token)...);
} }
template <template <typename, std::size_t...> class List, std::size_t... Indices, typename Device> template <template <typename, std::size_t...> class List, std::size_t... Indices, typename Device>
@ -690,7 +593,11 @@ struct DecoratorStorageTraits
vtkm::cont::Token& token) vtkm::cont::Token& token)
{ {
return CreatePortalDecorator<PortalExecutionType<Device>>( return CreatePortalDecorator<PortalExecutionType<Device>>(
numValues, impl, GetPortalOutput(vtkmstd::get<Indices>(arrays), dev, token)...); numValues,
impl,
// Don't touch the following line unless you really, really have to. See
// note in MakePortalControl.
GetPortalOutput(vtkm::Get<Indices>(arrays), dev, token)...);
} }
template <template <typename, std::size_t...> class List, std::size_t... Indices> template <template <typename, std::size_t...> class List, std::size_t... Indices>
@ -699,7 +606,7 @@ struct DecoratorStorageTraits
vtkm::Id numValues, vtkm::Id numValues,
List<std::size_t, Indices...>) List<std::size_t, Indices...>)
{ {
CallAllocate(IsAllocatable{}, impl, numValues, vtkmstd::get<Indices>(arrays)...); CallAllocate(IsAllocatable{}, impl, numValues, vtkm::Get<Indices>(arrays)...);
} }
template <template <typename, std::size_t...> class List, std::size_t... Indices> template <template <typename, std::size_t...> class List, std::size_t... Indices>
@ -708,10 +615,8 @@ struct DecoratorStorageTraits
vtkm::Id numValues, vtkm::Id numValues,
List<std::size_t, Indices...>) List<std::size_t, Indices...>)
{ {
CallShrink(IsShrinkable{}, impl, numValues, vtkmstd::get<Indices>(arrays)...); CallShrink(IsShrinkable{}, impl, numValues, vtkm::Get<Indices>(arrays)...);
} }
#endif // VTKM_USE_TAO_SEQ
}; };
} // end namespace decor } // end namespace decor
@ -1030,7 +935,7 @@ public:
ArrayHandleDecorator(vtkm::Id numValues, ArrayHandleDecorator(vtkm::Id numValues,
const typename std::decay<DecoratorImplT>::type& impl, const typename std::decay<DecoratorImplT>::type& impl,
const typename std::decay<ArrayTs>::type&... arrays) const typename std::decay<ArrayTs>::type&... arrays)
: Superclass{ StorageType{ impl, vtkmstd::make_tuple(arrays...), numValues } } : Superclass{ StorageType{ impl, vtkm::MakeTuple(arrays...), numValues } }
{ {
} }
}; };

@ -17,7 +17,7 @@
#include <vtkm/internal/ArrayPortalHelpers.h> #include <vtkm/internal/ArrayPortalHelpers.h>
#include <vtkmtaotuple/include/tao/seq/make_integer_sequence.hpp> #include <vtkmstd/integer_sequence.h>
#include <array> #include <array>
#include <limits> #include <limits>
@ -70,7 +70,7 @@ public:
typename = typename std::enable_if<Supported::value>::type> typename = typename std::enable_if<Supported::value>::type>
VTKM_EXEC_CONT ValueType Get(vtkm::Id valueIndex) const VTKM_EXEC_CONT ValueType Get(vtkm::Id valueIndex) const
{ {
return this->Get(valueIndex, tao::seq::make_index_sequence<NUM_COMPONENTS>()); return this->Get(valueIndex, vtkmstd::make_index_sequence<NUM_COMPONENTS>());
} }
template <typename SPT = SourcePortalType, template <typename SPT = SourcePortalType,
@ -78,7 +78,7 @@ public:
typename = typename std::enable_if<Supported::value>::type> typename = typename std::enable_if<Supported::value>::type>
VTKM_EXEC_CONT void Set(vtkm::Id valueIndex, const ValueType& value) const VTKM_EXEC_CONT void Set(vtkm::Id valueIndex, const ValueType& value) const
{ {
this->Set(valueIndex, value, tao::seq::make_index_sequence<NUM_COMPONENTS>()); this->Set(valueIndex, value, vtkmstd::make_index_sequence<NUM_COMPONENTS>());
} }
private: private:
@ -89,7 +89,7 @@ private:
} }
template <std::size_t... I> template <std::size_t... I>
VTKM_EXEC_CONT ValueType Get(vtkm::Id valueIndex, tao::seq::index_sequence<I...>) const VTKM_EXEC_CONT ValueType Get(vtkm::Id valueIndex, vtkmstd::index_sequence<I...>) const
{ {
return ValueType{ this->GetComponent<I>(valueIndex)... }; return ValueType{ this->GetComponent<I>(valueIndex)... };
} }
@ -105,7 +105,7 @@ private:
template <std::size_t... I> template <std::size_t... I>
VTKM_EXEC_CONT void Set(vtkm::Id valueIndex, VTKM_EXEC_CONT void Set(vtkm::Id valueIndex,
const ValueType& value, const ValueType& value,
tao::seq::index_sequence<I...>) const vtkmstd::index_sequence<I...>) const
{ {
// Is there a better way to unpack an expression and execute them with no other side effects? // Is there a better way to unpack an expression and execute them with no other side effects?
(void)std::initializer_list<bool>{ this->SetComponent<I>(valueIndex, value)... }; (void)std::initializer_list<bool>{ this->SetComponent<I>(valueIndex, value)... };

@ -10,8 +10,7 @@
#ifndef vtk_m_worklet_internal_Placeholders_h #ifndef vtk_m_worklet_internal_Placeholders_h
#define vtk_m_worklet_internal_Placeholders_h #define vtk_m_worklet_internal_Placeholders_h
#include <vtkmtaotuple/include/Tuple.h> #include <vtkmstd/integer_sequence.h>
#include <vtkmtaotuple/include/tao/seq/make_integer_sequence.hpp>
#include <type_traits> #include <type_traits>
@ -42,7 +41,7 @@ struct FunctionSigArity<R(ArgTypes...)>
//============================================================================ //============================================================================
template <int... Args> template <int... Args>
auto DefaultSigGenerator(tao::seq::integer_sequence<int, 0, Args...>) -> void (*)(Arg<Args>...); auto DefaultSigGenerator(vtkmstd::integer_sequence<int, 0, Args...>) -> void (*)(Arg<Args>...);
/** /**
* Given a desired length will generate the default/assumed ExecutionSignature. * Given a desired length will generate the default/assumed ExecutionSignature.
@ -56,7 +55,7 @@ auto DefaultSigGenerator(tao::seq::integer_sequence<int, 0, Args...>) -> void (*
template <int Length> template <int Length>
struct DefaultExecSig struct DefaultExecSig
{ {
using seq = tao::seq::make_integer_sequence<int, Length + 1>; using seq = vtkmstd::make_integer_sequence<int, Length + 1>;
using type = typename std::remove_pointer<decltype(DefaultSigGenerator(seq{}))>::type; using type = typename std::remove_pointer<decltype(DefaultSigGenerator(seq{}))>::type;
}; };
template <> template <>
@ -80,6 +79,19 @@ struct DefaultExecSig<4>
using type = void(Arg<1>, Arg<2>, Arg<3>, Arg<4>); using type = void(Arg<1>, Arg<2>, Arg<3>, Arg<4>);
}; };
template <bool HasExecSig_, typename Sig_>
struct ExecSigQuery
{
static constexpr bool HasExecSig = HasExecSig_;
using Sig = Sig_;
};
template <typename U, typename S = decltype(std::declval<typename U::ExecutionSignature>())>
static ExecSigQuery<true, typename U::ExecutionSignature> get_exec_sig(int);
template <typename U>
static ExecSigQuery<false, void> get_exec_sig(...);
//============================================================================ //============================================================================
/** /**
* Given a worklet this will produce a typedef `ExecutionSignature` that is * Given a worklet this will produce a typedef `ExecutionSignature` that is
@ -98,21 +110,15 @@ struct DefaultExecSig<4>
template <typename WorkletType> template <typename WorkletType>
struct GetExecSig struct GetExecSig
{ {
template <typename U, typename S = decltype(std::declval<typename U::ExecutionSignature>())>
static vtkmstd::tuple<std::true_type, typename U::ExecutionSignature> get_exec_sig(int);
template <typename U>
static vtkmstd::tuple<std::false_type, std::false_type> get_exec_sig(...);
using cont_sig = typename WorkletType::ControlSignature; using cont_sig = typename WorkletType::ControlSignature;
using cont_sig_info = vtkm::placeholders::FunctionSigArity<cont_sig>; using cont_sig_info = vtkm::placeholders::FunctionSigArity<cont_sig>;
using result = decltype(get_exec_sig<WorkletType>(0)); using result = decltype(get_exec_sig<WorkletType>(0));
using has_explicit_exec_sig = typename vtkmstd::tuple_element<0, result>::type; static constexpr bool has_explicit_exec_sig = result::HasExecSig;
using ExecutionSignature = typename std::conditional< using ExecutionSignature = typename std::conditional<
has_explicit_exec_sig::value, has_explicit_exec_sig,
typename vtkmstd::tuple_element<1, result>::type, typename result::Sig,
typename vtkm::placeholders::DefaultExecSig<cont_sig_info::value>::type>::type; typename vtkm::placeholders::DefaultExecSig<cont_sig_info::value>::type>::type;
}; };
} }