From e874b52f18b102e801aff3aa89ed1380bc063432 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 4 Jan 2016 12:53:56 -0700 Subject: [PATCH] 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. --- vtkm/cont/ArrayHandleCompositeVector.h | 92 ++++++-------------- vtkm/cont/testing/TestingFancyArrayHandles.h | 5 ++ 2 files changed, 30 insertions(+), 67 deletions(-) diff --git a/vtkm/cont/ArrayHandleCompositeVector.h b/vtkm/cont/ArrayHandleCompositeVector.h index 3caec810c..0f38de605 100644 --- a/vtkm/cont/ArrayHandleCompositeVector.h +++ b/vtkm/cont/ArrayHandleCompositeVector.h @@ -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 - 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 + template struct ReturnType { typedef typename ArrayHandleType::PortalConstControl type; }; - template + template VTKM_CONT_EXPORT - typename ReturnType::type - operator()(const ArrayHandleType &array) const { + typename ReturnType::type + operator()(const ArrayHandleType &array, + vtkm::internal::IndexTag) const { return array.GetPortalConstControl(); } }; @@ -171,13 +173,15 @@ template class ArrayPortalCompositeVector { typedef vtkm::internal::FunctionInterface PortalTypes; - typedef vtkm::Vec ComponentMapType; public: typedef typename PortalTypes::ResultType ValueType; static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VecTraits::NUM_COMPONENTS; + // Used internally. + typedef vtkm::Vec ComponentMapType; + VTKM_STATIC_ASSERT(NUM_COMPONENTS == PortalTypes::ARITY); VTKM_EXEC_CONT_EXPORT @@ -189,12 +193,14 @@ public: vtkm::Vec 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 -class ArrayPortalCompositeVectorCont -{ - typedef vtkm::internal::FunctionInterface - FunctionInterfaceArrays; - -public: - typedef typename FunctionInterfaceArrays::ResultType ValueType; - static const vtkm::IdComponent NUM_COMPONENTS = - vtkm::VecTraits::NUM_COMPONENTS; - typedef vtkm::Vec 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 struct StorageTagCompositeVector { }; @@ -294,8 +245,13 @@ class Storage< static const vtkm::IdComponent NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY; typedef vtkm::Vec ComponentMapType; + typedef typename FunctionInterfaceWithArrays::template StaticTransformType< + detail::CompositeVectorArrayToPortalCont>::type + FunctionInterfaceWithPortals; + typedef typename FunctionInterfaceWithPortals::Signature SignatureWithPortals; + public: - typedef ArrayPortalCompositeVectorCont PortalType; + typedef ArrayPortalCompositeVector 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::StorageType StorageType; - typedef typename internal::ArrayPortalCompositeVectorCont::ComponentMapType + typedef typename internal::ArrayPortalCompositeVector::ComponentMapType ComponentMapType; public: diff --git a/vtkm/cont/testing/TestingFancyArrayHandles.h b/vtkm/cont/testing/TestingFancyArrayHandles.h index 1958bab5d..3f1853e60 100644 --- a/vtkm/cont/testing/TestingFancyArrayHandles.h +++ b/vtkm/cont/testing/TestingFancyArrayHandles.h @@ -161,6 +161,11 @@ private: result.GetPortalConstControl().Get(i); VTKM_TEST_ASSERT(test_equal(result_v, vtkm::Vec(value)), "CompositeVector Handle Failed"); + + const vtkm::Vec result_c = + composite.GetPortalConstControl().Get(i); + VTKM_TEST_ASSERT(test_equal(result_c, vtkm::Vec(value)), + "CompositeVector Handle Failed"); } } };