Support control array portals in composite vector.
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.
This commit is contained in:
parent
b93658b403
commit
e874b52f18
@ -100,29 +100,31 @@ struct CompositeVectorPullValueFunctor
|
||||
CompositeVectorPullValueFunctor(vtkm::Id index) : Index(index) { }
|
||||
|
||||
// This form is to pull values out of array arguments.
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template<typename PortalType>
|
||||
VTKM_EXEC_EXPORT
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
typename PortalType::ValueType operator()(const PortalType &portal) const {
|
||||
return portal.Get(this->Index);
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
struct CompositeVectorArrayToPortalCont {
|
||||
template<typename ArrayHandleType>
|
||||
template<typename ArrayHandleType, vtkm::IdComponent Index>
|
||||
struct ReturnType {
|
||||
typedef typename ArrayHandleType::PortalConstControl type;
|
||||
};
|
||||
|
||||
template<typename ArrayHandleType>
|
||||
template<typename ArrayHandleType, vtkm::IdComponent Index>
|
||||
VTKM_CONT_EXPORT
|
||||
typename ReturnType<ArrayHandleType>::type
|
||||
operator()(const ArrayHandleType &array) const {
|
||||
typename ReturnType<ArrayHandleType, Index>::type
|
||||
operator()(const ArrayHandleType &array,
|
||||
vtkm::internal::IndexTag<Index>) const {
|
||||
return array.GetPortalConstControl();
|
||||
}
|
||||
};
|
||||
@ -171,13 +173,15 @@ template<typename SignatureWithPortals>
|
||||
class ArrayPortalCompositeVector
|
||||
{
|
||||
typedef vtkm::internal::FunctionInterface<SignatureWithPortals> PortalTypes;
|
||||
typedef vtkm::Vec<vtkm::IdComponent, PortalTypes::ARITY> ComponentMapType;
|
||||
|
||||
public:
|
||||
typedef typename PortalTypes::ResultType ValueType;
|
||||
static const vtkm::IdComponent 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_EXEC_CONT_EXPORT
|
||||
@ -189,12 +193,14 @@ public:
|
||||
vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> sourceComponents)
|
||||
: Portals(portals), SourceComponents(sourceComponents) { }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const {
|
||||
return this->Portals.template GetParameter<1>().GetNumberOfValues();
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const {
|
||||
// This might be inefficient because we are copying all the portals only
|
||||
// because they are coupled with the return value.
|
||||
@ -210,61 +216,6 @@ private:
|
||||
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>
|
||||
struct StorageTagCompositeVector { };
|
||||
|
||||
@ -294,8 +245,13 @@ class Storage<
|
||||
static const vtkm::IdComponent NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY;
|
||||
typedef vtkm::Vec<vtkm::IdComponent, NUM_COMPONENTS> ComponentMapType;
|
||||
|
||||
typedef typename FunctionInterfaceWithArrays::template StaticTransformType<
|
||||
detail::CompositeVectorArrayToPortalCont>::type
|
||||
FunctionInterfaceWithPortals;
|
||||
typedef typename FunctionInterfaceWithPortals::Signature SignatureWithPortals;
|
||||
|
||||
public:
|
||||
typedef ArrayPortalCompositeVectorCont<SignatureWithArrays> PortalType;
|
||||
typedef ArrayPortalCompositeVector<SignatureWithPortals> PortalType;
|
||||
typedef PortalType PortalConstType;
|
||||
typedef typename PortalType::ValueType ValueType;
|
||||
|
||||
@ -324,7 +280,9 @@ public:
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"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
|
||||
@ -487,7 +445,7 @@ class ArrayHandleCompositeVector
|
||||
{
|
||||
typedef typename internal::ArrayHandleCompositeVectorTraits<Signature>::StorageType
|
||||
StorageType;
|
||||
typedef typename internal::ArrayPortalCompositeVectorCont<Signature>::ComponentMapType
|
||||
typedef typename internal::ArrayPortalCompositeVector<Signature>::ComponentMapType
|
||||
ComponentMapType;
|
||||
|
||||
public:
|
||||
|
@ -161,6 +161,11 @@ private:
|
||||
result.GetPortalConstControl().Get(i);
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, vtkm::Vec<ValueType, 3>(value)),
|
||||
"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");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user