Merge branch 'composite-array-handle-in-control' into 'master'

Support control array portals in ArrayHandleCompositeVector.

Previously, the ArrayHandleCompositeVector had a separate implementation
of ArrayPortal for the control and execution environments. Because I was
lazy when I implemented it, the control version did not support Get.

Since originally implementing this class, VTK-m now allows defining
methods that are declared as working in both control and execution
environments (VTKM_EXEC_CONT_EXPORT) but only work in one or the other
depending on methods of templated subclasses they call. Thus, solve this
problem by simply removing the control version of the portal and use the
same portal for both.

See merge request !296
This commit is contained in:
Kenneth Moreland 2016-01-04 19:32:32 -05:00
commit d502f6e28b
2 changed files with 30 additions and 67 deletions

@ -100,29 +100,31 @@ struct CompositeVectorPullValueFunctor
CompositeVectorPullValueFunctor(vtkm::Id index) : Index(index) { } CompositeVectorPullValueFunctor(vtkm::Id index) : Index(index) { }
// This form is to pull values out of array arguments. // This form is to pull values out of array arguments.
VTKM_SUPPRESS_EXEC_WARNINGS
template<typename PortalType> template<typename PortalType>
VTKM_EXEC_EXPORT VTKM_EXEC_CONT_EXPORT
typename PortalType::ValueType operator()(const PortalType &portal) const { typename PortalType::ValueType operator()(const PortalType &portal) const {
return portal.Get(this->Index); return portal.Get(this->Index);
} }
// This form is an identity to pass the return value back. // This form is an identity to pass the return value back.
VTKM_EXEC_EXPORT VTKM_EXEC_CONT_EXPORT
const ReturnValueType &operator()(const ReturnValueType &value) const { const ReturnValueType &operator()(const ReturnValueType &value) const {
return value; return value;
} }
}; };
struct CompositeVectorArrayToPortalCont { struct CompositeVectorArrayToPortalCont {
template<typename ArrayHandleType> template<typename ArrayHandleType, vtkm::IdComponent Index>
struct ReturnType { struct ReturnType {
typedef typename ArrayHandleType::PortalConstControl type; typedef typename ArrayHandleType::PortalConstControl type;
}; };
template<typename ArrayHandleType> template<typename ArrayHandleType, vtkm::IdComponent Index>
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
typename ReturnType<ArrayHandleType>::type typename ReturnType<ArrayHandleType, Index>::type
operator()(const ArrayHandleType &array) const { operator()(const ArrayHandleType &array,
vtkm::internal::IndexTag<Index>) const {
return array.GetPortalConstControl(); return array.GetPortalConstControl();
} }
}; };
@ -171,13 +173,15 @@ template<typename SignatureWithPortals>
class ArrayPortalCompositeVector class ArrayPortalCompositeVector
{ {
typedef vtkm::internal::FunctionInterface<SignatureWithPortals> PortalTypes; typedef vtkm::internal::FunctionInterface<SignatureWithPortals> PortalTypes;
typedef vtkm::Vec<vtkm::IdComponent, PortalTypes::ARITY> ComponentMapType;
public: public:
typedef typename PortalTypes::ResultType ValueType; typedef typename PortalTypes::ResultType ValueType;
static const vtkm::IdComponent NUM_COMPONENTS = static const vtkm::IdComponent NUM_COMPONENTS =
vtkm::VecTraits<ValueType>::NUM_COMPONENTS; vtkm::VecTraits<ValueType>::NUM_COMPONENTS;
// Used internally.
typedef vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> ComponentMapType;
VTKM_STATIC_ASSERT(NUM_COMPONENTS == PortalTypes::ARITY); VTKM_STATIC_ASSERT(NUM_COMPONENTS == PortalTypes::ARITY);
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
@ -189,12 +193,14 @@ public:
vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> sourceComponents) vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> sourceComponents)
: Portals(portals), SourceComponents(sourceComponents) { } : Portals(portals), SourceComponents(sourceComponents) { }
VTKM_EXEC_EXPORT VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const { vtkm::Id GetNumberOfValues() const {
return this->Portals.template GetParameter<1>().GetNumberOfValues(); return this->Portals.template GetParameter<1>().GetNumberOfValues();
} }
VTKM_EXEC_EXPORT VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ValueType Get(vtkm::Id index) const { ValueType Get(vtkm::Id index) const {
// This might be inefficient because we are copying all the portals only // This might be inefficient because we are copying all the portals only
// because they are coupled with the return value. // because they are coupled with the return value.
@ -210,61 +216,6 @@ private:
ComponentMapType SourceComponents; ComponentMapType SourceComponents;
}; };
/// \brief A "portal" that holds arrays to get components from.
///
/// This class takes place as the control-side portal within an
/// ArrayHandleCompositeVector. This is an incomplete implementation, so you
/// really can't use it to get values. However, between this and the
/// specialization ArrayTransfer, it's enough to get values to the execution
/// environment.
///
template<typename SignatureWithArrays>
class ArrayPortalCompositeVectorCont
{
typedef vtkm::internal::FunctionInterface<SignatureWithArrays>
FunctionInterfaceArrays;
public:
typedef typename FunctionInterfaceArrays::ResultType ValueType;
static const vtkm::IdComponent NUM_COMPONENTS =
vtkm::VecTraits<ValueType>::NUM_COMPONENTS;
typedef vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> ComponentMapType;
// If you get a compile error here, it means you probably tried to create
// an ArrayHandleCompositeVector with a return type of a vector with a
// different number of components than the number of arrays given.
VTKM_STATIC_ASSERT(NUM_COMPONENTS == FunctionInterfaceArrays::ARITY);
VTKM_CONT_EXPORT
ArrayPortalCompositeVectorCont() : NumberOfValues(0) { }
VTKM_CONT_EXPORT
ArrayPortalCompositeVectorCont(
const FunctionInterfaceArrays &arrays,
const ComponentMapType &vtkmNotUsed(sourceComponents))
: NumberOfValues(arrays.template GetParameter<1>().GetNumberOfValues()) { }
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
return this->NumberOfValues;
}
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id vtkmNotUsed(index)) const {
throw vtkm::cont::ErrorControlInternal(
"Const Array Portal not implemented for composite vector.");
}
VTKM_CONT_EXPORT
void Set(vtkm::Id vtkmNotUsed(index), ValueType vtkmNotUsed(value)) {
throw vtkm::cont::ErrorControlInternal(
"Const Array Portal not implemented for composite vector.");
}
private:
vtkm::Id NumberOfValues;
};
template<typename SignatureWithArrays> template<typename SignatureWithArrays>
struct StorageTagCompositeVector { }; struct StorageTagCompositeVector { };
@ -294,8 +245,13 @@ class Storage<
static const vtkm::IdComponent NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY; static const vtkm::IdComponent NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY;
typedef vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> ComponentMapType; typedef vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> ComponentMapType;
typedef typename FunctionInterfaceWithArrays::template StaticTransformType<
detail::CompositeVectorArrayToPortalCont>::type
FunctionInterfaceWithPortals;
typedef typename FunctionInterfaceWithPortals::Signature SignatureWithPortals;
public: public:
typedef ArrayPortalCompositeVectorCont<SignatureWithArrays> PortalType; typedef ArrayPortalCompositeVector<SignatureWithPortals> PortalType;
typedef PortalType PortalConstType; typedef PortalType PortalConstType;
typedef typename PortalType::ValueType ValueType; typedef typename PortalType::ValueType ValueType;
@ -324,7 +280,9 @@ public:
throw vtkm::cont::ErrorControlBadValue( throw vtkm::cont::ErrorControlBadValue(
"Tried to use an ArrayHandleCompositeHandle without dependent arrays."); "Tried to use an ArrayHandleCompositeHandle without dependent arrays.");
} }
return PortalConstType(this->Arrays, this->SourceComponents); return PortalConstType(this->Arrays.StaticTransformCont(
detail::CompositeVectorArrayToPortalCont()),
this->SourceComponents);
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
@ -487,7 +445,7 @@ class ArrayHandleCompositeVector
{ {
typedef typename internal::ArrayHandleCompositeVectorTraits<Signature>::StorageType typedef typename internal::ArrayHandleCompositeVectorTraits<Signature>::StorageType
StorageType; StorageType;
typedef typename internal::ArrayPortalCompositeVectorCont<Signature>::ComponentMapType typedef typename internal::ArrayPortalCompositeVector<Signature>::ComponentMapType
ComponentMapType; ComponentMapType;
public: public:

@ -161,6 +161,11 @@ private:
result.GetPortalConstControl().Get(i); result.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, vtkm::Vec<ValueType, 3>(value)), VTKM_TEST_ASSERT(test_equal(result_v, vtkm::Vec<ValueType, 3>(value)),
"CompositeVector Handle Failed"); "CompositeVector Handle Failed");
const vtkm::Vec<ValueType, 3> result_c =
composite.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_c, vtkm::Vec<ValueType, 3>(value)),
"CompositeVector Handle Failed");
} }
} }
}; };