From 3813fb515cb843975ef7559bc4a66562ad92e6f1 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 22 Feb 2021 08:30:25 -0700 Subject: [PATCH] Make ArrayPortalRecombineVec trivially copyable Using this internal class is a bit tricky because it requires a pointer to a C array that is expected to contain portals. Both the C array and the portals must be defined for the expected device. This is already handled by the associated Storage. Assuming all of this holds, make sure the `ArrayPortalRecombineVec` is trivially copyable. This is a requirement for passing objects to the execution environment. --- vtkm/cont/ArrayHandleRecombineVec.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/vtkm/cont/ArrayHandleRecombineVec.h b/vtkm/cont/ArrayHandleRecombineVec.h index ef8327db8..f401ed125 100644 --- a/vtkm/cont/ArrayHandleRecombineVec.h +++ b/vtkm/cont/ArrayHandleRecombineVec.h @@ -294,24 +294,29 @@ namespace internal template class ArrayPortalRecombineVec { - vtkm::VecCConst Portals; + // Note that this ArrayPortal has a pointer to a C array of other portals. We need to + // make sure that the pointer is valid on the device we are using it on. See the + // CreateReadPortal and CreateWritePortal in the Storage below to see how that is + // managed. + const SourcePortalType* Portals; + vtkm::IdComponent NumberOfComponents; public: using ValueType = vtkm::internal::RecombineVec; ArrayPortalRecombineVec() = default; - ArrayPortalRecombineVec(const vtkm::VecCConst& portals) - : Portals(portals) - { - } ArrayPortalRecombineVec(const SourcePortalType* portals, vtkm::IdComponent numComponents) - : Portals(portals, numComponents) + : Portals(portals) + , NumberOfComponents(numComponents) { } VTKM_EXEC_CONT vtkm::Id GetNumberOfValues() const { return this->Portals[0].GetNumberOfValues(); } - VTKM_EXEC_CONT ValueType Get(vtkm::Id index) const { return ValueType(this->Portals, index); } + VTKM_EXEC_CONT ValueType Get(vtkm::Id index) const + { + return ValueType({ this->Portals, this->NumberOfComponents }, index); + } VTKM_EXEC_CONT void Set(vtkm::Id index, const ValueType& value) const { @@ -324,8 +329,8 @@ public: VTKM_EXEC_CONT void Set(vtkm::Id index, const T& value) const { using Traits = vtkm::VecTraits; - VTKM_ASSERT(Traits::GetNumberOfComponents(value) == this->Portals.GetNumberOfComponents()); - for (vtkm::IdComponent cIndex = 0; cIndex < this->Portals.GetNumberOfComponents(); ++cIndex) + VTKM_ASSERT(Traits::GetNumberOfComponents(value) == this->NumberOfComponents); + for (vtkm::IdComponent cIndex = 0; cIndex < this->NumberOfComponents; ++cIndex) { this->Portals[cIndex].Set(index, Traits::GetComponent(value, cIndex)); } @@ -441,7 +446,6 @@ public: vtkm::cont::DeviceAdapterId device, vtkm::cont::Token& token) { - ReadPortalType portal; vtkm::IdComponent numComponents = NumberOfComponents(buffers); // The array portal needs a runtime-allocated array of portals for each component. @@ -479,7 +483,6 @@ public: vtkm::cont::DeviceAdapterId device, vtkm::cont::Token& token) { - WritePortalType portal; vtkm::IdComponent numComponents = NumberOfComponents(buffers); // The array portal needs a runtime-allocated array of portals for each component.